Fix score of leagues
This commit is contained in:
@@ -133,7 +133,7 @@ def _extract_legs(page: Page, fallback_date: datetime | None) -> list[Bet]:
|
|||||||
title = leg.locator("h3").first.get_attribute("title") or ""
|
title = leg.locator("h3").first.get_attribute("title") or ""
|
||||||
date_text = leg.locator(".betslip-leg-date span").first.inner_text()
|
date_text = leg.locator(".betslip-leg-date span").first.inner_text()
|
||||||
bet_text = leg.locator("[data-selection-id]").first.inner_text()
|
bet_text = leg.locator("[data-selection-id]").first.inner_text()
|
||||||
league = leg.locator(".f-mt-1.f-leading-tight.f-line-clamp-2").first.inner_text()
|
league = leg.locator(".f-mt-1.f-leading-tight.f-line-clamp-2").first.inner_text().replace("Fotbal /", "")
|
||||||
|
|
||||||
team1, team2 = _parse_teams(title)
|
team1, team2 = _parse_teams(title)
|
||||||
date = _parse_czech_date(date_text) or fallback_date or datetime.now()
|
date = _parse_czech_date(date_text) or fallback_date or datetime.now()
|
||||||
|
|||||||
@@ -213,13 +213,13 @@ class TicketResolver:
|
|||||||
return self._league_cache[key]
|
return self._league_cache[key]
|
||||||
|
|
||||||
# Static map — fuzzy match
|
# Static map — fuzzy match
|
||||||
patterns = list(self._league_map.keys())
|
patterns = [x.lower().strip() for x in self._league_map.keys()]
|
||||||
idx, score = _best_match(key, patterns)
|
idx, score = _best_match(key, patterns)
|
||||||
if idx is not None:
|
if idx is not None:
|
||||||
best_id = self._league_map[patterns[idx]]
|
best_id = self._league_map[patterns[idx]]
|
||||||
_ansi.log(_ansi.gray(f" │ league {league_name!r} -> id={best_id} (static map, pattern={patterns[idx]!r}, score={score:.2f})"))
|
_ansi.log(_ansi.gray(f" │ league {league_name!r} -> id={best_id} (static map, pattern={patterns[idx]!r}, score={score:.2f})"))
|
||||||
self._league_cache[key] = (best_id, 1.0)
|
self._league_cache[key] = (best_id, score)
|
||||||
return best_id, 1.0
|
return best_id, score
|
||||||
|
|
||||||
# API fallback — fuzzy match all results
|
# API fallback — fuzzy match all results
|
||||||
_ansi.log(_ansi.gray(f" │ GET /leagues search={league_name!r}"))
|
_ansi.log(_ansi.gray(f" │ GET /leagues search={league_name!r}"))
|
||||||
@@ -307,7 +307,10 @@ def _best_fixture_match(fixtures: list[dict[str, Any]], team1: str, team2: str,
|
|||||||
# Name similarity is the primary signal; date proximity is a tiebreaker
|
# Name similarity is the primary signal; date proximity is a tiebreaker
|
||||||
home_names = [f["teams"]["home"]["name"] for f in fixtures]
|
home_names = [f["teams"]["home"]["name"] for f in fixtures]
|
||||||
away_names = [f["teams"]["away"]["name"] for f in fixtures]
|
away_names = [f["teams"]["away"]["name"] for f in fixtures]
|
||||||
|
print(home_names)
|
||||||
|
print(away_names)
|
||||||
name_scores = [(_similarity(team1, h) + _similarity(team2, a)) / 2 for h, a in zip(home_names, away_names)]
|
name_scores = [(_similarity(team1, h) + _similarity(team2, a)) / 2 for h, a in zip(home_names, away_names)]
|
||||||
|
print(name_scores)
|
||||||
date_proxies = [_date_proximity(f, center) for f in fixtures]
|
date_proxies = [_date_proximity(f, center) for f in fixtures]
|
||||||
combined = [n * 0.8 + d * 0.2 for n, d in zip(name_scores, date_proxies)]
|
combined = [n * 0.8 + d * 0.2 for n, d in zip(name_scores, date_proxies)]
|
||||||
best_idx = max(range(len(combined)), key=lambda i: combined[i])
|
best_idx = max(range(len(combined)), key=lambda i: combined[i])
|
||||||
|
|||||||
Reference in New Issue
Block a user