From 9756930ca4f05f990f6151bd97c0c4e328d2a462 Mon Sep 17 00:00:00 2001 From: Anton Komarev Date: Fri, 26 Aug 2022 08:43:01 +0300 Subject: [PATCH] Improve game end process --- app/bot.py | 3 ++- app/game.py | 10 ++++++---- app/game_registry.py | 8 +++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/bot.py b/app/bot.py index 7117cc9..4244eb4 100644 --- a/app/bot.py +++ b/app/bot.py @@ -226,7 +226,8 @@ async def create_game(chat: Chat, game_prototype: Game): async def end_game(chat: Chat, game: Game): - await game_registry.end_game(game) + game.end() + await game_registry.update_game(game) game_statistics = await game_registry.get_game_statistics(game) await chat.send_text(**game.render_results_system_message(game_statistics)) diff --git a/app/game.py b/app/game.py index b194497..7c70315 100644 --- a/app/game.py +++ b/app/game.py @@ -14,6 +14,9 @@ def __init__(self, chat_id: int, facilitator_message_id: int, name: str, facilit self.name = name self.facilitator = facilitator + def end(self): + self.status = self.STATUS_ENDED + def render_system_message(self): return { "text": self.render_system_message_text(), @@ -50,20 +53,19 @@ def render_facilitator_text(self) -> str: def render_name_text(self) -> str: if self.status == self.STATUS_STARTED: - return "Planning poker started: " + self.name + return "Game started: " + self.name elif self.status == self.STATUS_ENDED: - return "Planning poker ended: " + self.name + return "Game ended: " + self.name else: return "" def render_statistics_text(self, game_statistics) -> str: result = "" - result += "Estimated topics count: {}".format(game_statistics["estimated_game_sessions_count"]) + result += "Estimated topics: {}".format(game_statistics["estimated_game_sessions_count"]) return result - def to_dict(self): return { "facilitator": self.facilitator.to_dict(), diff --git a/app/game_registry.py b/app/game_registry.py index 69ce9e5..f8f7c28 100644 --- a/app/game_registry.py +++ b/app/game_registry.py @@ -96,7 +96,7 @@ async def create_game(self, game: Game): ) await self.db_connection.commit() - async def end_game(self, game: Game): + async def update_game(self, game: Game): await self.db_connection.execute( """ UPDATE game @@ -105,13 +105,11 @@ async def end_game(self, game: Game): """, { "game_id": game.id, - "game_status": game.STATUS_ENDED, + "game_status": game.status, } ) await self.db_connection.commit() - game.status = Game.STATUS_ENDED - async def find_active_game(self, chat_id: int, facilitator: TelegramUser) -> Game: query = """ SELECT @@ -298,4 +296,4 @@ async def get_game_statistics(self, game: Game): return { "estimated_game_sessions_count": row["estimated_game_sessions_count"], - } \ No newline at end of file + }