Richer event context: buildup lines from the full play-by-play feed
'X is shown a red card' alone isn't insight — the story is in the surrounding plays. The ESPN summary carries a ~110-line play-by-play feed (attempts, fouls, corners, VAR checks) we cached but never used: - normalizer keeps a trimmed commentary list (schema v3; the boot backfill re-stores older matches automatically) - previews serve it; expanding a timeline event now shows up to four feed lines from the three minutes leading in, then the event's own description — e.g. Korea's saved attempt and corner right before Czechia's counter-goal header, or the foul behind a booking Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -145,6 +145,35 @@ export function eventContext(e: ParsedEvent): string | null {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
export interface CommentaryLine { minute: number | null; text: string }
|
||||
|
||||
/**
|
||||
* The feed lines leading into an event — the buildup story shown when a
|
||||
* timeline item is expanded (the saved attempt before a counter-goal, the
|
||||
* foul before a card, a VAR check). Anchored on the entry that IS the event
|
||||
* (same text), else the last entry at the event's minute; returns up to
|
||||
* `max` preceding lines no older than three minutes.
|
||||
*/
|
||||
export function buildup(e: ParsedEvent, commentary: CommentaryLine[], max = 4): CommentaryLine[] {
|
||||
if (e.minute == null || !commentary.length) return [];
|
||||
let anchor = commentary.findIndex((c) => c.text === e.raw);
|
||||
if (anchor === -1) {
|
||||
for (let i = 0; i < commentary.length; i++) {
|
||||
const m = commentary[i]!.minute;
|
||||
if (m != null && m <= e.minute) anchor = i;
|
||||
if (m != null && m > e.minute) break;
|
||||
}
|
||||
}
|
||||
if (anchor <= 0) return [];
|
||||
const out: CommentaryLine[] = [];
|
||||
for (let i = anchor - 1; i >= 0 && out.length < max; i--) {
|
||||
const c = commentary[i]!;
|
||||
if (c.minute == null || c.minute < e.minute - 3) break;
|
||||
out.unshift(c);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Score at half-time: last goal score at minute ≤ 45 (0–0 when none). */
|
||||
export function halfTimeScore(parsed: ParsedEvent[]): [number, number] {
|
||||
let ht: [number, number] = [0, 0];
|
||||
|
||||
Reference in New Issue
Block a user