diff --git a/truthseeker/logic/data_persistance/data_access.py b/truthseeker/logic/data_persistance/data_access.py index 346ee2a..4d76116 100644 --- a/truthseeker/logic/data_persistance/data_access.py +++ b/truthseeker/logic/data_persistance/data_access.py @@ -17,38 +17,38 @@ url_object = eg.URL.create( engine = create_engine(url_object) session = Session(engine) -def getTextFromLid(lang,lid) -> str: +def get_text_from_lid(lang,lid) -> str: return session.query(tables.Locale).filter_by(LANG=lang, TEXT_ID=lid).one().TEXT -def getRandomPlace() -> tables.Place: +def get_random_place() -> tables.Place: return random.choice(session.query(tables.Place).all()) -def getRandomNpc() -> tables.Npc : +def get_random_npc() -> tables.Npc : return random.choice(session.query(tables.Npc).all()) -def getNpcRandomTraitId(npc) -> int: +def get_npc_random_trait_id(npc) -> int: reactions = session.query(tables.Reaction).filter_by(NPC_ID=npc.NPC_ID).all() reaction = random.choice(reactions) return reaction.TRAIT_ID -def getNpcRandomAnswer(npc, QA_TYPE) -> tables.Answer : +def get_npc_random_answer(npc, QA_TYPE) -> tables.Answer : answers = session.query(tables.Answer).filter_by(QA_TYPE=QA_TYPE,NPC_ID=npc.NPC_ID).all() return random.choice(answers) -def getRandomQuestion(QA_TYPE) -> tables.Answer : +def get_random_question(QA_TYPE) -> tables.Answer : answers = session.query(tables.Question).filter_by(QUESTION_TYPE=QA_TYPE).all() return random.choice(answers) -def getTraitFromText(text): +def get_trait_from_text(text): trait_lid = session.query(tables.Locale).filter_by(TEXT=text).one().TEXT_ID return session.query(tables.Trait).filter_by(NAME_LID=trait_lid).one().TRAIT_ID -def getTraitFromTraitId(trait_id): +def get_trait_from_trait_id(trait_id): trait = session.query(tables.Trait).filter_by(TRAIT_ID=trait_id).one() return trait -def getTraits(lang): +def get_traits(lang): traits = [] for trait in session.query(tables.Trait).all(): - traits.append(getTextFromLid(lang,trait.NAME_LID)) + traits.append(get_text_from_lid(lang,trait.NAME_LID)) return traits \ No newline at end of file diff --git a/truthseeker/logic/game_logic.py b/truthseeker/logic/game_logic.py index 8764b77..8f1f8bb 100644 --- a/truthseeker/logic/game_logic.py +++ b/truthseeker/logic/game_logic.py @@ -76,8 +76,8 @@ class Game: npcs[npc_id] = {} npcs[npc_id]["name"] = self.gamedata["npcs"][npc_id]["name"] traitId = self.reaction_table[npc_id] - trait = getTraitFromTraitId(traitId) - npcs[npc_id]["reaction"] = getTextFromLid("FR",trait.NAME_LID) + trait = get_trait_from_trait_id(traitId) + npcs[npc_id]["reaction"] = get_text_from_lid("FR",trait.NAME_LID) player_results = data["player"] = {} for member in self.members: player_results[member.username] = member.results @@ -130,7 +130,7 @@ class Game: results = {} try: for npc_id in responses: - trait_id = getTraitIdFromString(responses[npc_id]) + trait_id = get_trait_id_from_string(responses[npc_id]) results[npc_id] = trait_id == str(self.reaction_table[npc_id]) return results except: @@ -200,20 +200,20 @@ def check_username(username: str) -> bool: def generateNpcText(npc: tables.Npc, lang: str) -> dict: data = {} - data["name"] = getTextFromLid(lang, npc.NAME_LID) - data["QA_0"] = getTextFromLid(lang, getNpcRandomAnswer(npc,0).TEXT_LID) - data["QA_1"] = getTextFromLid(lang, getNpcRandomAnswer(npc,1).TEXT_LID) + data["name"] = get_text_from_lid(lang, npc.NAME_LID) + data["QA_0"] = get_text_from_lid(lang, get_npc_random_answer(npc,0).TEXT_LID) + data["QA_1"] = get_text_from_lid(lang, get_npc_random_answer(npc,1).TEXT_LID) return data def generateNpcReactions(npc: tables.Npc) ->list: - return getNpcRandomTraitId(npc) + return get_npc_random_trait_id(npc) -def generatePlaceData(npcs: list, places: list, lang: str) -> dict: +def generate_place_data(npcs: list, places: list, lang: str) -> dict: data = {} random.shuffle(npcs) for place in places: placedata = data[str(place.PLACE_ID)] = {} - placedata["name"] = getTextFromLid(lang,place.NAME_LID) + placedata["name"] = get_text_from_lid(lang,place.NAME_LID) placedata["npcs"] = [] for _ in npcs: placedata["npcs"].append(npcs.pop().NPC_ID) @@ -227,7 +227,7 @@ def generateGameData(LANG): reactions_table = {} npcs = [] while len(npcs) != 5: - npc = getRandomNpc() + npc = get_random_npc() if npc not in npcs : npcs.append(npc) for npc in npcs: @@ -236,15 +236,15 @@ def generateGameData(LANG): places = [] while len(places) != 3: - place = getRandomPlace() + place = get_random_place() if place not in places: places.append(place) - data["rooms"] = generatePlaceData(npcs,places,LANG) + data["rooms"] = generate_place_data(npcs,places,LANG) data["questions"] = {} - data["questions"]["QA_0"] = getTextFromLid("FR",getRandomQuestion(0).TEXT_LID) - data["questions"]["QA_1"] = getTextFromLid("FR",getRandomQuestion(1).TEXT_LID) - data["traits"] = getTraits(LANG) + data["questions"]["QA_0"] = get_text_from_lid("FR",get_random_question(0).TEXT_LID) + data["questions"]["QA_1"] = get_text_from_lid("FR",get_random_question(1).TEXT_LID) + data["traits"] = get_traits(LANG) return data, reactions_table def read_image(path:str): @@ -253,8 +253,8 @@ def read_image(path:str): except: return 1 -def getTraitIdFromString(trait): - return getTraitFromText(trait) +def get_trait_id_from_string(trait): + return get_trait_from_text(trait) def get_npc_image(npc_id): return read_image(f"./truthseeker/static/images/npc/{npc_id}/0.png")