Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.2.5: REFACTOR blitz-model changes #33

Merged
merged 7 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "blitz-models"
version = "1.2.4"
version = "1.2.5"
authors = [{ name = "Jylpah", email = "[email protected]" }]
description = "Pydantic models for Wargaming's World of Tanks Blitz game "
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions src/blitzmodels/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def index(self) -> Idx:
return self.id


class Maps(JSONExportableRootDict[Map]):
class Maps(JSONExportableRootDict[int, Map]):
"""Container model for Maps"""

_exclude_unset = False
Expand Down Expand Up @@ -144,7 +144,7 @@ def load_yaml(cls, yaml_doc: str) -> Self | None:
maps_yaml = safe_load(yaml_doc)
for key, map_cfg in maps_yaml["maps"].items():
try:
map_id: int = map_cfg["id"]
map_id: int = int(map_cfg["id"])
modes: List[int] = map_cfg["availableModes"]
localization_code: str = map_cfg["localName"]
maps.add(
Expand Down
4 changes: 2 additions & 2 deletions src/blitzmodels/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def update_title(self, tankopedia: WGApiWoTBlitzTankopedia, maps: Maps) -> str:
else:
tank_name = self.playerVehicleName

if self.mapName in maps:
map_name = maps[self.mapName].name
if self.mapId in maps:
map_name = maps[self.mapId].name
else:
map_name = self.mapName
# self.title = f"{tank_name} @ {map_name} by {self.playerName}"
Expand Down
1 change: 0 additions & 1 deletion src/blitzmodels/wg_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ class WGApiWoTBlitzTankopedia(WGApiWoTBlitz):
data: Dict[str, Tank] = Field(default=dict(), alias="d")
codes: Dict[str, Tank] = Field(default=dict(), alias="c")

# TODO: Implement tier cache
_tier_cache: Dict[int, Set[TankId]] = dict()

_exclude_export_DB_fields = {"codes": True}
Expand Down
6 changes: 3 additions & 3 deletions src/blitzmodels/wotinspector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
ReplayDetail as ReplayDetail,
ReplayAchievement as ReplayAchievement,
WoTBlitzMaps as WoTBlitzMaps,
EnumWinnerTeam as EnumWinnerTeam,
EnumBattleResult as EnumBattleResult,
EnumVehicleTypeInt as EnumVehicleTypeInt,
EnumWinnerTeam as EnumWinnerTeam,
EnumBattleResult as EnumBattleResult,
EnumVehicleTypeInt as EnumVehicleTypeInt,
)

__all__ = [
Expand Down
15 changes: 8 additions & 7 deletions src/blitzmodels/wotinspector/wi_apiv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ class ReplayDetail(JSONExportable):
vehicle_descr : int | None = Field(default=None, alias='vi')
wp_points_earned : int | None = Field(default=None, alias='we')
wp_points_stolen : int | None = Field(default=None, alias='ws')
# TODO[pydantic]: The following keys were removed: `allow_mutation`.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.

model_config = ConfigDict(extra="allow", frozen=False, validate_assignment=True, populate_by_name=True)


Expand Down Expand Up @@ -267,9 +266,12 @@ class ReplayData(JSONExportable):

_ViewUrlBase: str = "https://replays.wotinspector.com/en/view/"
_DLurlBase : str = "https://replays.wotinspector.com/en/download/"
# TODO[pydantic]: The following keys were removed: `allow_mutation`.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
model_config = ConfigDict(arbitrary_types_allowed=True, frozen=False, validate_assignment=True, populate_by_name=True)

model_config = ConfigDict(
# arbitrary_types_allowed=True,
frozen=False,
validate_assignment=True,
populate_by_name=True)

_exclude_export_DB_fields = {
"view_url": True,
Expand Down Expand Up @@ -1409,8 +1411,7 @@ def get_battle_result(self, player: int | None = None) -> EnumBattleResult:
# enemies : list[int] = Field(default=..., alias="e")
# mastery_badge : int | None = Field(default=None, alias="mb")
# details : ReplayDetail | list[ReplayDetail] = Field(default=..., alias="d")
# # TODO[pydantic]: The following keys were removed: `allow_mutation`.
# # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.

# model_config = ConfigDict(extra="allow", frozen=False, validate_assignment=True, populate_by_name=True)

# @field_validator("vehicle_tier")
Expand Down
5 changes: 4 additions & 1 deletion src/blitzmodels/wotinspector/wi_apiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ def root(self) -> Self:
self._TimestampFormat
),
)
if self.battle_result == EnumBattleResult.loss and self.winner_team == EnumWinnerTeam.draw:
if (
self.battle_result == EnumBattleResult.loss
and self.winner_team == EnumWinnerTeam.draw
):
self.battle_result = EnumBattleResult.draw
return self

Expand Down
13 changes: 13 additions & 0 deletions tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ async def test_1_import_export(
len(maps) == count
), f"could not import all maps: got {len(maps)}, expected {count}"

for key, map in maps.items():
assert isinstance(key, int), f"imported map keys are not int, but {type(key)}"
assert isinstance(
map.id, int
), f"imported map.id are not int, but {type(map.id)}"


@pytest.mark.asyncio
@MAPS
Expand Down Expand Up @@ -229,6 +235,13 @@ async def test_4_open_yaml(
assert (
maps := await Maps.open_yaml(maps_yaml)
) is not None, f"could not open maps from YAML file: {maps_yaml.name}"

for key, map in maps.items():
assert isinstance(key, int), f"imported map keys are not int, but {type(key)}"
assert isinstance(
map.id, int
), f"imported map.id are not int, but {type(map.id)}"

assert (
len(maps) == maps_new
), f"incorrect number of maps read from a YAML file: {len(maps)} != {maps_new}"
Expand Down