Spaces:
Sleeping
Sleeping
Update analytics/recommendation_rules.py
Browse files
analytics/recommendation_rules.py
CHANGED
|
@@ -5,10 +5,11 @@ from typing import Any
|
|
| 5 |
|
| 6 |
def apply_recommendation_rules(edge_row: dict[str, Any]) -> dict[str, Any]:
|
| 7 |
"""
|
| 8 |
-
Converts edge/confidence into
|
|
|
|
| 9 |
"""
|
| 10 |
-
|
| 11 |
-
|
| 12 |
confidence = float(edge_row.get("confidence", 0.0) or 0.0)
|
| 13 |
slot = str(edge_row.get("slot", "") or "").strip().lower()
|
| 14 |
|
|
@@ -16,29 +17,39 @@ def apply_recommendation_rules(edge_row: dict[str, Any]) -> dict[str, Any]:
|
|
| 16 |
|
| 17 |
slot_boost = 0.0
|
| 18 |
if slot == "on deck":
|
| 19 |
-
slot_boost = 0.
|
| 20 |
reason_tags.append("On-deck priority")
|
| 21 |
elif slot == "in hole":
|
| 22 |
-
slot_boost = 0.
|
| 23 |
reason_tags.append("In-hole visibility")
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
adjusted_edge =
|
| 26 |
|
| 27 |
if confidence < 50:
|
| 28 |
tier = "pass"
|
| 29 |
reason_tags.append("Low confidence")
|
| 30 |
-
elif adjusted_edge >= 0.
|
| 31 |
tier = "bet"
|
| 32 |
reason_tags.append("Strong positive edge")
|
| 33 |
-
elif adjusted_edge >= 0.
|
| 34 |
tier = "watch"
|
| 35 |
reason_tags.append("Watchlist edge")
|
| 36 |
else:
|
| 37 |
tier = "pass"
|
| 38 |
reason_tags.append("Below action threshold")
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
return {
|
| 41 |
"recommendation_tier": tier,
|
| 42 |
-
"reason_tags": reason_tags,
|
| 43 |
"adjusted_edge": adjusted_edge,
|
|
|
|
| 44 |
}
|
|
|
|
| 5 |
|
| 6 |
def apply_recommendation_rules(edge_row: dict[str, Any]) -> dict[str, Any]:
|
| 7 |
"""
|
| 8 |
+
Converts edge/confidence into recommendation tiers.
|
| 9 |
+
Focuses on HR market first for now.
|
| 10 |
"""
|
| 11 |
+
hr_edge = float(edge_row.get("hr_edge", 0.0) or 0.0)
|
| 12 |
+
hr_bet_ev = float(edge_row.get("hr_bet_ev", 0.0) or 0.0)
|
| 13 |
confidence = float(edge_row.get("confidence", 0.0) or 0.0)
|
| 14 |
slot = str(edge_row.get("slot", "") or "").strip().lower()
|
| 15 |
|
|
|
|
| 17 |
|
| 18 |
slot_boost = 0.0
|
| 19 |
if slot == "on deck":
|
| 20 |
+
slot_boost = 0.012
|
| 21 |
reason_tags.append("On-deck priority")
|
| 22 |
elif slot == "in hole":
|
| 23 |
+
slot_boost = 0.006
|
| 24 |
reason_tags.append("In-hole visibility")
|
| 25 |
+
elif slot == "3 away":
|
| 26 |
+
slot_boost = 0.0
|
| 27 |
+
reason_tags.append("Farther from action window")
|
| 28 |
|
| 29 |
+
adjusted_edge = hr_edge + slot_boost
|
| 30 |
|
| 31 |
if confidence < 50:
|
| 32 |
tier = "pass"
|
| 33 |
reason_tags.append("Low confidence")
|
| 34 |
+
elif adjusted_edge >= 0.06 and hr_bet_ev > 0 and confidence >= 78:
|
| 35 |
tier = "bet"
|
| 36 |
reason_tags.append("Strong positive edge")
|
| 37 |
+
elif adjusted_edge >= 0.025 and confidence >= 62:
|
| 38 |
tier = "watch"
|
| 39 |
reason_tags.append("Watchlist edge")
|
| 40 |
else:
|
| 41 |
tier = "pass"
|
| 42 |
reason_tags.append("Below action threshold")
|
| 43 |
|
| 44 |
+
priority_score = adjusted_edge * 100 + (confidence / 10.0)
|
| 45 |
+
if slot == "on deck":
|
| 46 |
+
priority_score += 2.0
|
| 47 |
+
elif slot == "in hole":
|
| 48 |
+
priority_score += 1.0
|
| 49 |
+
|
| 50 |
return {
|
| 51 |
"recommendation_tier": tier,
|
| 52 |
+
"reason_tags": reason_tags[:6],
|
| 53 |
"adjusted_edge": adjusted_edge,
|
| 54 |
+
"priority_score": priority_score,
|
| 55 |
}
|