fixed code to use new model

This commit is contained in:
Djalim Simaila 2023-03-14 17:53:11 +01:00
parent 709d4ced32
commit 278ed41630
3 changed files with 9 additions and 10 deletions

View File

@ -11,7 +11,8 @@ def get_text_from_lid(lang: str, lid: int) -> str:
:param lid: the locale id the get the text from :param lid: the locale id the get the text from
:return: the text associated to the lang and lid :return: the text associated to the lang and lid
""" """
return db.session.query(Locale).filter_by(LANG=lang, TEXT_ID=lid).one().TEXT texts = db.session.query(Text).filter_by(LANG=lang, TEXT_ID=lid).all()
return random.choice(texts).TEXT
def get_random_place() -> Place: def get_random_place() -> Place:
""" """
@ -58,9 +59,8 @@ def get_random_question(qa_type: int) -> QuestionType :
:param qa_type: the type of the question :param qa_type: the type of the question
:return: a Question object :return: a Question object
""" """
answers = db.session.query(QuestionType).filter_by(QUESTION_TYPE_ID=qa_type).all() return db.session.query(QuestionType).filter_by(QUESTION_TYPE_ID=qa_type).one()
return random.choice(answers)
def get_trait_from_text(text: str) -> int: def get_trait_from_text(text: str) -> int:
""" """
Returns the trait_id from its text value Returns the trait_id from its text value
@ -68,7 +68,7 @@ def get_trait_from_text(text: str) -> int:
:param text: the text representation of the trait in any lang :param text: the text representation of the trait in any lang
:return: the trait_id linked to this text :return: the trait_id linked to this text
""" """
trait_lid = db.session.query(Locale).filter_by(TEXT=text).one().TEXT_ID trait_lid = db.session.query(Text).filter_by(TEXT=text).one().TEXT_ID
return db.session.query(Trait).filter_by(NAME_LID=trait_lid).one().TRAIT_ID return db.session.query(Trait).filter_by(NAME_LID=trait_lid).one().TRAIT_ID
def get_trait_from_trait_id(trait_id: int) -> Trait: def get_trait_from_trait_id(trait_id: int) -> Trait:
@ -81,7 +81,7 @@ def get_trait_from_trait_id(trait_id: int) -> Trait:
trait = db.session.query(Trait).filter_by(TRAIT_ID=trait_id).one() trait = db.session.query(Trait).filter_by(TRAIT_ID=trait_id).one()
return trait return trait
def get_reaction_description(lang, npc_id, trait_id) -> str: def get_reaction_description(lang, trait_id) -> str:
""" """
Returns the description of the reaction of a given npc in the language specified by the parametter lang Returns the description of the reaction of a given npc in the language specified by the parametter lang

View File

@ -1,6 +1,5 @@
from sqlalchemy import Column, Integer, VARCHAR, Text, ForeignKey from sqlalchemy import Column, Integer, VARCHAR, Text, ForeignKey
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship, declarative_base
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base() Base = declarative_base()

View File

@ -84,7 +84,7 @@ class Game:
trait_id = self.reaction_table[npc_id] trait_id = self.reaction_table[npc_id]
trait = dbutils.get_trait_from_trait_id(trait_id) trait = dbutils.get_trait_from_trait_id(trait_id)
npcs[npc_id]["reaction"] = dbutils.get_text_from_lid("FR", trait.NAME_LID) npcs[npc_id]["reaction"] = dbutils.get_text_from_lid("FR", trait.NAME_LID)
npcs[npc_id]["description"] = dbutils.get_reaction_description("FR", npc_id, trait.TRAIT_ID) npcs[npc_id]["description"] = dbutils.get_reaction_description("FR", trait.TRAIT_ID)
player_results = data["player"] = {} player_results = data["player"] = {}
for member in self.members: for member in self.members:
player_results[member.username] = member.results player_results[member.username] = member.results
@ -322,4 +322,4 @@ def get_npc_image(npc_id: int):
:param npc_id: npc to get the neutral image from :param npc_id: npc to get the neutral image from
:return: the byte representation of the image, none if its not found or not readable :return: the byte representation of the image, none if its not found or not readable
""" """
return read_image(f"./truthinquiry/static/images/npc/{npc_id}/0.png") return read_image(f"./truthinquiry/static/images/npc/{npc_id}/0.png")