Spaces:
Sleeping
Sleeping
Update database/db.py
Browse files- database/db.py +52 -0
database/db.py
CHANGED
|
@@ -141,6 +141,58 @@ def insert_bet(
|
|
| 141 |
],
|
| 142 |
)
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
def ensure_recommendation_outcomes_table(conn) -> None:
|
| 146 |
conn.execute(
|
|
|
|
| 141 |
],
|
| 142 |
)
|
| 143 |
|
| 144 |
+
def read_recommendation_audit_view(conn) -> pd.DataFrame:
|
| 145 |
+
ensure_recommendation_logs_table(conn)
|
| 146 |
+
ensure_recommendation_outcomes_table(conn)
|
| 147 |
+
|
| 148 |
+
query = """
|
| 149 |
+
SELECT
|
| 150 |
+
l.created_at,
|
| 151 |
+
l.game_pk,
|
| 152 |
+
l.away_team,
|
| 153 |
+
l.home_team,
|
| 154 |
+
l.status,
|
| 155 |
+
l.slot,
|
| 156 |
+
l.batter_name,
|
| 157 |
+
l.pitcher_name,
|
| 158 |
+
l.ev90,
|
| 159 |
+
l.hit_prob,
|
| 160 |
+
l.hr_prob,
|
| 161 |
+
l.tb2p_prob,
|
| 162 |
+
l.fair_hit_odds,
|
| 163 |
+
l.fair_hr_odds,
|
| 164 |
+
l.fair_tb2p_odds,
|
| 165 |
+
l.book_hit_odds,
|
| 166 |
+
l.book_hr_odds,
|
| 167 |
+
l.book_tb2p_odds,
|
| 168 |
+
l.hit_edge,
|
| 169 |
+
l.hr_edge,
|
| 170 |
+
l.tb2p_edge,
|
| 171 |
+
l.adjusted_edge,
|
| 172 |
+
l.hit_bet_ev,
|
| 173 |
+
l.hr_bet_ev,
|
| 174 |
+
l.tb2p_bet_ev,
|
| 175 |
+
l.confidence,
|
| 176 |
+
l.confidence_bucket,
|
| 177 |
+
l.recommendation_tier,
|
| 178 |
+
l.priority_score,
|
| 179 |
+
l.reason_tags,
|
| 180 |
+
l.starter_stays_next_batter_prob,
|
| 181 |
+
l.starter_stays_next_inning_prob,
|
| 182 |
+
l.bullpen_entry_prob,
|
| 183 |
+
o.realized_hit,
|
| 184 |
+
o.realized_hr,
|
| 185 |
+
o.realized_tb2p,
|
| 186 |
+
o.graded_at,
|
| 187 |
+
o.outcome_source
|
| 188 |
+
FROM recommendation_logs l
|
| 189 |
+
LEFT JOIN recommendation_outcomes o
|
| 190 |
+
ON l.game_pk = o.game_pk
|
| 191 |
+
AND l.batter_name = o.batter_name
|
| 192 |
+
AND l.slot = o.slot
|
| 193 |
+
ORDER BY l.created_at DESC
|
| 194 |
+
"""
|
| 195 |
+
return conn.execute(query).df()
|
| 196 |
|
| 197 |
def ensure_recommendation_outcomes_table(conn) -> None:
|
| 198 |
conn.execute(
|