gg
This commit is contained in:
@@ -59,7 +59,7 @@ def fetch_matches(conn, sport: str):
|
||||
|
||||
|
||||
def flush_features_batch(conn, rows, dry_run: bool, sport: str = 'football'):
|
||||
"""Bulk upsert a batch of (match_id, home_elo, away_elo) into sport-partitioned ai_features table."""
|
||||
"""Bulk upsert ELO features into sport-partitioned ai_features table."""
|
||||
if not rows or dry_run:
|
||||
return
|
||||
|
||||
@@ -70,19 +70,27 @@ def flush_features_batch(conn, rows, dry_run: bool, sport: str = 'football'):
|
||||
f"""
|
||||
INSERT INTO {table_name}
|
||||
(match_id, home_elo, away_elo,
|
||||
home_home_elo, away_away_elo,
|
||||
home_form_elo, away_form_elo,
|
||||
elo_diff,
|
||||
home_form_score, away_form_score,
|
||||
missing_players_impact, calculator_ver, updated_at)
|
||||
VALUES %s
|
||||
ON CONFLICT (match_id) DO UPDATE SET
|
||||
home_elo = EXCLUDED.home_elo,
|
||||
away_elo = EXCLUDED.away_elo,
|
||||
home_home_elo = EXCLUDED.home_home_elo,
|
||||
away_away_elo = EXCLUDED.away_away_elo,
|
||||
home_form_elo = EXCLUDED.home_form_elo,
|
||||
away_form_elo = EXCLUDED.away_form_elo,
|
||||
elo_diff = EXCLUDED.elo_diff,
|
||||
home_form_score = EXCLUDED.home_form_score,
|
||||
away_form_score = EXCLUDED.away_form_score,
|
||||
calculator_ver = EXCLUDED.calculator_ver,
|
||||
updated_at = EXCLUDED.updated_at
|
||||
""",
|
||||
rows,
|
||||
template="(%s, %s, %s, %s, %s, 0.0, %s, NOW())",
|
||||
template="(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 0.0, %s, NOW())",
|
||||
page_size=500,
|
||||
)
|
||||
conn.commit()
|
||||
@@ -136,16 +144,24 @@ def backfill(sport: str, batch_size: int, dry_run: bool):
|
||||
if not home_id or not away_id:
|
||||
continue
|
||||
|
||||
# Snapshot PRE-match ELO
|
||||
# Snapshot PRE-match ELO (all dimensions)
|
||||
home_rating = elo.get_or_create_rating(home_id, h_name or "")
|
||||
away_rating = elo.get_or_create_rating(away_id, a_name or "")
|
||||
|
||||
h_overall = round(home_rating.overall_elo, 2)
|
||||
a_overall = round(away_rating.overall_elo, 2)
|
||||
|
||||
feature_buf.append((
|
||||
match_id,
|
||||
round(home_rating.overall_elo, 2),
|
||||
round(away_rating.overall_elo, 2),
|
||||
round(form_to_score(home_rating.recent_form), 2),
|
||||
round(form_to_score(away_rating.recent_form), 2),
|
||||
h_overall, # home_elo
|
||||
a_overall, # away_elo
|
||||
round(home_rating.home_elo, 2), # home_home_elo
|
||||
round(away_rating.away_elo, 2), # away_away_elo
|
||||
round(home_rating.form_elo, 2), # home_form_elo
|
||||
round(away_rating.form_elo, 2), # away_form_elo
|
||||
round(h_overall - a_overall, 2), # elo_diff
|
||||
round(form_to_score(home_rating.recent_form), 2), # home_form_score
|
||||
round(form_to_score(away_rating.recent_form), 2), # away_form_score
|
||||
CALCULATOR_VER,
|
||||
))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user