Skip to content

Commit

Permalink
Modify HSR Pure Fiction and MOC Models (#192)
Browse files Browse the repository at this point in the history
* Add MOC challenge seasons

* Add challenge season to dunder all

* Use extract name approach

* Add seasons field to MOC and pure fiction models

* Export model to dunder all

Export StarRailChallengeSeason

* Remove name field from StarRailChallenge

* Remove name, season_id, begin_time, end_time fields

* Mark fields as deprecated
  • Loading branch information
seriaati authored Jun 11, 2024
1 parent dc44045 commit 01200ad
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions genshin/models/starrail/chronicle/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"FictionFloorNode",
"FloorNode",
"StarRailChallenge",
"StarRailChallengeSeason",
"StarRailFloor",
"StarRailPureFiction",
]
Expand All @@ -44,6 +45,16 @@ class StarRailFloor(APIModel):
is_chaos: bool


class StarRailChallengeSeason(APIModel):
"""A season of a challenge."""

id: int = Aliased("schedule_id")
name: str = Aliased("name_mi18n")
status: str
begin_time: PartialTime
end_time: PartialTime


class StarRailChallenge(APIModel):
"""Challenge in a season."""

Expand All @@ -58,13 +69,14 @@ class StarRailChallenge(APIModel):
has_data: bool

floors: List[StarRailFloor] = Aliased("all_floor_detail")
seasons: List[StarRailChallengeSeason] = Aliased("groups")

@pydantic.root_validator(pre=True)
def __extract_name(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "groups" in values and isinstance(values["groups"], List):
groups: List[Dict[str, Any]] = values["groups"]
if len(groups) > 0:
values["name"] = groups[0]["name_mi18n"]
if "seasons" in values and isinstance(values["seasons"], List):
seasons: List[Dict[str, Any]] = values["seasons"]
if len(seasons) > 0:
values["name"] = seasons[0]["name_mi18n"]

return values

Expand Down Expand Up @@ -105,27 +117,28 @@ def score(self) -> int:
class StarRailPureFiction(APIModel):
"""Pure Fiction challenge in a season."""

name: str
season_id: int
begin_time: PartialTime
end_time: PartialTime
name: str = pydantic.Field(deprecated="Use `season_id` together with `seasons instead`.")
season_id: int = pydantic.Field(deprecated="Use `season_id` together with `seasons instead`.")
begin_time: PartialTime = pydantic.Field(deprecated="Use `season_id` together with `seasons instead`.")
end_time: PartialTime = pydantic.Field(deprecated="Use `season_id` together with `seasons instead`.")

total_stars: int = Aliased("star_num")
max_floor: str
total_battles: int = Aliased("battle_num")
has_data: bool

floors: List[FictionFloor] = Aliased("all_floor_detail")
seasons: List[StarRailChallengeSeason] = Aliased("groups")
max_floor_id: int

@pydantic.root_validator(pre=True)
def __unnest_groups(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "groups" in values and isinstance(values["groups"], List):
groups: List[Dict[str, Any]] = values["groups"]
if len(groups) > 0:
values["name"] = groups[0]["name_mi18n"]
values["season_id"] = groups[0]["schedule_id"]
values["begin_time"] = groups[0]["begin_time"]
values["end_time"] = groups[0]["end_time"]
if "seasons" in values and isinstance(values["seasons"], List):
seasons: List[Dict[str, Any]] = values["seasons"]
if len(seasons) > 0:
values["name"] = seasons[0]["name_mi18n"]
values["season_id"] = seasons[0]["schedule_id"]
values["begin_time"] = seasons[0]["begin_time"]
values["end_time"] = seasons[0]["end_time"]

return values

0 comments on commit 01200ad

Please sign in to comment.