Compare commits

..

1 Commits

Author SHA1 Message Date
ef11cdbac3 Convert scripts to use Typer and add requirements.txt
- Replaced argparse with Typer for CLI argument parsing in both scripts
- Updated function signatures and calls accordingly in build_season_schedule.py and compute_ratings.py
- Added requirements.txt listing dependencies including typer[all], pandas, numpy, etc.
2025-08-28 15:06:10 -05:00
3 changed files with 5 additions and 16 deletions

View File

@@ -291,7 +291,6 @@ def main(
def match_opponent(text: str) -> Optional[TeamRec]:
return best_match_team(text, by_slug, by_norm)
# Group by game_id if available; otherwise fallback on (date + unordered pair + raw score text if present)
buckets: Dict[str, dict] = {}
fallback_rows = 0
@@ -336,7 +335,6 @@ def main(
if fallback_rows:
logging.info(f"Used fallback dedupe for {fallback_rows} rows without game_id.")
# Merge perspectives into a single home/away row
out_rows = []
time_cache: Dict[str, Optional[str]] = {}
@@ -345,11 +343,9 @@ def main(
date = p[0]["date"]
game_id = bucket.get("game_id", "")
# Identify home/away perspectives
p_home = next((x for x in p if x["is_away"] is False), None)
p_away = next((x for x in p if x["is_away"] is True), None)
# Team identities
home_team = (p_home["team"] if p_home else (p_away["opp"] if p_away else None))
away_team = (p_away["team"] if p_away else (p_home["opp"] if p_home else None))
@@ -358,7 +354,6 @@ def main(
return rec.slug, rec.instance_id, rec.team_id, rec.name
return fallback_slug, "", "", fallback_slug.replace("-", " ").title()
# Prefer runs from the explicit perspective (home if available; otherwise away)
home_runs = away_runs = None
if p_home and isinstance(p_home["team_runs"], int) and isinstance(p_home["opp_runs"], int):
home_runs = p_home["team_runs"]
@@ -367,7 +362,6 @@ def main(
away_runs = p_away["team_runs"]
home_runs = p_away["opp_runs"]
# Fallback: single perspective present but numbers known → place by is_away
if (home_runs is None or away_runs is None) and p:
one = p[0]
if isinstance(one["team_runs"], int) and isinstance(one["opp_runs"], int):
@@ -378,7 +372,6 @@ def main(
home_runs = one["team_runs"]; away_runs = one["opp_runs"]
home_team = one["team"]; away_team = one["opp"] if one["opp"] else away_team
# Pack final team identifiers (fallback slug = guess from perspectives)
guess_home_fallback = (p_home["team"].slug if p_home and p_home["team"] else
p_away["opp"].slug if p_away and p_away["opp"] else
p[0]["pair"][0])
@@ -389,7 +382,6 @@ def main(
home_slug, home_inst, home_id, home_name = pack_team(home_team, guess_home_fallback)
away_slug, away_inst, away_id, away_name = pack_team(away_team, guess_away_fallback)
# Winner/loser
winner_slug = winner_inst = winner_id = loser_slug = loser_inst = loser_id = ""
if isinstance(home_runs, int) and isinstance(away_runs, int):
if home_runs > away_runs:
@@ -399,12 +391,10 @@ def main(
winner_slug, winner_inst, winner_id = away_slug, away_inst, away_id
loser_slug, loser_inst, loser_id = home_slug, home_inst, home_id
# Meta from perspectives
loc = (p_home["location"] if p_home else "") or (p_away["location"] if p_away else "")
status = (p_home["status"] if p_home else "") or (p_away["status"] if p_away else "")
source_urls = sorted({x["source_url"] for x in p})
# -------- NEW: fetch game start time from game page --------
time_local = ""
if fetch_time and game_id:
if game_id in time_cache:

View File

@@ -141,7 +141,6 @@ def elo_once(df: pd.DataFrame, K: float, H: float, mcap: float, init: dict[str,f
def elo(df: pd.DataFrame, K=24.0, H=30.0, mcap=2.0, shuffles=20, seed=42) -> pd.Series:
teams = sorted(set(df["HomeTeam"]).union(df["AwayTeam"]))
base = {t: 1500.0 for t in teams}
# baseline in chronological order (Date may be NaT; sort is stable)
df0 = df.sort_values(["Date"]).reset_index(drop=True)
r_first = elo_once(df0, K, H, mcap, base)
rng = np.random.default_rng(seed)

View File

@@ -1,5 +1,5 @@
typer[all]==0.16.1
pandas==2.3.2
numpy==2.3.2
beautifulsoup4==4.13.5
requests==2.32.5
typer[all]
pandas
numpy
beautifulsoup4
requests