From 979b7cf34d89e4a24ecd91e47cde7ef45ba9dde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o?= Date: Sun, 29 Nov 2026 12:39:07 -0600 Subject: [PATCH] Gobernanza: the header's domain switcher, model titles, confirmations, a stop button, an upload button --- src/app/app.html | 8 ++- src/app/app.ts | 9 +-- src/app/gobernanza/figures.ts | 6 +- src/app/gobernanza/gobernanza.html | 98 ++++++++++++++++++++---------- src/app/gobernanza/gobernanza.scss | 44 ++++++++++---- src/app/gobernanza/gobernanza.ts | 60 +++++++++++++++--- 6 files changed, 162 insertions(+), 63 deletions(-) diff --git a/src/app/app.html b/src/app/app.html index 74ebbdb..03c0404 100644 --- a/src/app/app.html +++ b/src/app/app.html @@ -4,7 +4,9 @@ ISSSTELEON @if (domain(); as current) { - Plataforma de Indicadores + {{ + section() === 'gobernanza' ? 'Gobernanza de modelos' : 'Plataforma de Indicadores' + }} {{ u.email }} diff --git a/src/app/app.ts b/src/app/app.ts index 9f2123d..d19637f 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -43,10 +43,11 @@ export class App { ), { initialValue: '' }, ); - /** The domain of an indicator page, if this is one. */ - protected readonly domain = computed( - () => /^\/indicadores\/(\w+)/.exec(this.url())?.[1] as Domain | undefined, - ); + /** The section and domain of a page that has one (indicators, governance): the switcher + * moves between that section's domains. */ + private readonly place = computed(() => /^\/(indicadores|gobernanza)\/(\w+)/.exec(this.url())); + protected readonly section = computed(() => this.place()?.[1] ?? 'indicadores'); + protected readonly domain = computed(() => this.place()?.[2] as Domain | undefined); protected readonly others = computed(() => (this.domains.value() ?? []).filter((d) => d !== this.domain() && this.auth.canSee(d)), ); diff --git a/src/app/gobernanza/figures.ts b/src/app/gobernanza/figures.ts index 336f9fc..61b7a26 100644 --- a/src/app/gobernanza/figures.ts +++ b/src/app/gobernanza/figures.ts @@ -286,8 +286,10 @@ export function scenarioFigure( points('LR + HBN combinado (IC 95 % bootstrap)', horizons, e.points.COMB), ], layout: { - xaxis: { title: { text: 'Meses desde el diagnóstico' } }, - yaxis: { title: { text: yTitle } }, + // One label per month with every curve's survival there, as percentages. + hovermode: 'x unified', + xaxis: { title: { text: 'Meses desde el diagnóstico' }, hoverformat: '.0f' }, + yaxis: { title: { text: yTitle }, tickformat: '.1~%', hoverformat: '.1%' }, }, }, }; diff --git a/src/app/gobernanza/gobernanza.html b/src/app/gobernanza/gobernanza.html index 79fa5b6..215f5cf 100644 --- a/src/app/gobernanza/gobernanza.html +++ b/src/app/gobernanza/gobernanza.html @@ -1,10 +1,6 @@
-

Gobernanza de modelos

- +

{{ labels[domain()] ?? domain() }}

+

Versiones, informes, promoción y ejecuciones de sus modelos.

@@ -17,13 +13,44 @@ name="asOf" /> - - - @if (domain() === 'tea') { - + @if (confirming(); as c) { + + {{ + c === 'train' + ? '¿Entrenar todos los modelos de este dominio ahora?' + : '¿Calcular los riesgos de todas las pacientes con los modelos en producción?' + }} + + + + } @else { + + + @if (domain() === 'tea') { + + } } @if (run(); as r) { - {{ r.kind }}: {{ r.status }} + {{ r.kind }}: {{ STATUS[r.status] ?? r.status }} + @if (running()) { + + } }
@if (message()) { @@ -37,13 +64,15 @@ } @for (m of models.value() ?? []; track m.name) {
-

{{ m.name }}

+

+ {{ m.title }} {{ m.name }} +

- + @@ -59,32 +88,37 @@ } - +
Versión CreadaEntrenamiento / pruebaDatos Informes Validación clínica {{ v.created | date: 'yyyy-MM-dd HH:mm' }} - {{ v.metrics['n_train'] | number }} / {{ v.metrics['n_test'] | number }} - {{ sizes(v) }} - @for (r of v.reports; track r) { - {{ - reportNames[r] ?? r - }} - } - @if (v.reports.includes('interpretability')) { - - } +
+ @for (r of v.reports; track r) { + {{ + reportNames[r] ?? r + }} + } + @if (v.reports.includes('interpretability')) { + + } +
@if (!v.reports.includes('clinical_validation')) { + } @else { Agregada } @@ -105,7 +139,7 @@ @if (chosen(); as c) {
-

Interpretabilidad · {{ c.name }} v{{ c.version }}

+

Interpretabilidad · {{ titleOf(c.name) }} v{{ c.version }}

@for (f of figures(); track f.title) {

{{ f.title }}

diff --git a/src/app/gobernanza/gobernanza.scss b/src/app/gobernanza/gobernanza.scss index e974ad7..16c0d92 100644 --- a/src/app/gobernanza/gobernanza.scss +++ b/src/app/gobernanza/gobernanza.scss @@ -1,18 +1,8 @@ :host { display: block; } -h1 { - text-align: center; -} -.domains { - display: flex; - justify-content: center; - gap: var(--space-4); - margin-bottom: var(--space-4); -} -.domains a.active { - font-weight: 600; - text-decoration: underline; +.subtitle { + margin: 4px 0 var(--space-4); } .actions { display: flex; @@ -30,6 +20,7 @@ h1 { white-space: nowrap; } .badge { + white-space: nowrap; margin-left: var(--space-2); padding: 2px 8px; border-radius: 999px; @@ -45,3 +36,32 @@ td a { padding: 48px 0; text-align: center; } + +.reports { + display: flex; + flex-wrap: wrap; + align-items: center; + column-gap: var(--space-3); + row-gap: 2px; +} +.reports a { + margin-right: 0; +} +h2 .code { + font-size: 12px; + font-weight: 400; + margin-left: var(--space-2); +} +.confirm { + display: inline-flex; + flex-wrap: wrap; + align-items: center; + gap: var(--space-2); + padding: 4px 4px 4px 12px; + border-radius: 8px; + background: var(--color-surface-warning, #fdf3dc); +} + +td button { + white-space: nowrap; +} diff --git a/src/app/gobernanza/gobernanza.ts b/src/app/gobernanza/gobernanza.ts index 12d6bc1..d6d831c 100644 --- a/src/app/gobernanza/gobernanza.ts +++ b/src/app/gobernanza/gobernanza.ts @@ -6,7 +6,6 @@ import { FormsModule } from '@angular/forms'; import { MatButtonModule } from '@angular/material/button'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatInputModule } from '@angular/material/input'; -import { RouterLink } from '@angular/router'; import { Api } from '../api/api'; import { ApiConfiguration } from '../api/api-configuration'; import { addClinicalValidation } from '../api/fn/models/add-clinical-validation'; @@ -17,9 +16,9 @@ import { readReport$Json } from '../api/fn/models/read-report-json'; import { score } from '../api/fn/models/score'; import { train } from '../api/fn/models/train'; import { versions } from '../api/fn/models/versions'; -import { domains } from '../api/fn/operations/domains'; import { studies } from '../api/fn/eeg/studies'; import { study } from '../api/fn/eeg/study'; +import { terminateRun } from '../api/fn/runs/terminate-run'; import { runStatus } from '../api/fn/runs/run-status'; import type { Domain } from '../api/models/domain'; import type { Version } from '../api/models/version'; @@ -47,7 +46,6 @@ const REPORTS: Record = { MatButtonModule, MatFormFieldModule, MatInputModule, - RouterLink, Plot, ], templateUrl: './gobernanza.html', @@ -60,15 +58,15 @@ export class Gobernanza { protected readonly labels = DOMAINS as Record; protected readonly reportNames = REPORTS; - protected readonly domains = resource({ loader: () => this.api.invoke(domains) }); private readonly refreshed = signal(0); protected readonly models = resource({ params: () => ({ domain: this.domain() as Domain, at: this.refreshed() }), loader: async ({ params: { domain } }) => { - const names = await this.api.invoke(models, { domain }); + const found = await this.api.invoke(models, { domain }); return Promise.all( - names.map(async (name) => ({ + found.map(async ({ name, title }) => ({ name, + title, versions: await this.api.invoke(versions, { domain, name }), })), ); @@ -96,7 +94,41 @@ export class Gobernanza { }); protected readonly metricNames = METRIC_NAMES; protected readonly asOf = signal(''); - protected readonly run = signal<{ kind: string; status: string } | undefined>(undefined); + protected readonly run = signal<{ id: string; kind: string; status: string } | undefined>( + undefined, + ); + /** The run "Entrenar" or "Calcular riesgos" will start once confirmed. */ + protected readonly confirming = signal<'train' | 'score' | undefined>(undefined); + protected readonly running = computed(() => { + const r = this.run(); + return !!r && !['SUCCESS', 'FAILURE', 'CANCELED'].includes(r.status); + }); + protected readonly STATUS: Record = { + QUEUED: 'en cola', + NOT_STARTED: 'por iniciar', + STARTING: 'iniciando', + STARTED: 'en curso', + SUCCESS: 'terminado', + FAILURE: 'con error', + CANCELING: 'deteniéndose', + CANCELED: 'detenido', + }; + /** A model's title by its name, for messages. */ + protected titleOf(name: string): string { + return this.models.value()?.find((m) => m.name === name)?.title ?? name; + } + /** What a version learned from, as its metrics say it (each kind of model its own). */ + protected sizes(v: Version): string { + const m = v.metrics; + const n = (x: number) => x.toLocaleString('es-MX'); + if (m['n_train'] !== undefined) + return `${n(m['n_train'])} entrenamiento / ${n(m['n_test'] ?? 0)} prueba`; + if (m['n_reference'] !== undefined) return `${n(m['n_reference'])} EEG de referencia`; + if (m['children'] !== undefined) return `${n(m['children'])} niños`; + const c = Object.entries(m).find(([k]) => k.endsWith('c_index_cox')); + if (c) return `C-index ${c[1].toFixed(3)}`; + return '—'; + } protected readonly message = signal(''); protected champion(v: Version): boolean { @@ -117,14 +149,14 @@ export class Gobernanza { // OpenAPI's binary is typed as a string; the request builder sends the File as is. body: { file: file as unknown as string }, }); - this.message.set(`Validación clínica agregada a ${name} v${version}.`); + this.message.set(`Validación clínica agregada a ${this.titleOf(name)} v${version}.`); this.refreshed.update((n) => n + 1); } protected async promote(name: string, version: number): Promise { try { await this.api.invoke(promote, { domain: this.domain() as Domain, name, version }); - this.message.set(`${name} v${version} es ahora la versión en producción.`); + this.message.set(`${this.titleOf(name)} v${version} es ahora la versión en producción.`); this.refreshed.update((n) => n + 1); } catch (e) { const detail = e instanceof HttpErrorResponse ? e.error?.detail : undefined; @@ -140,14 +172,22 @@ export class Gobernanza { private async follow(run_id: string, label: string): Promise { for (;;) { const status = (await this.api.invoke(runStatus, { run_id }))['status'] as string; - this.run.set({ kind: label, status }); + this.run.set({ id: run_id, kind: label, status }); if (['SUCCESS', 'FAILURE', 'CANCELED'].includes(status)) break; await new Promise((r) => setTimeout(r, 2000)); } this.refreshed.update((n) => n + 1); } + protected async stop(): Promise { + const r = this.run(); + if (!r) return; + const found = await this.api.invoke(terminateRun, { run_id: r.id }); + this.run.set({ ...r, status: found['status'] }); + } + protected async start(kind: 'train' | 'score'): Promise { + this.confirming.set(undefined); const domain = this.domain() as Domain; const { run_id } = kind === 'train'