Spaces:
Sleeping
Sleeping
Create recommendation_logger.py
Browse files
analytics/recommendation_logger.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import Any
|
| 4 |
+
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def build_recommendation_log_rows(
|
| 9 |
+
recommendations: list[dict[str, Any]],
|
| 10 |
+
game_row: dict[str, Any],
|
| 11 |
+
created_at: str,
|
| 12 |
+
) -> pd.DataFrame:
|
| 13 |
+
rows: list[dict[str, Any]] = []
|
| 14 |
+
|
| 15 |
+
away_team = str(game_row.get("away_team", "") or "").strip()
|
| 16 |
+
home_team = str(game_row.get("home_team", "") or "").strip()
|
| 17 |
+
status = str(game_row.get("status", "") or "").strip()
|
| 18 |
+
game_pk = str(game_row.get("game_pk", "") or "").strip()
|
| 19 |
+
|
| 20 |
+
for rec in recommendations:
|
| 21 |
+
rows.append(
|
| 22 |
+
{
|
| 23 |
+
"created_at": created_at,
|
| 24 |
+
"game_pk": game_pk,
|
| 25 |
+
"away_team": away_team,
|
| 26 |
+
"home_team": home_team,
|
| 27 |
+
"status": status,
|
| 28 |
+
"slot": rec.get("slot"),
|
| 29 |
+
"batter_name": rec.get("batter_name"),
|
| 30 |
+
"pitcher_name": rec.get("pitcher_name"),
|
| 31 |
+
"ev90": rec.get("ev90"),
|
| 32 |
+
"hit_prob": rec.get("hit_prob"),
|
| 33 |
+
"hr_prob": rec.get("hr_prob"),
|
| 34 |
+
"tb2p_prob": rec.get("tb2p_prob"),
|
| 35 |
+
"fair_hit_odds": rec.get("fair_hit_odds"),
|
| 36 |
+
"fair_hr_odds": rec.get("fair_hr_odds"),
|
| 37 |
+
"fair_tb2p_odds": rec.get("fair_tb2p_odds"),
|
| 38 |
+
"book_hit_odds": rec.get("book_hit_odds"),
|
| 39 |
+
"book_hr_odds": rec.get("book_hr_odds"),
|
| 40 |
+
"book_tb2p_odds": rec.get("book_tb2p_odds"),
|
| 41 |
+
"hit_edge": rec.get("hit_edge"),
|
| 42 |
+
"hr_edge": rec.get("hr_edge"),
|
| 43 |
+
"tb2p_edge": rec.get("tb2p_edge"),
|
| 44 |
+
"adjusted_edge": rec.get("adjusted_edge"),
|
| 45 |
+
"hit_bet_ev": rec.get("hit_bet_ev"),
|
| 46 |
+
"hr_bet_ev": rec.get("hr_bet_ev"),
|
| 47 |
+
"tb2p_bet_ev": rec.get("tb2p_bet_ev"),
|
| 48 |
+
"confidence": rec.get("confidence"),
|
| 49 |
+
"confidence_bucket": rec.get("confidence_bucket"),
|
| 50 |
+
"recommendation_tier": rec.get("recommendation_tier"),
|
| 51 |
+
"priority_score": rec.get("priority_score"),
|
| 52 |
+
"reason_tags": " | ".join(rec.get("reason_tags", []) or []),
|
| 53 |
+
"starter_stays_next_batter_prob": rec.get("starter_stays_next_batter_prob"),
|
| 54 |
+
"starter_stays_next_inning_prob": rec.get("starter_stays_next_inning_prob"),
|
| 55 |
+
"bullpen_entry_prob": rec.get("bullpen_entry_prob"),
|
| 56 |
+
}
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
return pd.DataFrame(rows)
|