Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : UQO Éval — Le Grand Défi Immobilier8 * File : apps/web/src/admin/Dashboard.tsx9 * Module : admin10 * Repository : https://git.spboucher.ai/uqo-eval-jeux11 * Project Website : https://jeux.uqo-eval.app12 * Created : 2026-11-2513 * Last Modified : 2026-11-2514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { Link } from "wouter";44import { formatInt, formatPercent } from "@jeux/engine/format";45import { IconCheck, IconCross } from "../components/Icons";46import { REJECTION_LABEL, SYNC_STATUS, formatAgo, formatBytes, formatDateTime, formatDuration, formatRate, useLoad, type DashboardData } from "./lib";47import { Figures, Histogram, LoadState, Note, PageHead, RefreshButton, Section, TableScroll, TallyBars } from "./ui";4849function Health({ ok, yes, no }: { ok: boolean; yes: string; no: string }) {50 return (51 <span className={`adm-state ${ok ? "is-ok" : "is-bad"}`}>52 {ok ? <IconCheck size={16} /> : <IconCross size={16} />}53 {ok ? yes : no}54 </span>55 );56}5758export default function Dashboard() {59 const state = useLoad<DashboardData>("/dashboard", 30_000);60 return (61 <div className="adm-page">62 <PageHead63 title="Tableau de bord"64 lede="Compétitions officielles : participation, résultats, bassin de propriétés et état des services. Actualisation automatique toutes les 30 secondes."65 actions={<RefreshButton state={state} />}66 />67 <LoadState state={state} label="Chargement du tableau de bord…">68 {(d) => {69 const none = "—";70 const score = (v: number | null): string => (v === null ? none : formatPercent(v, 1));71 const scored = d.distribution.reduce((acc, b) => acc + b.n, 0);72 const topRejections = Object.entries(d.sync.last?.stats?.rejections ?? {}).sort((a, b) => b[1] - a[1]).slice(0, 3);73 return (74 <>75 <Figures76 label="Participation"77 items={[78 { label: "Participants", value: formatInt(d.totals.participants), note: `${formatInt(d.totals.sessions)} parties officielles` },79 { label: "Parties actives", value: formatInt(d.totals.active), note: `actives depuis 10 min · ${formatInt(d.totals.in_progress)} en cours` },80 { label: "Parties terminées", value: formatInt(d.totals.completed), note: `sur ${formatInt(d.totals.sessions)} commencées` },81 { label: "Taux de complétion", value: d.totals.sessions ? formatRate(d.totals.completionRate) : none, note: "terminées ÷ commencées" },82 ]}83 />84 <Figures85 label="Résultats"86 items={[87 { label: "Score moyen", value: score(d.scores.mean_score), note: "bonnes réponses, parties terminées" },88 { label: "Score médian", value: score(d.scores.median_score), note: "la moitié fait mieux" },89 { label: "Erreur relative moyenne", value: score(d.scores.mean_mape), note: "écart au prix affiché" },90 { label: "Hors compétition", value: formatInt(d.totals.training + d.totals.daily), note: `entraînement : ${formatInt(d.totals.training)} · défi du jour : ${formatInt(d.totals.daily)}` },91 ]}92 />9394 {(d.pending.flags > 0 || d.pending.anomalies > 0) && (95 <Note tone="warn" title="À examiner.">96 {d.pending.flags > 0 && <><Link href="/admin/analyses">{formatInt(d.pending.flags)} signalement{d.pending.flags > 1 ? "s" : ""} de question</Link> en attente. </>}97 {d.pending.anomalies > 0 && <><Link href="/admin/participants">{formatInt(d.pending.anomalies)} anomalie{d.pending.anomalies > 1 ? "s" : ""} statistique{d.pending.anomalies > 1 ? "s" : ""}</Link> à réviser (jamais une preuve, aucune exclusion automatique).</>}98 </Note>99 )}100101 <div className="adm-cols adm-cols-wide-left">102 <Section title="Distribution des scores" note={`${formatInt(scored)} partie${scored > 1 ? "s" : ""} terminée${scored > 1 ? "s" : ""} au classement.`}>103 {scored === 0 ? (104 <p className="adm-quiet">Aucune partie terminée pour l'instant : l'histogramme s'affichera dès le premier résultat.</p>105 ) : (106 <Histogram data={d.distribution} label="Distribution des scores" unit="Pourcentage de bonnes réponses (tranches de 10 points) · nombre de parties." />107 )}108 </Section>109 <Section title="Performance par cours">110 {d.byCourse.length === 0 ? (111 <p className="adm-quiet">Aucun résultat par cours pour l'instant.</p>112 ) : (113 <TableScroll label="Performance par cours">114 <table className="table adm-table">115 <caption className="sr-only">Score et erreur relative moyens par cours, parties terminées</caption>116 <thead>117 <tr><th scope="col">Cours</th><th scope="col" className="right">Parties</th><th scope="col" className="right">Score moyen</th><th scope="col" className="right">Erreur moy.</th></tr>118 </thead>119 <tbody>120 {d.byCourse.map((c) => (121 <tr key={c.course}>122 <th scope="row">{c.course === "Externe" ? "Hors cours" : c.course}</th>123 <td className="right">{formatInt(c.n)}</td>124 <td className="right">{formatPercent(c.meanScore, 1)}</td>125 <td className="right">{formatPercent(c.meanMape, 1)}</td>126 </tr>127 ))}128 </tbody>129 </table>130 </TableScroll>131 )}132 </Section>133 </div>134135 <div className="adm-cols">136 <Section title="Bassin de propriétés" aside={<Link href="/admin/donnees" className="adm-more">Données</Link>}>137 <Figures138 label="Bassin de propriétés"139 items={[140 { label: "Disponibles", value: formatInt(d.pool.total), note: "inscriptions actives" },141 { label: "Admissibles", value: formatInt(d.pool.eligible), note: d.pool.total ? `${formatRate(d.pool.eligible / d.pool.total)} du bassin` : undefined },142 ]}143 />144 <h3 className="adm-h3">Propriétés admissibles par catégorie</h3>145 <TallyBars rows={d.pool.byCategory} label="Propriétés admissibles par catégorie" total={d.pool.eligible} />146 </Section>147148 <div>149 <Section title="Synchronisation des données">150 <dl className="adm-dl">151 <div><dt>Source de données</dt><dd><Health ok={d.sync.sourceAvailable} yes="Accessible" no="Inaccessible" /></dd></div>152 <div>153 <dt>État</dt>154 <dd>{d.sync.running ? <span className="adm-state is-run"><span className="adm-dot" aria-hidden="true" />Synchronisation en cours</span> : "Au repos"}</dd>155 </div>156 {d.sync.last ? (157 <>158 <div>159 <dt>Dernière tâche</dt>160 <dd>161 <Health ok={d.sync.last.status !== "failed"} yes={SYNC_STATUS[d.sync.last.status]} no={SYNC_STATUS.failed} />162 <span className="muted"> · {formatDateTime(d.sync.last.started_at)} ({formatAgo(d.sync.last.started_at)})</span>163 </dd>164 </div>165 {d.sync.last.stats && (166 <div>167 <dt>Bilan</dt>168 <dd>{formatInt(d.sync.last.stats.scanned ?? 0)} lues · {formatInt(d.sync.last.stats.normalized ?? 0)} normalisées · {formatInt(d.sync.last.stats.eligible ?? 0)} admissibles</dd>169 </div>170 )}171 {topRejections.length > 0 && (172 <div>173 <dt>Principaux rejets</dt>174 <dd>{topRejections.map(([reason, n]) => `${REJECTION_LABEL[reason] ?? reason} (${formatInt(n)})`).join(" · ")}</dd>175 </div>176 )}177 {d.sync.last.error && <div><dt>Erreur</dt><dd className="error-text">{d.sync.last.error}</dd></div>}178 </>179 ) : (180 <div><dt>Dernière tâche</dt><dd>Aucune synchronisation enregistrée</dd></div>181 )}182 </dl>183 </Section>184185 <Section title="État des services">186 <dl className="adm-dl">187 <div><dt>Base de données</dt><dd><Health ok={d.services.database} yes="En service" no="Hors service" /></dd></div>188 <div><dt>Écouteurs temps réel</dt><dd>{formatInt(d.services.liveListeners)} connexion{d.services.liveListeners > 1 ? "s" : ""} ouverte{d.services.liveListeners > 1 ? "s" : ""}</dd></div>189 <div><dt>Cache d'images</dt><dd>{formatInt(d.services.imageCache.files)} fichiers · {formatBytes(d.services.imageCache.bytes)}</dd></div>190 <div><dt>Mémoire</dt><dd>{formatInt(d.services.memoryMb)} Mo</dd></div>191 <div><dt>En fonction depuis</dt><dd>{formatDuration(d.services.uptimeSeconds)}</dd></div>192 <div><dt>Version</dt><dd>{d.services.version}</dd></div>193 </dl>194 </Section>195196 <Section title="En attente de révision">197 <dl className="adm-dl">198 <div>199 <dt>Signalements de questions</dt>200 <dd>{d.pending.flags === 0 ? "Aucun" : <Link href="/admin/analyses">{formatInt(d.pending.flags)} à traiter</Link>}</dd>201 </div>202 <div>203 <dt>Anomalies statistiques</dt>204 <dd>{d.pending.anomalies === 0 ? "Aucune" : <Link href="/admin/participants">{formatInt(d.pending.anomalies)} à réviser</Link>}</dd>205 </div>206 </dl>207 </Section>208 </div>209 </div>210 </>211 );212 }}213 </LoadState>214 </div>215 );216}217