Skip to content

Commit

Permalink
Add game id to rating change message (#973)
Browse files Browse the repository at this point in the history
* Add game id to rating change message

* Fix integration test
  • Loading branch information
BlackYps authored Aug 20, 2023
1 parent 33c5e7b commit a6c626a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/rating_service/rating_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ async def _rate(self, summary: GameRatingSummary) -> None:

for rating_result in rating_results:
await self._publish_rating_changes(
rating_result.game_id,
rating_result.rating_type,
rating_result.old_ratings,
rating_result.new_ratings,
Expand Down Expand Up @@ -248,6 +249,7 @@ async def _rate_for_leaderboard(
)

return GameRatingResult(
game_id,
rating_type,
old_ratings,
new_ratings,
Expand Down Expand Up @@ -456,6 +458,7 @@ def _update_player_object(

async def _publish_rating_changes(
self,
game_id: int,
rating_type: str,
old_ratings: RatingDict,
new_ratings: RatingDict,
Expand All @@ -472,6 +475,7 @@ async def _publish_rating_changes(
old_rating = old_ratings[player_id]

rating_change_dict = {
"game_id": game_id,
"player_id": player_id,
"rating_type": rating_type,
"new_rating_mean": new_rating.mean,
Expand Down
1 change: 1 addition & 0 deletions server/rating_service/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def from_game_info_dict(cls, game_info: dict[str]) -> "GameRatingSummary":


class GameRatingResult(NamedTuple):
game_id: int
rating_type: str
old_ratings: RatingDict
new_ratings: RatingDict
Expand Down
2 changes: 2 additions & 0 deletions tests/integration_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ async def test_game_ended_broadcasts_rating_update(lobby_server, channel):
new_persisted_ratings = await get_player_ratings(host_proto, "test", "Rhiza")

rhiza_message = {
"game_id": 41956,
"player_id": 3, # Rhiza
"rating_type": "global",
"new_rating_mean": new_persisted_ratings["Rhiza"][0],
Expand All @@ -376,6 +377,7 @@ async def test_game_ended_broadcasts_rating_update(lobby_server, channel):
}

test_message = {
"game_id": 41956,
"player_id": 1, # test
"rating_type": "global",
"new_rating_mean": new_persisted_ratings["test"][0],
Expand Down

0 comments on commit a6c626a

Please sign in to comment.