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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 60x 60x 60x 60x 60x 60x 60x 1x 1x 1x 1x 1x 1x 1x 1x 1x 35x 35x 35x 35x 1x 1x 1x 1x 1x 1x 1x 1x 1x 68x 68x 68x 68x 68x 68x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 1x 1x 25x 25x 25x 1x 62x 62x 1x 1x 62x 62x 1x 1x 1x 1x 62x 34x 62x 34x 34x 34x 34x 34x 1x 1x 62x 62x 62x 1x 1x 1x 1x 1x 1x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 1x 1x 1x 1x 1x 26x 26x 26x 26x 1x 1x 1x 1x 1x 26x 26x 2x 2x 2x 2x 2x 26x 26x 26x | /** * The Scouting tab's head-to-head rows (SB-1906): both teams' main tables, * row by row, the way a tale of the tape reads. * * Fest teams come from different conferences, so a row compares two numbers * that each mean "inside my own table"; the panel says so. Absent stays * absent: a side with no value renders "—", never 0, and is never called * better or worse. */ /** "—" for absent, never 0: a team nobody measured has no value. */ export const fmt = v => (v == null ? '—' : v); export const perGame = v => (v == null ? '—' : Number(v).toFixed(1)); 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}`; }; const KIND_LABELS = { flex: 'Flex', pathway: 'Pro Player Pathway' }; /** "Pro Player Pathway", "Flex", or the league's own name. */ export const kindLabel = line => KIND_LABELS[line?.kind] || line?.league || line?.competition || 'League'; /** * A conference's name without the league it already sits under: "Northeast", * not "Northeast (Pro Player Pathway)" next to "Pro Player Pathway". */ export const conferenceName = line => { const name = line?.division?.name || ''; const suffix = ` (${kindLabel(line)})`; return name.endsWith(suffix) ? name.slice(0, -suffix.length) : name; }; /** A team's league line: Homegrown, Academy or Pro Player Pathway. */ export const leagueLine = dossier => (dossier?.conferences || []).find(l => l.kind !== 'flex') || null; /** * A team's main Flex conference: the one it has played most in, the first * listed on a tie. Flex gets the same head-to-head block as League (SB-1914): * a Flex conference winner goes to MLS NEXT Cup. */ export const flexLine = dossier => { const flex = (dossier?.conferences || []).filter(l => l.kind === 'flex'); return flex.reduce( (best, l) => ((l.played || 0) > (best?.played || 0) ? l : best), flex[0] || null ); }; /** * The head-to-head blocks: League, then Flex, each only when at least one * team has that table. Each block carries both teams' lines and its rows. */ export function scoutingSections(homeDossier, awayDossier) { return [ { key: 'league', title: 'League', home: leagueLine(homeDossier), away: leagueLine(awayDossier), }, { key: 'flex', title: 'Flex', home: flexLine(homeDossier), away: flexLine(awayDossier), }, ] .filter(s => s.home || s.away) .map(s => ({ ...s, rows: compareRows(s.home, s.away) })); } /** Conference lines not in a head-to-head block: a team's other Flex conferences. */ export const otherLines = dossier => { const shown = [leagueLine(dossier), flexLine(dossier)]; return (dossier?.conferences || []).filter(l => !shown.includes(l)); }; export const positionText = line => line?.position == null ? '—' : `${ordinal(line.position)} of ${fmt(line.table_size)}`; export const recordText = line => !line || line.no_results || line.wins == null ? '—' : `${fmt(line.wins)}-${fmt(line.draws)}-${fmt(line.losses)}`; const number = v => (v == null || Number.isNaN(Number(v)) ? null : Number(v)); /** Bar widths for two values, the larger one full; null when either is absent. */ const bars = (a, b) => { if (a == null || b == null) return null; const max = Math.max(a, b); if (max <= 0) return { home: 0, away: 0 }; return { home: Math.round((a / max) * 100), away: Math.round((b / max) * 100), }; }; /** Which side reads better, only when both have a value and they differ. */ const better = (a, b, higherIsBetter) => { if (a == null || b == null || a === b) return null; return a > b === higherIsBetter ? 'home' : 'away'; }; /** * Rows for the two primary lines (either may be null). Each row: * `{ key, label, home, away, better, bars }`; `better` and `bars` are null * whenever a comparison would rest on an absent value. */ export function compareRows(home, away) { const gf = [number(home?.gf_per_game), number(away?.gf_per_game)]; const ga = [number(home?.ga_per_game), number(away?.ga_per_game)]; return [ { key: 'position', label: 'Position', home: positionText(home), away: positionText(away), better: null, bars: null, }, { key: 'record', label: 'W-D-L', home: recordText(home), away: recordText(away), better: null, bars: null, }, { key: 'gf', label: 'Goals for / game', home: perGame(gf[0]), away: perGame(gf[1]), better: better(gf[0], gf[1], true), bars: bars(gf[0], gf[1]), }, { key: 'ga', label: 'Goals against / game', home: perGame(ga[0]), away: perGame(ga[1]), better: better(ga[0], ga[1], false), bars: bars(ga[0], ga[1]), }, ]; } /** * The context chips for one team: playing up or down, a pro academy whose * league sits a year up (SB-1900), a small sample. */ export function dossierLabels(dossier) { const flags = dossier?.flags || []; const context = dossier?.context; const out = []; if (flags.includes('playing_up')) { const from = context?.season_age_group?.name; let label = from ? `Playing up from ${from}` : 'Playing up'; if (flags.includes('playing_up_inferred')) label += ' (inferred)'; out.push(label); } if (flags.includes('playing_down')) out.push('Older age group'); if (flags.includes('league_age_up')) { const at = context?.season_age_group?.name; out.push( at ? `Pro academy · league at ${at}` : 'Pro academy · league a year up' ); } if (flags.includes('low_sample')) out.push('Small sample'); return out; } |