Skip to content

Commit

Permalink
revert: StarRailChallenge and StarRailPureFiction models
Browse files Browse the repository at this point in the history
  • Loading branch information
KT-Yeh committed Jun 29, 2024
1 parent dcaba8e commit 4f45eff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
13 changes: 13 additions & 0 deletions genshin/client/components/chronicle/starrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ async def get_starrail_pure_fiction(
"""Get starrail pure fiction runs."""
payload = dict(schedule_type=2 if previous else 1, need_all="true")
data = await self._request_starrail_record("challenge_story", uid, lang=lang, payload=payload)

# In "groups", it contains time data from both the current season and previous season.
data = dict(data)
time = data["groups"][0]
if previous is True and len(data["groups"]) > 1:
time = data["groups"][1]

# Extract the time data.
data["season_id"] = time["schedule_id"]
data["begin_time"] = time["begin_time"]
data["end_time"] = time["end_time"]
data["name"] = time["name_mi18n"]

return models.StarRailPureFiction(**data)

async def get_starrail_apc_shadow(
Expand Down
36 changes: 4 additions & 32 deletions genshin/models/starrail/chronicle/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class StarRailChallengeSeason(APIModel):
class StarRailChallenge(APIModel):
"""Memory of chaos challenge in a season."""

name: str
season: int = Aliased("schedule_id")
begin_time: PartialTime
end_time: PartialTime
Expand All @@ -81,16 +80,6 @@ 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 "seasons" in values and isinstance(values["seasons"], List):
seasons: List[Dict[str, Any]] = values["seasons"]
if len(seasons) > 0 and "name_mi18n" in seasons[0]:
values["name"] = seasons[0]["name_mi18n"]

return values


class ChallengeBuff(APIModel):
Expand Down Expand Up @@ -125,36 +114,19 @@ def score(self) -> int:
class StarRailPureFiction(APIModel):
"""Pure Fiction challenge in a season."""

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`.")
name: str
season_id: int
begin_time: PartialTime
end_time: PartialTime

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 "seasons" in values and isinstance(values["seasons"], List):
seasons: List[Dict[str, Any]] = values["seasons"]
if len(seasons) > 0:
if "name_mi18n" in seasons[0]:
values["name"] = seasons[0]["name_mi18n"]
if "schedule_id" in seasons[0]:
values["season_id"] = seasons[0]["schedule_id"]
if "begin_time" in seasons[0]:
values["begin_time"] = seasons[0]["begin_time"]
if "end_time" in seasons[0]:
values["end_time"] = seasons[0]["end_time"]

return values


class APCShadowFloorNode(FloorNode):
"""Node for a apocalyptic shadow floor."""
Expand Down

0 comments on commit 4f45eff

Please sign in to comment.