Spaces:
Sleeping
Sleeping
Create recommendation_engine.py
Browse files
analytics/recommendation_engine.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import Any
|
| 4 |
+
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
from analytics.confidence import compute_confidence
|
| 8 |
+
from analytics.recommendation_rules import apply_recommendation_rules
|
| 9 |
+
from models.live_fair_simulator_v3 import build_upcoming_simulated_rows
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def build_upcoming_hitter_recommendations(
|
| 13 |
+
game_row: dict[str, Any],
|
| 14 |
+
statcast_df: pd.DataFrame,
|
| 15 |
+
odds_df: pd.DataFrame | None = None,
|
| 16 |
+
weather_row: dict[str, Any] | None = None,
|
| 17 |
+
) -> list[dict[str, Any]]:
|
| 18 |
+
"""
|
| 19 |
+
Batch 3 decision-layer wrapper.
|
| 20 |
+
Uses simulated fair rows, then adds confidence + recommendation tier.
|
| 21 |
+
"""
|
| 22 |
+
rows = build_upcoming_simulated_rows(
|
| 23 |
+
game_row=game_row,
|
| 24 |
+
statcast_df=statcast_df,
|
| 25 |
+
weather_row=weather_row,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
recommendations: list[dict[str, Any]] = []
|
| 29 |
+
|
| 30 |
+
for row in rows:
|
| 31 |
+
confidence_block = compute_confidence(row, game_row=game_row)
|
| 32 |
+
row.update(confidence_block)
|
| 33 |
+
|
| 34 |
+
rules_block = apply_recommendation_rules(row)
|
| 35 |
+
row.update(rules_block)
|
| 36 |
+
|
| 37 |
+
recommendations.append(row)
|
| 38 |
+
|
| 39 |
+
return recommendations
|