Modify Question table and rename to QuestionType

This commit is contained in:
Thomas Rubini 2023-03-11 17:10:10 +01:00
parent 5f84794e24
commit c450bd36b0
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
2 changed files with 9 additions and 11 deletions

View File

@ -51,14 +51,14 @@ def get_npc_random_answer(npc_id:int, qa_type:int) -> Answer :
answers = db.session.query(Answer).filter_by(QA_TYPE=qa_type,NPC_ID=npc_id.NPC_ID).all() answers = db.session.query(Answer).filter_by(QA_TYPE=qa_type,NPC_ID=npc_id.NPC_ID).all()
return random.choice(answers) return random.choice(answers)
def get_random_question(qa_type: int) -> Question : def get_random_question(qa_type: int) -> QuestionType :
""" """
Returns a random inspector question from a question type Returns a random inspector question from a question type
: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(Question).filter_by(QUESTION_TYPE=qa_type).all() answers = db.session.query(QuestionType).filter_by(QUESTION_TYPE_ID=qa_type).all()
return random.choice(answers) return random.choice(answers)
def get_trait_from_text(text: str) -> int: def get_trait_from_text(text: str) -> int:

View File

@ -42,24 +42,22 @@ class Place(Base):
return f"{self.PLACE_ID} {self.NAME_LID}" return f"{self.PLACE_ID} {self.NAME_LID}"
class Question(Base): class QuestionType(Base):
""" """
Stores questions asked by players Stores questions types that can be asked by players, e.g "where", "with tho"
""" """
__tablename__ = "T_QUESTION" __tablename__ = "T_QUESTION_TYPE"
QUESTION_ID = Column(Integer, primary_key=True, comment="ID of this question") QUESTION_TYPE_ID = Column(Integer, primary_key=True, comment="ID of this question type.")
QUESTION_TYPE = Column(Integer, comment="Question type ID, e.g 'when..', 'where..'")
TEXT_LID = Column(Integer, ForeignKey("T_LOCALE.TEXT_ID"), comment="Question text") TEXT_LID = Column(Integer, ForeignKey("T_LOCALE.TEXT_ID"), comment="Question text")
LOCALE = relationship("Locale") LOCALE = relationship("Locale")
def __init__(self, QUESTION_ID, QUESTION_TYPE, TEXT_LID): def __init__(self, QUESTION_TYPE_ID, TEXT_LID):
self.QUESTION_ID = QUESTION_ID self.QUESTION_ID = QUESTION_TYPE_ID
self.QUESTION_TYPE = QUESTION_TYPE
self.TEXT_LID = TEXT_LID self.TEXT_LID = TEXT_LID
def __str__(self): def __str__(self):
return f"{self.QUESTION_ID} {self.QUESTION_TYPE} {self.TEXT_LID}" return f"{self.QUESTION_ID} {self.QUESTION_TYPE_ID}"
class Answer(Base): class Answer(Base):