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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 169x 169x 169x 169x 169x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 144x 39x 39x 105x 143x 35x 105x 105x 34x 1x 105x 105x 144x 144x 144x 144x 1x 1x 44x 44x 44x 44x 44x 44x 44x 44x 44x 1x 1x 1x 1x 1x 1x 1x 34x 102x 102x 102x 102x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 136x 34x 136x 68x 102x 34x 34x 136x 34x 34x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 91x 90x 91x 79x 1x 1x 1x 1x 102x 101x 102x 101x 101x 101x 101x 101x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 2x 2x 2x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 1x 1x 1x 1x 1x 1x 1x 1x 24x 23x 24x 21x 24x 24x 24x 1x 1x 1x 1x 1x 22x 22x 20x 20x 22x 22x 22x 59x 59x 59x 59x 59x 59x 59x 22x 22x 22x 22x 22x 22x 22x | /**
* Formatting for the Power Rating list (SB-1809), kept pure so the rules that
* matter — absent is never zero, a rating reads like a rating — are tested
* without mounting anything.
*/
// The two badges the run stores (`PowerRatingDAO`), short on the chip with
// the rule in the title. Pro academy is a row flag, not a stored badge.
export const BADGES = {
provisional: {
label: 'Provisional',
title: 'Provisional: 6 or 7 matches, so the rating still moves quickly',
},
low_cross_conference: {
label: 'Low cross-conf.',
title:
'Low cross-conference data: fewer than 3 matches against other conferences',
},
};
const MINUS = '−';
/** 1642 -> "1,642". Null stays null: no rating is not a rating of 0. */
export const formatRating = rating =>
rating == null ? null : Number(rating).toLocaleString('en-US');
/** 1 -> "1st", 12 -> "12th", 22 -> "22nd". */
export const ordinal = n => {
if (n == null) return null;
const mod100 = n % 100;
if (mod100 >= 11 && mod100 <= 13) return `${n}th`;
return `${n}${{ 1: 'st', 2: 'nd', 3: 'rd' }[n % 10] || 'th'}`;
};
/**
* Movement over 7 days, as places and points: "▲2 · +12", "▼1 · −8".
*
* Null is absent, never "▲0": no run a week earlier (`movementSince` null)
* renders nothing, and a team that was not in that run reads "New". A rank
* that held drops its arrow and keeps the points; an unchanged rating is ±0.
* Returns `{ text, direction }` or null; direction is 'up' | 'down' | 'flat'
* | 'new'.
*/
export const formatMovement = (rankChange, ratingChange, movementSince) => {
if (rankChange == null && ratingChange == null) {
return movementSince ? { text: 'New', direction: 'new' } : null;
}
const parts = [];
if (rankChange > 0) parts.push(`▲${rankChange}`);
else if (rankChange < 0) parts.push(`▼${Math.abs(rankChange)}`);
if (ratingChange != null) {
if (ratingChange > 0) parts.push(`+${ratingChange}`);
else if (ratingChange < 0) parts.push(`${MINUS}${Math.abs(ratingChange)}`);
else parts.push('±0');
}
// Places lead; with no place change the points decide the colour.
const lead = rankChange || ratingChange || 0;
const direction = lead > 0 ? 'up' : lead < 0 ? 'down' : 'flat';
return { text: parts.join(' · '), direction };
};
/** "2026-12-15T10:00:04Z" -> "Dec 15, 2026"; null for nothing usable. */
export const formatUpdated = computedAt => {
if (!computedAt) return null;
const d = new Date(computedAt);
if (Number.isNaN(d.getTime())) return null;
return d.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
});
};
/**
* The national list under its tier headers, in the order `tiers` gives.
* Ranked teams below the lowest cut-off go under "Others"; teams outside the
* main island (`comparable_nationally` false, no national rank) go last,
* under their own header, never interleaved into the order.
*/
export const groupByTier = (teams, tiers) => {
const groups = (tiers || []).map(t => ({
key: t.key,
label: t.label,
hint: `${formatRating(t.min)}+`,
rows: [],
}));
const byKey = Object.fromEntries(groups.map(g => [g.key, g]));
const lowest = (tiers || []).reduce(
(min, t) => (min == null || t.min < min ? t.min : min),
null
);
const others = {
key: 'others',
label: 'Others',
hint: lowest == null ? null : `below ${formatRating(lowest)}`,
rows: [],
};
const apart = {
key: 'not_comparable',
label: 'Not yet comparable nationally',
hint: 'shown with their conference',
rows: [],
};
for (const row of teams || []) {
if (row.comparable_nationally === false || row.rank == null) {
apart.rows.push(row);
} else if (row.tier && byKey[row.tier]) {
byKey[row.tier].rows.push(row);
} else {
others.rows.push(row);
}
}
return [...groups, others, apart].filter(g => g.rows.length > 0);
};
// --- the team's "why" panel (SB-1810) ------------------------------------
// The badges in words, for the panel. Same rules as the chip titles.
export const BADGE_EXPLANATIONS = {
provisional:
'Provisional: fewer than 8 matches rated, so the rating still moves quickly.',
low_cross_conference:
'Low cross-conference data: fewer than 3 matches against teams outside its conference, so its place against other conferences is less certain.',
};
const VERB = { W: 'Beat', D: 'Drew with', L: 'Lost to' };
/** 24.4 -> "+24", -57 -> "−57", 0.3 -> "±0". Whole points, as the rating is shown. */
export const formatDelta = delta => {
if (delta == null) return null;
const n = Math.round(delta);
if (n > 0) return `+${n}`;
if (n < 0) return `${MINUS}${Math.abs(n)}`;
return '±0';
};
/** "2026-12-14" -> "Dec 14", read as a calendar date (no timezone shift). */
export const formatMatchDate = isoDate => {
if (!isoDate) return null;
const [y, m, d] = String(isoDate).slice(0, 10).split('-').map(Number);
if (!y || !m || !d) return null;
return new Date(y, m - 1, d).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
});
};
/**
* One of the matches that moved the rating most, as a sentence:
* `{ headline: "Beat NEFC U17 3–0", delta: "+24", detail: [...] }`.
*
* `expected` is the share of the points the team was expected to take, a draw
* counting half, so it reads "expected to take 41% of the points" rather than
* a win chance. A shoot-out keeps its regulation score and says it was rated
* as a draw. A score the match row no longer has is left out, never 0–0.
*/
export const formatMover = move => {
const score =
move.goals_for != null && move.goals_against != null
? ` ${move.goals_for}–${move.goals_against}`
: '';
const detail = [];
const date = formatMatchDate(move.match_date);
if (date) detail.push(date);
const pf = move.penalties_for;
const pa = move.penalties_against;
if (pf != null && pa != null && pf !== pa) {
const how = pf > pa ? 'Won' : 'Lost';
detail.push(`${how} ${pf}–${pa} on penalties, rated as a draw`);
}
if (move.expected != null) {
detail.push(
`expected to take ${Math.round(move.expected * 100)}% of the points`
);
}
return {
headline: `${VERB[move.result] || 'Played'} ${move.opponent}${score}`,
delta: formatDelta(move.delta),
direction: move.delta > 0 ? 'up' : move.delta < 0 ? 'down' : 'flat',
detail: detail.join(' · '),
};
};
/**
* Strength of schedule: "Average opponent 1,538 — 12th toughest of 147".
* The rank always comes with its denominator; with no rank (an unranked
* team, or no peers to rank against) only the average is stated. A
* conference-scoped rank names the conference, since separate conferences
* are not on one scale.
*/
export const formatSos = (sos, conference) => {
if (!sos || sos.rating == null) return null;
const average = `Average opponent ${formatRating(sos.rating)}`;
if (sos.rank == null || sos.of == null) return average;
const where =
sos.scope === 'conference' && conference ? ` in ${conference}` : '';
return `${average} — ${ordinal(sos.rank)} toughest of ${sos.of}${where}`;
};
/**
* Points for an inline SVG sparkline over `history` (one per week, oldest
* first) in a `width` × `height` box. Fewer than 2 points draws no line.
*/
export const sparkline = (history, width = 200, height = 40, pad = 3) => {
const values = (history || []).map(h => h.rating).filter(v => v != null);
if (values.length < 2) return null;
const min = Math.min(...values);
const max = Math.max(...values);
const span = max - min || 1;
const step = (width - 2 * pad) / (values.length - 1);
const pts = values.map((v, i) => {
const x = pad + i * step;
// A flat history sits in the middle rather than on the floor.
const y =
max === min
? height / 2
: height - pad - ((v - min) / span) * (height - 2 * pad);
return [Math.round(x * 10) / 10, Math.round(y * 10) / 10];
});
return {
points: pts.map(p => p.join(',')).join(' '),
first: pts[0],
last: pts[pts.length - 1],
};
};
|