Skip to content

Commit 94e8e68

Browse files
committed
refactor: consistently apply PEP-8 formatting and improve readability
1 parent e5d290f commit 94e8e68

30 files changed

Lines changed: 668 additions & 724 deletions

src/swgoh_comlink/StatCalc/calculator.py

Lines changed: 68 additions & 182 deletions
Large diffs are not rendered by default.

src/swgoh_comlink/StatCalc/calculator_async.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ async def _async_fetch_game_data_from_github(cls) -> dict[str, Any]:
7979
payload = response.json()
8080
except Exception as exc:
8181
cls._LOGGER.exception("Failed to fetch game data from GitHub")
82-
raise RuntimeError(
83-
f"Unable to retrieve game data from {cls._DEFAULT_GAMEDATA_URL}"
84-
) from exc
82+
raise RuntimeError(f"Unable to retrieve game data from {cls._DEFAULT_GAMEDATA_URL}") from exc
8583

8684
return cls._normalize_game_data_payload(payload)

src/swgoh_comlink/StatCalc/data_builder/_builder_base.py

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
_RELIC_SUFFIX_RE = re.compile(r"(\d+)$")
109109

110110

111-
112111
# ===================================================================
113112
# Public API
114113
# ===================================================================
@@ -133,8 +132,7 @@ def _build_game_data(raw: dict[str, Any]) -> dict[str, Any]:
133132
``gpTables``, ``relicData``.
134133
"""
135134
logger.debug(
136-
"Raw game data keys: %s | units=%d equipment=%d "
137-
"statProgression=%d skill=%d relicTierDefinition=%d",
135+
"Raw game data keys: %s | units=%d equipment=%d statProgression=%d skill=%d relicTierDefinition=%d",
138136
sorted(raw.keys()),
139137
len(raw.get("units", [])),
140138
len(raw.get("equipment", [])),
@@ -193,16 +191,13 @@ def _build_stat_tables(raw_progressions: list[dict[str, Any]]) -> dict[str, dict
193191
tables: dict[str, dict[str, int | float]] = {}
194192

195193
# Extract only the stattable items from the raw progression collection
196-
stat_progression_tables = [table for table in raw_progressions if
197-
table.get('id', "").startswith('stattable_')]
194+
stat_progression_tables = [table for table in raw_progressions if table.get("id", "").startswith("stattable_")]
198195

199196
for table in stat_progression_tables:
200197
table_id = table.get("id", "")
201198
table_data: dict[str, int | float] = {}
202199
for stat in table.get("stat", {}).get("stat", []):
203-
table_data[str(stat.get("unitStatId", ""))] = _num(
204-
stat.get("unscaledDecimalValue", 0)
205-
)
200+
table_data[str(stat.get("unitStatId", ""))] = _num(stat.get("unscaledDecimalValue", 0))
206201
tables[table_id] = table_data
207202
return tables
208203

@@ -252,10 +247,7 @@ def _build_unit_data(
252247
total_units = 0
253248

254249
# Filter for only obtainable units at rarity 1
255-
base_unit_list = [
256-
unit for unit in raw_units
257-
if unit.get("obtainable", False) and unit.get("obtainableTime") == "0"
258-
]
250+
base_unit_list = [unit for unit in raw_units if unit.get("obtainable", False) and unit.get("obtainableTime") == "0"]
259251

260252
for unit in base_unit_list:
261253
rarity = unit.get("rarity", 1)
@@ -280,13 +272,9 @@ def _build_unit_data(
280272
primary_stat = unit.get("primaryUnitStat", 2)
281273

282274
if combat_type == 1:
283-
data[base_id] = _build_character(
284-
base_id, unit, primary_stat, stat_prog_map, stat_tables, skills_map
285-
)
275+
data[base_id] = _build_character(base_id, unit, primary_stat, stat_prog_map, stat_tables, skills_map)
286276
else:
287-
data[base_id] = _build_ship(
288-
base_id, unit, primary_stat, stat_prog_map, stat_tables, skills_map
289-
)
277+
data[base_id] = _build_ship(base_id, unit, primary_stat, stat_prog_map, stat_tables, skills_map)
290278
return data
291279

292280

@@ -304,9 +292,7 @@ def _build_character(
304292
tier_num = str(gt.get("tier", 1))
305293
tier_stats: dict[str, int | float] = {}
306294
for s in gt.get("baseStat", {}).get("stat", []):
307-
tier_stats[str(s.get("unitStatId", ""))] = _num(
308-
s.get("unscaledDecimalValue", 0)
309-
)
295+
tier_stats[str(s.get("unitStatId", ""))] = _num(s.get("unscaledDecimalValue", 0))
310296
gear_lvl[tier_num] = {
311297
"gear": gt.get("equipmentSet", []),
312298
"stats": tier_stats,
@@ -354,9 +340,7 @@ def _build_ship(
354340
# Base stats
355341
stats: dict[str, int | float] = {}
356342
for s in unit.get("baseStat", {}).get("stat", []):
357-
stats[str(s.get("unitStatId", ""))] = _num(
358-
s.get("unscaledDecimalValue", 0)
359-
)
343+
stats[str(s.get("unitStatId", ""))] = _num(s.get("unscaledDecimalValue", 0))
360344

361345
# Growth modifiers per rarity
362346
growth: dict[str, dict[str, int | float]] = {}
@@ -375,9 +359,7 @@ def _build_ship(
375359
crew: list[str] = []
376360
for member in unit.get("crew", []):
377361
crew.append(member.get("unitId", ""))
378-
crew_skill_refs = _resolve_skills(
379-
member.get("skillReference", []), skills_map
380-
)
362+
crew_skill_refs = _resolve_skills(member.get("skillReference", []), skills_map)
381363
skill_refs.extend(crew_skill_refs)
382364

383365
return {
@@ -401,16 +383,15 @@ def _build_gear_data(raw_equipment: list[dict[str, Any]]) -> dict[str, dict[str,
401383
if len(stat_list) > 0:
402384
stats: dict[str, int | float] = {}
403385
for stat in stat_list:
404-
stats[str(stat.get("unitStatId", ""))] = _num(
405-
stat.get("unscaledDecimalValue", 0)
406-
)
386+
stats[str(stat.get("unitStatId", ""))] = _num(stat.get("unscaledDecimalValue", 0))
407387
data[gear_id] = {"stats": stats}
408388
else:
409389
no_stats += 1
410390
if not data:
411391
logger.warning(
412392
"Gear data is empty: %d equipment items received, %d had no statList",
413-
len(raw_equipment), no_stats,
393+
len(raw_equipment),
394+
no_stats,
414395
)
415396
return data
416397

@@ -520,9 +501,7 @@ def _build_relic_data(
520501
relic_id = relic.get("id", "")
521502
stats: dict[str, int | float] = {}
522503
for s in relic.get("stat", {}).get("stat", []):
523-
stats[str(s.get("unitStatId", ""))] = _num(
524-
s.get("unscaledDecimalValue", 0)
525-
)
504+
stats[str(s.get("unitStatId", ""))] = _num(s.get("unscaledDecimalValue", 0))
526505
gms = dict(stat_tables.get(relic.get("relicStatTable", ""), {}))
527506
data[relic_id] = {"stats": stats, "gms": gms}
528507
return data
@@ -612,9 +591,7 @@ def _mod_gp_rows(rows: list[dict[str, Any]]) -> dict[str, dict[str, dict[str, fl
612591
if len(parts) < 4:
613592
continue
614593
pips, level, tier = parts[0], parts[1], parts[2]
615-
out.setdefault(pips, {}).setdefault(level, {})[tier] = _num(
616-
r.get("value", 0)
617-
)
594+
out.setdefault(pips, {}).setdefault(level, {})[tier] = _num(r.get("value", 0))
618595
return out
619596

620597

@@ -655,7 +632,6 @@ def _gear_piece_gp_rows(rows: list[dict[str, Any]]) -> dict[str, dict[str, float
655632
return out
656633

657634

658-
659635
def _ability_special_gp(rows: list[dict[str, Any]]) -> dict[str, float]:
660636
"""Parse ability-special table for GP (flat key→value)."""
661637
return {r.get("key", ""): _num(r.get("value", 0)) for r in rows}
@@ -691,9 +667,7 @@ def _num(value: Any) -> int | float:
691667
return 0
692668

693669

694-
def _resolve_skills(
695-
refs: list[dict[str, Any]], skills_map: dict[str, dict[str, Any]]
696-
) -> list[dict[str, Any]]:
670+
def _resolve_skills(refs: list[dict[str, Any]], skills_map: dict[str, dict[str, Any]]) -> list[dict[str, Any]]:
697671
"""Map ``skillReferenceList`` entries to resolved skill dicts."""
698672
out: list[dict[str, Any]] = []
699673
for ref in refs:

src/swgoh_comlink/_base.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _mask(value: str | None, visible: int = 4) -> str:
8383
def __repr__(self) -> str:
8484
cls_name = type(self).__name__
8585
return (
86-
f"{cls_name}("
86+
f"{cls_name} version {self.__version__!r} ("
8787
f"url={self.url_base!r}, "
8888
f"hmac={self.hmac}, "
8989
f"access_key={self._mask(self.access_key)!r}, "
@@ -234,9 +234,7 @@ def _build_game_data_payload(
234234
return payload
235235

236236
@staticmethod
237-
def _build_unit_stats_endpoint(
238-
flags: list[str] | None = None, language: str | None = None
239-
) -> str:
237+
def _build_unit_stats_endpoint(flags: list[str] | None = None, language: str | None = None) -> str:
240238
"""Build the stats endpoint string with query parameters.
241239
242240
Returns:
@@ -276,3 +274,15 @@ def _build_unit_stats_endpoint(
276274
query_string = "?" + "&".join(filter(None, iter([flag_str, lang_str])))
277275

278276
return "api" + query_string if query_string else "api"
277+
278+
@property
279+
def version(self) -> str:
280+
return self.__version__
281+
282+
@version.setter
283+
def version(self, value: str) -> None:
284+
raise AttributeError("Module 'version' is read-only")
285+
286+
@version.deleter
287+
def version(self) -> None:
288+
raise AttributeError("Module 'version' is read-only")

src/swgoh_comlink/helpers/__init__.py

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,32 @@
1919
get_current_gac_event,
2020
get_gac_brackets,
2121
search_gac_brackets,
22-
)
22+
)
2323
from ._game_data import (
2424
create_localized_unit_name_dictionary,
2525
get_current_datacron_sets,
2626
get_datacron_dismantle_total,
2727
get_datacron_dismantle_value,
2828
get_playable_units,
2929
get_raid_leaderboard_ids,
30-
)
30+
)
3131
from ._guild import async_get_guild_members, get_guild_members
32+
from ._localization import (
33+
parse_swgoh_string,
34+
)
3235
from ._omicron import (
3336
get_omicron_skill_tier,
3437
get_omicron_skills,
3538
get_tw_omicrons,
3639
get_unit_from_skill,
3740
is_omicron_skill,
38-
)
41+
)
3942
from ._sentinels import (
4043
GIVEN,
4144
MISSING,
4245
REQUIRED,
4346
MutualExclusiveRequired,
44-
)
47+
)
4548
from ._stat_data import (
4649
LANGUAGES,
4750
MOD_SET_IDS,
@@ -52,74 +55,71 @@
5255
UNIT_RARITY,
5356
UNIT_RARITY_NAMES,
5457
UNIT_STAT_ENUMS_MAP,
55-
)
58+
)
5659
from ._utils import (
5760
convert_relic_tier,
5861
get_enum_key_by_value,
5962
get_function_name,
6063
human_time,
6164
sanitize_allycode,
6265
validate_file_path,
63-
)
64-
from ._localization import (
65-
parse_swgoh_string,
66-
)
66+
)
6767

6868
__all__ = [
69-
# Sentinels
70-
"GIVEN",
71-
"MISSING",
72-
"MutualExclusiveRequired",
73-
"REQUIRED",
74-
# Enums and constants
75-
"Constants",
76-
"DataItems",
77-
# Stat data
78-
"LANGUAGES",
79-
"MOD_SET_IDS",
80-
"MOD_SLOTS",
81-
"OMICRON_MODE",
82-
"STAT_ENUMS",
83-
"STATS",
84-
"UNIT_RARITY",
85-
"UNIT_RARITY_NAMES",
86-
"UNIT_STAT_ENUMS_MAP",
87-
# Decorators
88-
"func_debug_logger",
89-
"func_timer",
90-
# Utility functions
91-
"convert_relic_tier",
92-
"get_enum_key_by_value",
93-
"get_function_name",
94-
"human_time",
95-
"sanitize_allycode",
96-
"validate_file_path",
97-
"parse_swgoh_string",
98-
# Arena
99-
"get_arena_payout",
100-
"get_max_rank_jump",
101-
# GAC
102-
"async_get_current_gac_event",
103-
"async_get_gac_brackets",
104-
"convert_divisions_to_int",
105-
"convert_league_to_int",
106-
"get_current_gac_event",
107-
"get_gac_brackets",
108-
"search_gac_brackets",
109-
# Game data
110-
"create_localized_unit_name_dictionary",
111-
"get_current_datacron_sets",
112-
"get_datacron_dismantle_total",
113-
"get_datacron_dismantle_value",
114-
"get_playable_units",
115-
"get_raid_leaderboard_ids",
116-
# Guild
117-
"async_get_guild_members",
118-
"get_guild_members",
119-
# Omicron
120-
"get_omicron_skill_tier",
121-
"get_omicron_skills",
122-
"get_tw_omicrons",
123-
"get_unit_from_skill",
124-
"is_omicron_skill",
125-
]
69+
# Sentinels
70+
"GIVEN",
71+
"MISSING",
72+
"MutualExclusiveRequired",
73+
"REQUIRED",
74+
# Enums and constants
75+
"Constants",
76+
"DataItems",
77+
# Stat data
78+
"LANGUAGES",
79+
"MOD_SET_IDS",
80+
"MOD_SLOTS",
81+
"OMICRON_MODE",
82+
"STAT_ENUMS",
83+
"STATS",
84+
"UNIT_RARITY",
85+
"UNIT_RARITY_NAMES",
86+
"UNIT_STAT_ENUMS_MAP",
87+
# Decorators
88+
"func_debug_logger",
89+
"func_timer",
90+
# Utility functions
91+
"convert_relic_tier",
92+
"get_enum_key_by_value",
93+
"get_function_name",
94+
"human_time",
95+
"sanitize_allycode",
96+
"validate_file_path",
97+
"parse_swgoh_string",
98+
# Arena
99+
"get_arena_payout",
100+
"get_max_rank_jump",
101+
# GAC
102+
"async_get_current_gac_event",
103+
"async_get_gac_brackets",
104+
"convert_divisions_to_int",
105+
"convert_league_to_int",
106+
"get_current_gac_event",
107+
"get_gac_brackets",
108+
"search_gac_brackets",
109+
# Game data
110+
"create_localized_unit_name_dictionary",
111+
"get_current_datacron_sets",
112+
"get_datacron_dismantle_total",
113+
"get_datacron_dismantle_value",
114+
"get_playable_units",
115+
"get_raid_leaderboard_ids",
116+
# Guild
117+
"async_get_guild_members",
118+
"get_guild_members",
119+
# Omicron
120+
"get_omicron_skill_tier",
121+
"get_omicron_skills",
122+
"get_tw_omicrons",
123+
"get_unit_from_skill",
124+
"is_omicron_skill",
125+
]

0 commit comments

Comments
 (0)