goals fix

This commit is contained in:
2026-06-29 13:39:17 -05:00
parent 1d94f805fd
commit 7c910e9199

View File

@@ -1,4 +1,4 @@
import { GroupId, Match, MatchStatus, Team } from "./types";
import { GroupId, GoalEvent, Match, MatchStatus, Team } from "./types";
import { venueFor } from "./venues";
import { localisedTeamName } from "./team-mappings";
import { R32, LATER_ROUNDS, resolveAnnexC, qualifiedThirdGroups } from "./bracket";
@@ -568,7 +568,8 @@ interface Wc26Game {
home_score?: string;
away_score?: string;
time_elapsed?: string;
goals?: Array<{ name?: string; minute?: string; team?: string }>;
home_scorers?: string;
away_scorers?: string;
current_minute?: string;
}
@@ -736,15 +737,28 @@ export function attachKOLiveData(matches: Match[], teams: Team[], koGames: Wc26G
if (!isNaN(min)) result.minute = min;
}
// Torereignisse
if (wm.goals && wm.goals.length > 0) {
result.goals = wm.goals.map(g => ({
scorer: g.name ?? "?",
minute: parseInt(g.minute ?? "0", 10) || 0,
team: g.team?.toLowerCase() === "away" ? "away" as const : "home" as const,
}));
// Torereignisse aus home_scorers / away_scorers parsen (Format: "{\"Name Minute'\"}")
const goals: GoalEvent[] = [];
if (wm.home_scorers) parseScorers(wm.home_scorers, "home", goals);
if (wm.away_scorers) parseScorers(wm.away_scorers, "away", goals);
if (goals.length > 0) {
goals.sort((a, b) => a.minute - b.minute);
result.goals = goals;
}
return result;
});
}
// Parst worldcup26-Scorer-String: "{\"Casemiro 56'\"}" oder "{\"Player 12'\",\"Other 34'\"}"
function parseScorers(raw: string, team: "home" | "away", out: GoalEvent[]): void {
const cleaned = raw.replace(/[{}"\\]/g, "").trim();
if (!cleaned) return;
const parts = cleaned.split(",");
for (const p of parts) {
const m = /^(.+?)\s+(\d+)'?\s*$/.exec(p.trim());
if (m) {
out.push({ scorer: m[1].trim(), minute: parseInt(m[2], 10), team });
}
}
}