-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from EboMike/cleanup
Moved some code from the scorecard file to the helpers.
- Loading branch information
Showing
6 changed files
with
174 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Various constants and helpers when displaying stats about individual games. | ||
This is different from statshelper in that it does not calculate stats, it | ||
only deals with getting and extracting and visualizing data. | ||
""" | ||
from typing import List | ||
|
||
from db.types import PlayerStateDetailType | ||
|
||
"""Map of every possible player state and the display name for it in SM5 games. | ||
Multiple player states map to the same name since they're intended to be lumped | ||
together - in SM5, we don't care if a player is down because of a nuke or a | ||
missile. | ||
""" | ||
SM5_STATE_LABEL_MAP = { | ||
PlayerStateDetailType.ACTIVE: "Active", | ||
PlayerStateDetailType.DOWN_ZAPPED: "Down", | ||
PlayerStateDetailType.DOWN_MISSILED: "Down", | ||
PlayerStateDetailType.DOWN_NUKED: "Down", | ||
PlayerStateDetailType.DOWN_FOR_OTHER: "Down", | ||
PlayerStateDetailType.DOWN_FOR_RESUP: "Down (Resup)", | ||
PlayerStateDetailType.RESETTABLE: "Resettable", | ||
} | ||
|
||
"""Map of every SM5 player state and the color to use when visualizing it. | ||
All keys in this dict map to values in SM5_STATE_LABEL_MAP.""" | ||
SM5_STATE_COLORS = { | ||
"Active": "#11dd11", | ||
"Down": "#993202", | ||
"Down (Resup)": "#8702ab", | ||
"Resettable": "#cbd103", | ||
} | ||
|
||
|
||
def get_players_from_team(all_players: List[dict], team_index: int) -> List[dict]: | ||
"""Returns subset of the list of players - only those in the given team.""" | ||
return [ | ||
player for player in all_players if player["team"] == team_index | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import unittest | ||
|
||
from db.sm5 import SM5Game, SM5Stats | ||
from helpers.gamehelper import get_players_from_team | ||
from helpers.statshelper import count_zaps, get_sm5_kd_ratio, get_sm5_score_components | ||
from tests.helpers.environment import setup_test_database, ENTITY_ID_1, ENTITY_ID_2, get_sm5_game_id, \ | ||
teardown_test_database, create_destroy_base_event, add_entity, get_red_team | ||
|
||
|
||
class TestGameHelper(unittest.IsolatedAsyncioTestCase): | ||
async def asyncSetUp(self): | ||
await setup_test_database() | ||
|
||
async def asyncTearDown(self): | ||
await teardown_test_database() | ||
|
||
async def test_get_players_from_team(self): | ||
player1 = { | ||
"name": "Indy", | ||
"team": 0, | ||
} | ||
player2 = { | ||
"name": "Barbie", | ||
"team": 1, | ||
} | ||
player3 = { | ||
"name": "Sonic", | ||
"team": 1, | ||
} | ||
|
||
players_in_team = get_players_from_team([player1, player2, player3], team_index=1) | ||
|
||
self.assertCountEqual([player2, player3], players_in_team) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters