Skip to content

Commit

Permalink
Fixed an issue when analysing career pages with empty stats for a spe…
Browse files Browse the repository at this point in the history
…cific hero (#7)
  • Loading branch information
Valentin Porchet authored Dec 19, 2022
1 parent 7592a04 commit eceb5da
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 60 deletions.
2 changes: 1 addition & 1 deletion overfastapi/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

# List of players used for testing
players_ids = [
"copypasting-1216", # Player with an empty hero career stats (lucio)
"Dekk-2677", # Classic profile without rank
"KIRIKO-21253", # Profile with rank on only two roles
"Player-1112937", # Console player
"Player-137712", # Private profile
"SoSucre-2795", # Top player Open Queue
"TeKrop-2217", # Classic profile
"Unknown-1234", # No player
]
Expand Down
70 changes: 33 additions & 37 deletions overfastapi/models/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,124 +212,120 @@ class CareerStats(BaseModel):
None,
description="Total of statistics for all heroes",
alias="all-heroes",
min_items=1,
)
ana: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Ana", min_items=1
None, description="Career statistics for Ana"
)
ashe: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Ashe", min_items=1
None, description="Career statistics for Ashe"
)
baptiste: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Baptiste", min_items=1
None, description="Career statistics for Baptiste"
)
bastion: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Bastion", min_items=1
None, description="Career statistics for Bastion"
)
brigitte: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Brigitte", min_items=1
None, description="Career statistics for Brigitte"
)
cassidy: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Cassidy", min_items=1
None, description="Career statistics for Cassidy"
)
dva: list[HeroCareerStats] | None = Field(
None, description="Career statistics for D.Va", min_items=1
None, description="Career statistics for D.Va"
)
doomfist: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Doomfist", min_items=1
None, description="Career statistics for Doomfist"
)
echo: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Echo", min_items=1
None, description="Career statistics for Echo"
)
genji: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Genji", min_items=1
None, description="Career statistics for Genji"
)
hanzo: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Hanzo", min_items=1
None, description="Career statistics for Hanzo"
)
junker_queen: list[HeroCareerStats] | None = Field(
None,
description="Career statistics for Junker Queen",
alias="junker-queen",
min_items=1,
)
junkrat: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Junkrat", min_items=1
None, description="Career statistics for Junkrat"
)
kiriko: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Kiriko", min_items=1
None, description="Career statistics for Kiriko"
)
lucio: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Lúcio", min_items=1
None, description="Career statistics for Lúcio"
)
mei: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Mei", min_items=1
None, description="Career statistics for Mei"
)
mercy: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Mercy", min_items=1
None, description="Career statistics for Mercy"
)
moira: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Moira", min_items=1
None, description="Career statistics for Moira"
)
orisa: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Orisa", min_items=1
None, description="Career statistics for Orisa"
)
pharah: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Pharah", min_items=1
None, description="Career statistics for Pharah"
)
ramattra: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Ramattra", min_items=1
None, description="Career statistics for Ramattra"
)
reaper: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Reaper", min_items=1
None, description="Career statistics for Reaper"
)
reinhardt: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Reinhardt", min_items=1
None, description="Career statistics for Reinhardt"
)
roadhog: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Roadhog", min_items=1
None, description="Career statistics for Roadhog"
)
sigma: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Sigma", min_items=1
None, description="Career statistics for Sigma"
)
soldier_76: list[HeroCareerStats] | None = Field(
None,
description="Career statistics for Soldier: 76",
alias="soldier-76",
min_items=1,
)
sojourn: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Sojourn", min_items=1
None, description="Career statistics for Sojourn"
)
sombra: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Sombra", min_items=1
None, description="Career statistics for Sombra"
)
symmetra: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Symmetra", min_items=1
None, description="Career statistics for Symmetra"
)
torbjorn: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Torbjörn", min_items=1
None, description="Career statistics for Torbjörn"
)
tracer: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Tracer", min_items=1
None, description="Career statistics for Tracer"
)
widowmaker: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Widowmaker", min_items=1
None, description="Career statistics for Widowmaker"
)
winston: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Winston", min_items=1
None, description="Career statistics for Winston"
)
wrecking_ball: list[HeroCareerStats] | None = Field(
None,
description="Career statistics for Wrecking Ball",
alias="wrecking-ball",
min_items=1,
)
zarya: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Zarya", min_items=1
None, description="Career statistics for Zarya"
)
zenyatta: list[HeroCareerStats] | None = Field(
None, description="Career statistics for Zenyatta", min_items=1
None, description="Career statistics for Zenyatta"
)

class Config:
Expand Down
6 changes: 6 additions & 0 deletions overfastapi/parsers/player_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ def __get_career_stats(career_stats_section: Tag) -> dict:
}
)

# For a reason, sometimes the hero is in the dropdown but there
# is no stat to show. In this case, return None as if there was
# no stat at all
if len(career_stats[hero_key]) == 0:
career_stats[hero_key] = None

for hero_key in HeroKey:
if hero_key.value not in career_stats:
career_stats[hero_key.value] = None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "overfast-api"
version = "2.3.2"
version = "2.3.3"
description = "Overwatch API giving data about heroes, maps, and players statistics."
authors = ["TeKrop <tekrop@gmail.com>"]
license = "MIT"
Expand Down
20 changes: 0 additions & 20 deletions tests/fixtures/html/players/SoSucre-2795.html

This file was deleted.

20 changes: 20 additions & 0 deletions tests/fixtures/html/players/copypasting-1216.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion tests/fixtures/json/players/SoSucre-2795.json

This file was deleted.

1 change: 1 addition & 0 deletions tests/fixtures/json/players/copypasting-1216.json

Large diffs are not rendered by default.

0 comments on commit eceb5da

Please sign in to comment.