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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 140x 140x 140x 140x 8x 8x 8x 8x 8x 7x 7x 7x 7x 7x 7x 7x 7x 7x 8x 8x 8x 52x 26x 8x 8x 8x 8x 6x 6x 6x 6x 6x 8x 8x 8x 8x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 10x 11x 1x 1x 1x 1x 11x 11x 11x 8x 8x 4x 4x 1x 1x 1x 3x 8x 8x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 2x 2x 2x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x | <template>
<!--
Power Rating audit (SB-1812) over GET /api/admin/power-rating/audit: the
teams whose Elo and Massey places, within their island, differ by more
than the gap. Investigate, never auto-fix. Admin only.
-->
<div class="admin-power-rating-audit" data-testid="pr-audit">
<div
class="flex flex-col sm:flex-row sm:justify-between sm:items-center gap-3 mb-6"
>
<h2 class="text-xl font-semibold text-fg">Power Rating audit</h2>
<button
type="button"
@click="recomputeNow"
:disabled="recomputing"
class="px-4 py-2 text-sm rounded-lg font-medium bg-brand-500 text-white disabled:opacity-50 disabled:cursor-not-allowed"
data-testid="pr-audit-recompute"
>
{{ recomputing ? 'Recomputing...' : 'Recompute now' }}
</button>
</div>
<div class="flex flex-col sm:flex-row sm:items-end gap-4 mb-4">
<div>
<h3 class="text-sm font-medium text-fg mb-2">Age Groups</h3>
<div class="flex flex-wrap gap-2">
<button
v-for="age in AGE_GROUPS"
:key="age"
type="button"
@click="selectedAgeGroup = age"
:class="pillClass(selectedAgeGroup === age)"
:data-testid="`pr-audit-age-${age}`"
>
{{ age }}
</button>
</div>
</div>
<div>
<label
for="pr-audit-min-gap"
class="block text-sm font-medium text-fg mb-2"
>Flag gaps above (places)</label
>
<input
id="pr-audit-min-gap"
v-model.number="minGapInput"
type="number"
min="0"
step="1"
@change="applyMinGap"
class="w-24 px-3 py-2 text-sm bg-card border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
data-testid="pr-audit-min-gap"
/>
</div>
</div>
<!-- What the last "Recompute now" did, per age group -->
<div
v-if="recomputeError"
class="mb-4 p-3 bg-red-50 border border-red-200 rounded text-red-700 text-sm"
data-testid="pr-audit-recompute-error"
>
{{ recomputeError }}
</div>
<div
v-if="recomputeSummary"
class="mb-4 p-3 bg-brand-50 border border-brand-200 rounded text-sm text-fg"
data-testid="pr-audit-recompute-summary"
>
<p class="font-medium mb-1">Recomputed {{ recomputeSummary.league }}</p>
<ul class="space-y-0.5">
<li
v-for="ag in recomputeSummary.age_groups"
:key="ag.age_group"
:data-testid="`pr-audit-recompute-${ag.age_group}`"
>
{{ recomputeLine(ag) }}
</li>
</ul>
</div>
<div
v-if="loading"
class="text-center py-8 text-fg-muted"
data-testid="pr-audit-loading"
>
Loading audit...
</div>
<div
v-else-if="error"
class="p-3 bg-red-50 border border-red-200 rounded text-red-700 text-sm"
data-testid="pr-audit-error"
>
{{ error }}
</div>
<template v-else-if="result">
<div class="mb-4 space-y-1">
<p
v-if="summaryLine"
class="text-sm font-medium text-fg"
data-testid="pr-audit-summary"
>
{{ summaryLine }}
</p>
<p class="text-xs text-fg-muted" data-testid="pr-audit-scope">
{{ result.scope }}
</p>
<p class="text-xs text-fg-muted" data-testid="pr-audit-note">
{{ result.note }}
</p>
</div>
<!-- No run, or nothing to compare: the API's reason -->
<div
v-if="result.reason"
class="text-center py-8 text-fg-muted"
data-testid="pr-audit-empty"
>
{{ result.reason }}
</div>
<div
v-else-if="!rows.length"
class="text-center py-8 text-fg-muted"
data-testid="pr-audit-none-flagged"
>
No gaps above {{ result.min_gap }} places.
</div>
<template v-else>
<!-- Desktop table -->
<div
class="hidden sm:block overflow-x-auto border border-line rounded-lg"
>
<table class="min-w-full text-sm" data-testid="pr-audit-table">
<thead class="bg-surface-alt text-fg-muted text-xs uppercase">
<tr>
<th class="px-3 py-2 text-left">Team</th>
<th class="px-3 py-2 text-left">Conference</th>
<th class="px-3 py-2 text-right">Elo</th>
<th class="px-3 py-2 text-right">Elo rank</th>
<th class="px-3 py-2 text-right">Massey rank</th>
<th class="px-3 py-2 text-right">Gap</th>
<th class="px-3 py-2 text-right">MP</th>
<th class="px-3 py-2 text-right">X-conf MP</th>
<th class="px-3 py-2 text-left">Badges</th>
</tr>
</thead>
<tbody class="divide-y divide-line">
<tr
v-for="row in rows"
:key="row.team_id"
data-testid="pr-audit-row"
>
<td class="px-3 py-2 text-fg">{{ row.team }}</td>
<td class="px-3 py-2 text-fg-muted">
{{ row.conference || '—' }}
</td>
<td class="px-3 py-2 text-right">
{{ formatRating(row.elo_rating) }}
</td>
<td class="px-3 py-2 text-right">{{ row.elo_rank }}</td>
<td class="px-3 py-2 text-right">{{ row.massey_rank }}</td>
<td class="px-3 py-2 text-right font-medium">
{{ formatGap(row.gap) }}
</td>
<td class="px-3 py-2 text-right">{{ row.mp }}</td>
<td class="px-3 py-2 text-right">{{ row.xconf_mp }}</td>
<td class="px-3 py-2 text-fg-muted">
{{ badgeText(row.badges) }}
</td>
</tr>
</tbody>
</table>
</div>
<!-- Mobile: stacked rows -->
<ul
class="sm:hidden divide-y divide-line border border-line rounded-lg"
data-testid="pr-audit-list"
>
<li
v-for="row in rows"
:key="row.team_id"
class="p-3 text-sm"
data-testid="pr-audit-item"
>
<div class="flex justify-between gap-2">
<span class="font-medium text-fg">{{ row.team }}</span>
<span class="font-medium">{{ formatGap(row.gap) }}</span>
</div>
<p class="text-xs text-fg-muted">
{{ row.conference || '—' }} · Elo
{{ formatRating(row.elo_rating) }}
</p>
<p class="text-xs text-fg-muted">
Elo {{ row.elo_rank }} · Massey {{ row.massey_rank }} ·
{{ row.mp }} MP · {{ row.xconf_mp }} cross-conf.
</p>
<p v-if="row.badges.length" class="text-xs text-fg-muted">
{{ badgeText(row.badges) }}
</p>
</li>
</ul>
</template>
</template>
</div>
</template>
<script>
import { computed, onMounted, ref, watch } from 'vue';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '@/config/api';
import { BADGES, formatRating, formatUpdated } from '@/utils/powerRating';
// The Power Rating covers Homegrown U15 to U19 (power-rating.md "Scope").
const AGE_GROUPS = ['U15', 'U16', 'U17', 'U19'];
const LEAGUE = 'Homegrown';
// About the worst 5% at the 2026-11-26 freeze (power-rating.md).
const DEFAULT_MIN_GAP = 30;
const MINUS = '−';
export default {
name: 'AdminPowerRatingAudit',
setup() {
const authStore = useAuthStore();
const selectedAgeGroup = ref('U15');
const minGap = ref(DEFAULT_MIN_GAP);
const minGapInput = ref(DEFAULT_MIN_GAP);
const result = ref(null);
const loading = ref(false);
const error = ref('');
const recomputing = ref(false);
const recomputeSummary = ref(null);
const recomputeError = ref('');
const pillClass = active => [
'px-4 py-2 text-sm rounded-lg font-medium transition-colors',
active
? 'bg-brand-500 text-white shadow-sm'
: 'bg-surface-alt text-fg-muted hover:bg-line',
];
const rows = computed(() => result.value?.teams || []);
const summaryLine = computed(() => {
const r = result.value;
if (!r?.run) return '';
const parts = [`Run #${r.run.id}`];
const updated = formatUpdated(r.run.computed_at);
if (updated) parts.push(`updated ${updated}`);
parts.push(`${r.teams_compared} teams compared`);
parts.push(`${r.flagged_count} flagged above ${r.min_gap} places`);
if (r.rank_correlation != null) {
parts.push(`rank correlation ${r.rank_correlation.toFixed(2)}`);
}
return parts.join(' · ');
});
// Positive gap: Elo ranks the team higher than Massey does.
const formatGap = gap => {
if (gap > 0) return `+${gap} Elo higher`;
if (gap < 0) return `${MINUS}${Math.abs(gap)} Massey higher`;
return '0';
};
const badgeText = badges =>
(badges || []).map(b => BADGES[b]?.label || b).join(', ') || '—';
const recomputeLine = ag => {
const parts = [`${ag.age_group}: ${ag.status}`];
if (ag.run_id != null) parts.push(`run #${ag.run_id}`);
if (ag.teams != null) parts.push(`${ag.teams} teams`);
if (ag.reason) parts.push(ag.reason);
return parts.join(' · ');
};
// A filter change mid-flight must not let the older answer land last.
let requestId = 0;
const fetchAudit = async () => {
const id = ++requestId;
loading.value = true;
error.value = '';
const params = new URLSearchParams({
league: LEAGUE,
age_group: selectedAgeGroup.value,
min_gap: String(minGap.value),
});
try {
const data = await authStore.apiRequest(
`${getApiBaseUrl()}/api/admin/power-rating/audit?${params}`
);
if (id !== requestId) return;
result.value = data;
} catch (err) {
if (id !== requestId) return;
result.value = null;
error.value =
err?.message || 'The Power Rating audit is unavailable right now.';
} finally {
if (id === requestId) loading.value = false;
}
};
const applyMinGap = () => {
const value = Number(minGapInput.value);
if (!Number.isInteger(value) || value < 0) {
minGapInput.value = minGap.value;
return;
}
minGap.value = value;
};
const recomputeNow = async () => {
recomputing.value = true;
recomputeError.value = '';
try {
recomputeSummary.value = await authStore.apiRequest(
`${getApiBaseUrl()}/api/admin/power-rating/recompute?league=${LEAGUE}`,
{ method: 'POST' }
);
await fetchAudit();
} catch (err) {
recomputeSummary.value = null;
recomputeError.value =
err?.message || 'Could not recompute the power rating.';
} finally {
recomputing.value = false;
}
};
watch([selectedAgeGroup, minGap], fetchAudit);
onMounted(fetchAudit);
return {
AGE_GROUPS,
selectedAgeGroup,
minGapInput,
result,
loading,
error,
recomputing,
recomputeSummary,
recomputeError,
rows,
summaryLine,
pillClass,
formatGap,
formatRating,
badgeText,
recomputeLine,
applyMinGap,
recomputeNow,
};
},
};
</script>
|