Spaces:
Running on T4
Running on T4
Download backend/app/common/labels.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/common/labels.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/backend/app/common/labels.py
-
curl -L -o labels.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/common/labels.py
1 kB
| """Small lookups shared by several modules: mode and focus labels, score tones, the drill catalog.""" | |
| from collections.abc import Iterable | |
| from functools import cache | |
| DISCIPLINES = {"h": "hitting", "p": "pitching"} # session mode -> ai_coach drill discipline | |
| FOCUS_LABEL = {"h": "Hitting", "p": "Pitching", "both": "Both"} # coach focus -> display label | |
| TONE_GREEN_MIN = 80 # overall score at or above: "g"; at or above TONE_YELLOW_MIN: "y"; below: "r" | |
| TONE_YELLOW_MIN = 60 | |
| def drill_catalog() -> dict[str, dict]: | |
| """ai_coach catalog drills by id.""" | |
| from ai_coach.knowledge import all_drills | |
| return {d["id"]: d for d in all_drills()} | |
| def tone(score: int | None) -> str: | |
| if score is None: | |
| return "y" | |
| return "g" if score >= TONE_GREEN_MIN else "y" if score >= TONE_YELLOW_MIN else "r" | |
| def tone_counts(scores: Iterable[int]) -> dict[str, int]: | |
| counts = dict.fromkeys("gyr", 0) | |
| for score in scores: | |
| counts[tone(score)] += 1 | |
| return counts | |