Skip to content

Commit

Permalink
🐛 Fix sub stat score property
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed May 11, 2024
1 parent f65deb0 commit 7028740
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/starrailrelicscore/client/relic_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,23 @@ def count_pairs(sets: List[str]) -> int:
@staticmethod
def score(relic: Dict, character_id: int) -> Score:
if (not relic) or (not character_id):
return Score(score="0", rating="N/A", main_stat_score=0)
return Score(
tid=0, score="0", rating="N/A", main_stat_score=0, sub_stat_score=[]
)
scaling = RelicScorer.get_scaling(character_id)
scoring_metadata: "METADATA_CH_TYPE" = get_scoring_metadata(character_id)
multipliers = scoring_metadata["stats"]

sum_value = 0
sub_stat_score = []
for sub_stat in relic["substats"]:
sum_value += (
score = (
sub_stat["value"]
* (multipliers.get(sub_stat["stat"], 0))
* scaling[sub_stat["stat"]]
)
sum_value += score
sub_stat_score.append(round(score, 1))

sum_value += RelicScorer.main_stat_free_roll(
relic["part"], relic["main"]["stat"], scoring_metadata
Expand All @@ -110,10 +115,11 @@ def score(relic: Dict, character_id: int) -> Score:
)

return Score(
tid=relic["tid"],
score=round(sum_value, 1),
rating=rating,
main_stat_score=main_stat_score,
tid=relic["tid"],
sub_stat_score=sub_stat_score,
meta=scoring_metadata,
)

Expand Down
3 changes: 2 additions & 1 deletion src/starrailrelicscore/models/relic_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class Rating(BaseModel):


class Score(BaseModel):
tid: int
score: float
rating: str
main_stat_score: float
tid: int
sub_stat_score: List[float]
meta: Optional[dict] = None


Expand Down
2 changes: 2 additions & 0 deletions tests/test_score_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def test_score_character():
avatars.append(Avatar(**b))
for avatar in avatars:
score = Character.score_character(avatar)
for relic in score.relics:
print(relic.sub_stat_score)
print(score.total_score)
print(score.total_rating)
assert score is not None

0 comments on commit 7028740

Please sign in to comment.