Skip to content

Commit

Permalink
Improve game end process
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Aug 26, 2022
1 parent f5cebb2 commit 9756930
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
10 changes: 6 additions & 4 deletions app/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 3 additions & 5 deletions app/game_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -298,4 +296,4 @@ async def get_game_statistics(self, game: Game):

return {
"estimated_game_sessions_count": row["estimated_game_sessions_count"],
}
}

0 comments on commit 9756930

Please sign in to comment.