diff --git a/app/services/formula_engine.py b/app/services/formula_engine.py index c863051..2e55a65 100644 --- a/app/services/formula_engine.py +++ b/app/services/formula_engine.py @@ -90,13 +90,23 @@ def tier_from_value(value: float, track) -> int: Args: value: Computed formula value. - track: Object (or dict-like) with t1, t2, t3, t4 attributes/keys. + track: Object (or dict-like) with t1_threshold..t4_threshold attributes/keys. """ # Support both attribute-style (Peewee model) and dict (seed fixture) if isinstance(track, dict): - t1, t2, t3, t4 = track["t1"], track["t2"], track["t3"], track["t4"] + t1, t2, t3, t4 = ( + track["t1_threshold"], + track["t2_threshold"], + track["t3_threshold"], + track["t4_threshold"], + ) else: - t1, t2, t3, t4 = track.t1, track.t2, track.t3, track.t4 + t1, t2, t3, t4 = ( + track.t1_threshold, + track.t2_threshold, + track.t3_threshold, + track.t4_threshold, + ) if value >= t4: return 4 diff --git a/tests/test_formula_engine.py b/tests/test_formula_engine.py index 67c14a9..435cd92 100644 --- a/tests/test_formula_engine.py +++ b/tests/test_formula_engine.py @@ -43,9 +43,27 @@ def pitcher_stats(**kwargs): def track_dict(card_type: str) -> dict: """Return the locked threshold dict for a given card_type.""" return { - "batter": {"card_type": "batter", "t1": 37, "t2": 149, "t3": 448, "t4": 896}, - "sp": {"card_type": "sp", "t1": 10, "t2": 40, "t3": 120, "t4": 240}, - "rp": {"card_type": "rp", "t1": 3, "t2": 12, "t3": 35, "t4": 70}, + "batter": { + "card_type": "batter", + "t1_threshold": 37, + "t2_threshold": 149, + "t3_threshold": 448, + "t4_threshold": 896, + }, + "sp": { + "card_type": "sp", + "t1_threshold": 10, + "t2_threshold": 40, + "t3_threshold": 120, + "t4_threshold": 240, + }, + "rp": { + "card_type": "rp", + "t1_threshold": 3, + "t2_threshold": 12, + "t3_threshold": 35, + "t4_threshold": 70, + }, }[card_type]