Skip to content

Commit

Permalink
Change ArmyResult field name
Browse files Browse the repository at this point in the history
  • Loading branch information
eoinnoble committed May 16, 2021
1 parent e412413 commit 48cf73a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
5 changes: 2 additions & 3 deletions server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Iterable,
List,
Optional,
OrderedDict,
Set,
Tuple
)
Expand Down Expand Up @@ -851,14 +850,14 @@ def get_player_outcome(self, player: Player) -> ArmyOutcome:

return self._results.outcome(army)

def get_army_results(self, player: Player) -> OrderedDict:
def get_army_results(self, player: Player) -> ArmyResult:
army = self.get_player_option(player.id, "Army")
return ArmyResult(
player.id,
army,
self.get_player_outcome(player).name,
self._results.metadata(army),
)._asdict()
)

def report_army_stats(self, stats_json):
self._army_stats_list = json.loads(stats_json)["stats"]
Expand Down
2 changes: 1 addition & 1 deletion server/games/game_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ArmyResult(NamedTuple):
"""
player_id: int
army: Optional[int]
army_result: str
army_outcome: str
metadata: List[str]


Expand Down
10 changes: 5 additions & 5 deletions server/games/typedefs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum, unique
from typing import Any, Dict, List, NamedTuple, Optional, OrderedDict, Set
from typing import Any, Dict, List, NamedTuple, Optional, Set

from server.games.game_results import GameOutcome
from server.games.game_results import ArmyResult, GameOutcome
from server.players import Player


Expand Down Expand Up @@ -123,7 +123,7 @@ class BasicGameInfo(NamedTuple):
class TeamRatingSummary(NamedTuple):
outcome: GameOutcome
player_ids: Set[int]
army_results: List[OrderedDict]
army_results: List[ArmyResult]


class EndedGameInfo(NamedTuple):
Expand Down Expand Up @@ -155,7 +155,7 @@ def from_basic(
validity: ValidityState,
team_outcomes: List[GameOutcome],
commander_kills: Dict[str, int],
team_army_results: List[List[OrderedDict]],
team_army_results: List[List[ArmyResult]],
) -> "EndedGameInfo":
if len(basic_info.teams) != len(team_outcomes):
raise ValueError(
Expand Down Expand Up @@ -193,7 +193,7 @@ def to_dict(self):
{
"outcome": team_summary.outcome.name,
"player_ids": list(team_summary.player_ids),
"army_results": team_summary.army_results,
"army_results": [result._asdict() for result in team_summary.army_results],
}
for team_summary in self.team_summaries
],
Expand Down
2 changes: 1 addition & 1 deletion tests/data/test-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ INSERT INTO `coop_map` (`type`, `name`, `description`, `version`, `filename`) VA
insert into game_featuredMods (id, gamemod, name, description, publish, git_url, git_branch, file_extension, allow_override) values
(1, 'faf', 'FAF', 'Forged Alliance Forever', 1, 'https://github.com/FAForever/fa.git', 'deploy/faf', 'nx2', FALSE),
(6, 'ladder1v1', 'FAF', 'Ladder games', 1, 'https://github.com/FAForever/fa.git', 'deploy/faf', 'nx2', TRUE),
(24, 'gw', '', 'Galactic War', 0, NULL, NULL, NULL, NULL), -- GW unpublished because you can't start them from "Host game"
(24, 'gw', '', 'Galactic War', 0, NULL, NULL, NULL, NULL), -- GW shouldn't show up in the featured mod list in the client
(25, 'coop', 'Coop', 'Multiplayer campaign games', 1, 'https://github.com/FAForever/fa-coop.git', 'master', 'cop', TRUE);

insert into game_stats (id, startTime, gameName, gameType, gameMod, host, mapId, validity) values
Expand Down
20 changes: 10 additions & 10 deletions tests/integration_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ async def test_galactic_war_1v1_game_ended_broadcasts_army_results(lobby_server,
host_proto,
[host_id, "Army", 1],
[host_id, "Team", 1],
[host_id, "StartSpot", 0],
[host_id, "StartSpot", 1],
[host_id, "Faction", 1],
[host_id, "Color", 1],
[guest_id, "Army", 2],
[guest_id, "Team", 2],
[guest_id, "StartSpot", 1],
[guest_id, "StartSpot", 2],
[guest_id, "Faction", 2],
[guest_id, "Color", 2],
)
Expand Down Expand Up @@ -637,7 +637,7 @@ async def test_galactic_war_1v1_game_ended_broadcasts_army_results(lobby_server,
{
"player_id": 3,
"army": 2,
"army_result": "DEFEAT",
"army_outcome": "DEFEAT",
"metadata": ["recall"],
},
]
Expand All @@ -649,7 +649,7 @@ async def test_galactic_war_1v1_game_ended_broadcasts_army_results(lobby_server,
{
"player_id": 1,
"army": 1,
"army_result": "VICTORY",
"army_outcome": "VICTORY",
"metadata": [],
},
]
Expand Down Expand Up @@ -692,17 +692,17 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server,
host_proto,
[host_id, "Army", 1],
[host_id, "Team", 0],
[host_id, "StartSpot", 0],
[host_id, "StartSpot", 1],
[host_id, "Faction", 1],
[host_id, "Color", 1],
[guest_id, "Army", 2],
[guest_id, "Team", 0],
[guest_id, "StartSpot", 1],
[guest_id, "StartSpot", 2],
[guest_id, "Faction", 1],
[guest_id, "Color", 2],
[other_guest_id, "Army", 3],
[other_guest_id, "Team", 2],
[other_guest_id, "StartSpot", 2],
[other_guest_id, "StartSpot", 3],
[other_guest_id, "Faction", 2],
[other_guest_id, "Color", 3],
)
Expand Down Expand Up @@ -772,13 +772,13 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server,
{
"player_id": 1,
"army": 1,
"army_result": "VICTORY",
"army_outcome": "VICTORY",
"metadata": [],
},
{
"player_id": 3,
"army": 2,
"army_result": "VICTORY",
"army_outcome": "VICTORY",
"metadata": ["recall"],
},
],
Expand All @@ -790,7 +790,7 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server,
{
"player_id": 6,
"army": 3,
"army_result": "DEFEAT",
"army_outcome": "DEFEAT",
"metadata": ["recall"],
},
],
Expand Down
18 changes: 9 additions & 9 deletions tests/unit_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ async def test_game_results(game: Game, players):
{
"player_id": team["player_ids"][0],
"army": army,
"army_result": outcome,
"army_outcome": outcome,
"metadata": [],
}
]
Expand Down Expand Up @@ -989,13 +989,13 @@ async def test_team_game_results(game: Game, game_add_players):
{
"player_id": 1,
"army": 0,
"army_result": "VICTORY",
"army_outcome": "VICTORY",
"metadata": [],
},
{
"player_id": 2,
"army": 1,
"army_result": "DEFEAT",
"army_outcome": "DEFEAT",
"metadata": [],
},
]
Expand All @@ -1004,13 +1004,13 @@ async def test_team_game_results(game: Game, game_add_players):
{
"player_id": 3,
"army": 2,
"army_result": "DEFEAT",
"army_outcome": "DEFEAT",
"metadata": [],
},
{
"player_id": 4,
"army": 3,
"army_result": "DEFEAT",
"army_outcome": "DEFEAT",
"metadata": [],
},
]
Expand Down Expand Up @@ -1038,13 +1038,13 @@ async def test_army_results_present_for_invalid_games(game: Game, game_add_playe
{
"player_id": 1,
"army": 0,
"army_result": "VICTORY",
"army_outcome": "VICTORY",
"metadata": [],
},
{
"player_id": 2,
"army": 1,
"army_result": "DEFEAT",
"army_outcome": "DEFEAT",
"metadata": [],
},
]
Expand All @@ -1053,13 +1053,13 @@ async def test_army_results_present_for_invalid_games(game: Game, game_add_playe
{
"player_id": 3,
"army": 2,
"army_result": "DEFEAT",
"army_outcome": "DEFEAT",
"metadata": [],
},
{
"player_id": 4,
"army": 3,
"army_result": "DEFEAT",
"army_outcome": "DEFEAT",
"metadata": [],
},
]
Expand Down

0 comments on commit 48cf73a

Please sign in to comment.