Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 128x 128x 1x 1x 1x 1x 1x 1x 1x 49x 49x 49x 49x 49x 34x 34x 34x 34x 34x 34x 1x 1x 1x 1x 1x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 11x 11x 11x 43x 43x 43x 43x 43x 43x 1x 88x 88x 88x 88x 88x 1x 1x 43x 43x 43x 43x 43x 43x 43x 1x 1x 39x 39x 39x 39x 1x 1x 1x 1x 1x 1x 18x 18x 18x 18x 18x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 18x 18x 18x 18x 18x 1x 1x 1x 1x 1x 9x 9x 9x 9x 1x 1x 8x 8x 14x 7x 7x 7x 7x 7x 8x 8x 1x 8x 8x 1x 1x 1x 5x 5x 1x 9x 9x 9x 9x 9x 9x 9x 1x 1x 1x 1x 1x 1x 1x 6x 6x 4x 4x 30x 30x 4x 6x 15x 15x 15x 15x 15x 15x 15x 5x 4x 4x 4x 4x 15x 4x 4x 4x 4x 6x 3x 3x 1x 1x 4x 4x 6x 6x 3x 4x 4x 4x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 2x 4x 4x 4x 4x 4x 4x 4x 2x 5x 2x 2x 2x 2x 1x 1x 11x 5x 1x 1x | /**
* The Fest Team Schedule share card (SB-1917): one team's Fest matches at one
* age group, as a preview before a ball is kicked, a running record while the
* Fest is on, and a recap once every match is final. Pure functions only; the
* share modal fetches, the card draws.
*/
import { festKickoff } from './festCard';
/** Statuses whose score is final and counts toward the record. */
const FINAL = new Set(['completed', 'forfeit']);
const isFinal = m =>
FINAL.has(m?.match_status) && m.home_score != null && m.away_score != null;
const isLive = m => m?.match_status === 'live';
/** A match row's id for the team, or null when the team is not playing. */
const sideOf = (match, teamId) => {
if (match?.home_team?.id === teamId) return 'home';
if (match?.away_team?.id === teamId) return 'away';
return null;
};
/**
* "NSH"-style initials for a crest that has no logo. Club suffixes are left
* out so "Nashville SC" reads NSH-ish rather than "NS".
*/
export function opponentInitials(name) {
const words = String(name || '')
.split(/\s+/)
.filter(w => w && !/^(fc|sc|cf|ac|the)$/i.test(w));
if (!words.length) return '?';
if (words.length === 1) return words[0].slice(0, 3).toUpperCase();
return words
.map(w => w[0])
.join('')
.slice(0, 3)
.toUpperCase();
}
/**
* The team's result in one final match: W/D/L from its own side, the score
* with its goals first, and the shootout when a level match went to one.
*/
export function teamResult(match, teamId) {
const side = sideOf(match, teamId);
if (!side || !(isFinal(match) || isLive(match))) return null;
const own = side === 'home' ? match.home_score : match.away_score;
const opp = side === 'home' ? match.away_score : match.home_score;
const ownPens =
side === 'home' ? match.home_penalty_score : match.away_penalty_score;
const oppPens =
side === 'home' ? match.away_penalty_score : match.home_penalty_score;
const shootout = own === opp && ownPens != null && oppPens != null;
let letter = own > opp ? 'W' : own < opp ? 'L' : 'D';
if (shootout && ownPens !== oppPens) letter = ownPens > oppPens ? 'W' : 'L';
return {
letter,
score: `${own}–${opp}`,
pens: shootout ? `${ownPens}–${oppPens} pens` : null,
live: isLive(match),
own,
opp,
};
}
const kickoffTime = m => {
const t = Date.parse(m?.scheduled_kickoff || '');
if (!Number.isNaN(t)) return t;
const d = Date.parse(`${m?.match_date || ''}T12:00:00Z`);
return Number.isNaN(d) ? Infinity : d;
};
/** "Field 20" from "Arizona Athletic Grounds - Field 20"; null if none. */
export function fieldOf(location) {
const parts = String(location ?? '')
.split(/\s+-\s+|\s*·\s*/)
.map(p => p.trim())
.filter(Boolean);
const field = parts.reverse().find(p => /^(field|pitch)\b/i.test(p));
return field || null;
}
/** A knockout round's label ("Round of 16"); null for group games. */
const stageLabel = m => {
const round = m?.tournament_round;
if (!round || round === 'group_stage') return null;
return m.stage_label || round.replace(/_/g, ' ');
};
/**
* One row per match, in kickoff order. `tournamentLocation` is the
* tournament's venue, which sets the kickoff time zone (the match rows from
* the tournament list do not carry it).
*/
export function scheduleRows(matches, teamId, tournamentLocation = null) {
const rows = (matches || [])
.filter(m => sideOf(m, teamId))
.slice()
.sort((a, b) => kickoffTime(a) - kickoffTime(b))
.map(m => {
const side = sideOf(m, teamId);
const opponent = side === 'home' ? m.away_team : m.home_team;
const opponentClub =
side === 'home' ? m.away_team_club : m.home_team_club;
const k = festKickoff({ ...m, tournament_location: tournamentLocation });
const result = teamResult(m, teamId);
return {
id: m.id,
day: k.day,
date: k.date,
time: k.time,
isHome: side === 'home',
vs: side === 'home' ? 'VS' : '@',
opponent: {
name: opponent?.name || 'TBD',
logoUrl: opponentClub?.logo_url || null,
initials: opponentInitials(opponent?.name),
},
stage: stageLabel(m),
field: fieldOf(m.location),
status: result?.live ? 'live' : result ? 'final' : 'upcoming',
result,
isNext: false,
};
});
const next = rows.find(r => r.status !== 'final');
if (next && rows.some(r => r.status === 'final')) next.isNext = true;
return rows;
}
/**
* Which card to draw: 'preview' before any result, 'recap' once every match
* is final, 'progress' in between. A live match counts as not yet final.
*/
export function schedulePhase(rows) {
const finals = (rows || []).filter(r => r.status === 'final').length;
if (!finals) return 'preview';
return finals === rows.length ? 'recap' : 'progress';
}
/** W-D-L and goals over the final matches only. */
export function scheduleRecord(rows) {
const out = { w: 0, d: 0, l: 0, gf: 0, ga: 0, played: 0 };
for (const r of rows || []) {
if (r.status !== 'final') continue;
out.played += 1;
out[r.result.letter.toLowerCase()] += 1;
out.gf += r.result.own;
out.ga += r.result.opp;
}
return out;
}
export function scheduleEyebrow(phase, rows) {
if (phase === 'recap') return 'Fest recap';
if (phase === 'progress') {
const played = rows.filter(r => r.status === 'final').length;
return `Fest so far · ${played} of ${rows.length}`;
}
return 'Fest schedule';
}
export const ordinal = n => {
const mod100 = n % 100;
const suffix =
mod100 >= 11 && mod100 <= 13
? 'th'
: { 1: 'st', 2: 'nd', 3: 'rd' }[n % 10] || 'th';
return `${n}${suffix}`;
};
/**
* The team's finish in its group, from that group's matches: points, then
* goal difference, then goals for. Only when every match in the group is
* final; a table with games still to play is not a finish. Null otherwise,
* or when the team is not in it.
*/
export function groupFinish(groupMatches, teamId) {
const ms = groupMatches || [];
if (!ms.length || !ms.every(isFinal)) return null;
const table = new Map();
const row = id => {
if (!table.has(id)) table.set(id, { id, pts: 0, gd: 0, gf: 0 });
return table.get(id);
};
for (const m of ms) {
const h = row(m.home_team.id);
const a = row(m.away_team.id);
h.gf += m.home_score;
a.gf += m.away_score;
h.gd += m.home_score - m.away_score;
a.gd += m.away_score - m.home_score;
if (m.home_score > m.away_score) h.pts += 3;
else if (m.home_score < m.away_score) a.pts += 3;
else {
h.pts += 1;
a.pts += 1;
}
}
const sorted = [...table.values()].sort(
(x, y) => y.pts - x.pts || y.gd - x.gd || y.gf - x.gf
);
const index = sorted.findIndex(r => r.id === teamId);
if (index < 0) return null;
return { position: index + 1, size: sorted.length };
}
/** The team's group-stage group, from its group matches. */
export function teamGroup(matches, teamId) {
const m = (matches || []).find(
x =>
sideOf(x, teamId) &&
x.tournament_group &&
(!x.tournament_round || x.tournament_round === 'group_stage')
);
return m?.tournament_group || null;
}
/**
* The team's top scorers across the Fest, from logged goal events. Null when
* no goal for the team was logged: most teams log none, and an empty list
* would read as "nobody scored", which the score line contradicts.
*/
export function topScorers(events, teamId, limit = 3) {
const goals = (events || []).filter(
e => e?.event_type === 'goal' && e.team_id === teamId
);
if (!goals.length) return null;
const counts = new Map();
for (const e of goals) {
const key =
e.player_id != null ? `id:${e.player_id}` : `name:${e.player_name}`;
const cur = counts.get(key) || { name: e.player_name || null, goals: 0 };
cur.goals += 1;
counts.set(key, cur);
}
const named = [...counts.values()].filter(s => s.name);
if (!named.length) return null;
return named
.sort((a, b) => b.goals - a.goals || a.name.localeCompare(b.name))
.slice(0, limit);
}
/** Row density by match count: more matches, tighter rows. */
export function rowDensity(count) {
if (count <= 4) return 'roomy';
if (count <= 6) return 'compact';
return 'tight';
}
|