Files
iddaai-be/ai-engine/utils/league_reliability.py
T
fahricansecer 2f0b85a0c7
Deploy Iddaai Backend / build-and-deploy (push) Failing after 18s
first (part 2: other directories)
2026-04-16 15:11:25 +03:00

55 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
League Reliability Loader
=========================
Loads pre-computed per-league odds reliability scores from
data/league_reliability.json. Called once at orchestrator startup.
The reliability score (0.0 1.0) represents how well-calibrated
a league's betting odds are based on historical Brier Score analysis.
Usage:
from utils.league_reliability import load_league_reliability
lookup = load_league_reliability()
rel = lookup.get(league_id, 0.35)
"""
from __future__ import annotations
import json
import os
from typing import Dict
_DATA_FILE = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"..",
"data",
"league_reliability.json",
)
def load_league_reliability() -> Dict[str, float]:
"""
Returns a dict mapping league_id → odds_reliability (0.0-1.0).
Falls back gracefully to an empty dict if the file is missing.
"""
if not os.path.isfile(_DATA_FILE):
print(
f"⚠️ league_reliability.json not found at {_DATA_FILE}. "
"All leagues will use default reliability (0.35)."
)
return {}
try:
with open(_DATA_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
lookup: Dict[str, float] = data.get("lookup", {})
total = len(lookup)
print(f"✅ Loaded odds reliability for {total} leagues")
return lookup
except (json.JSONDecodeError, KeyError, TypeError) as exc:
print(f"⚠️ Failed to parse league_reliability.json: {exc}")
return {}