T13: Gobernanza as one page with its sections in fixed places
Keep the route, title, subtitle, domain navigation and composition in
gobernanza.{ts,html,scss}. Ejecución keeps mode and health in execution.ts.
Add models.{ts,html,scss} to own the actions, run monitor, status, versions,
reports, figures, clinical validation, and checks and lineage dialogs.
Render training.ts after Modelos with the existing source, configuration,
promotion checkbox, input sets and upload. Keep ZIP export and import in
bundles.ts. Keep scope, study list, EDF upload and run progress in
tea/studies.{ts,html}, and render tea/preview.ts separately for TEA with
its EDF and ADOS-2 selection, results and PDF export.
Use a page grid for section spacing and the global card style. Keep
table, action and dialog styles local to Modelos. Use Material fields
for editable values and Material buttons to open native file pickers,
retaining input labels and showing the selected filenames. Keep the
native suggestion lists for scheduler and input set names.
Default the training target to all on domain changes. Both Modelos
training actions focus the Entrenamiento heading and use the same
Formly submit path. Use the existing shared start flag and version
refresh via the Modelos component. Reset the training promotion
checkbox on domain changes and the upload selection with its input
listing. Ignore training submissions that finish in a different domain.
Move gobernanza.spec.ts to models.spec.ts alongside checkActions.
Keep bundles, execution, training, run-monitor, figures and preview PDF
logic specs. Update e2e/pages.spec.ts for Material selections and
the Modelos monitor, and check section order and training focus.
Prettier 3.10.1 and git diff --cached --check passed. The main checkout
has no local Prettier installation, so use the available lockfile
version directly from the requested working directory. Angular builds,
unit tests and Playwright are deferred to the VM per the spec.
This commit is contained in:
+16
-4
@@ -88,14 +88,25 @@ test('tea gobernanza: every section in sync mode, and the preview saved as PDF',
|
|||||||
}) => {
|
}) => {
|
||||||
const problems = watch(page);
|
const problems = watch(page);
|
||||||
await page.goto('/gobernanza/tea');
|
await page.goto('/gobernanza/tea');
|
||||||
await page.getByLabel('Modo').selectOption('sync');
|
await expect(page.locator('app-gobernanza').getByRole('heading', { level: 2 })).toHaveText([
|
||||||
|
'Ejecución',
|
||||||
|
'Modelos',
|
||||||
|
'Entrenamiento',
|
||||||
|
'Bundles',
|
||||||
|
'Estudios EEG',
|
||||||
|
'Vista previa',
|
||||||
|
]);
|
||||||
|
await page.getByRole('combobox', { name: 'Modo' }).click();
|
||||||
|
await page.getByRole('option', { name: 'Sync' }).click();
|
||||||
await expect(page.getByRole('status').filter({ hasText: 'Disponible' })).toBeVisible();
|
await expect(page.getByRole('status').filter({ hasText: 'Disponible' })).toBeVisible();
|
||||||
|
|
||||||
await page.getByRole('button', { name: 'Entrenar modelos' }).click();
|
await page.getByRole('button', { name: 'Entrenar modelos' }).click();
|
||||||
await expect(page.getByRole('heading', { name: 'Entrenar modelos', level: 3 })).toBeVisible();
|
const training = page.getByRole('heading', { name: 'Entrenamiento', level: 2 });
|
||||||
|
await expect(training).toBeVisible();
|
||||||
|
await expect(training).toBeFocused();
|
||||||
await expect(page.locator('app-governance-training formly-form')).toBeVisible();
|
await expect(page.locator('app-governance-training formly-form')).toBeVisible();
|
||||||
|
|
||||||
const monitor = page.locator('app-gobernanza > section > section app-run-monitor');
|
const monitor = page.locator('app-governance-models app-run-monitor');
|
||||||
await page.getByRole('button', { name: 'Analizar EEG' }).click();
|
await page.getByRole('button', { name: 'Analizar EEG' }).click();
|
||||||
await expect(page.getByRole('heading', { name: 'Análisis de EEG' })).toBeVisible();
|
await expect(page.getByRole('heading', { name: 'Análisis de EEG' })).toBeVisible();
|
||||||
await expect(monitor.getByRole('status')).toHaveText('SUCCESS', { timeout: 10 * 60_000 });
|
await expect(monitor.getByRole('status')).toHaveText('SUCCESS', { timeout: 10 * 60_000 });
|
||||||
@@ -131,7 +142,8 @@ test('tea gobernanza: every section in sync mode, and the preview saved as PDF',
|
|||||||
await dialog.getByRole('button', { name: 'Cerrar' }).click();
|
await dialog.getByRole('button', { name: 'Cerrar' }).click();
|
||||||
|
|
||||||
const bundles = page.locator('app-governance-bundles');
|
const bundles = page.locator('app-governance-bundles');
|
||||||
await bundles.getByLabel('Versiones').selectOption('all');
|
await bundles.getByRole('combobox', { name: 'Versiones' }).click();
|
||||||
|
await page.getByRole('option', { name: 'Todas' }).click();
|
||||||
await bundles.getByRole('button', { name: 'Exportar bundle' }).click();
|
await bundles.getByRole('button', { name: 'Exportar bundle' }).click();
|
||||||
await expect(bundles.getByRole('alert')).toContainText('nothing to export');
|
await expect(bundles.getByRole('alert')).toContainText('nothing to export');
|
||||||
expect(problems.filter((p) => !p.includes('409'))).toEqual([]);
|
expect(problems.filter((p) => !p.includes('409'))).toEqual([]);
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import { HttpErrorResponse } from '@angular/common/http';
|
|||||||
import { Component, inject, input, model, output, signal } from '@angular/core';
|
import { Component, inject, input, model, output, signal } from '@angular/core';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatInputModule } from '@angular/material/input';
|
||||||
|
import { MatSelectModule } from '@angular/material/select';
|
||||||
import { Api } from '../api/api';
|
import { Api } from '../api/api';
|
||||||
import { exportModels, type ExportModels$Params } from '../api/fn/models/export-models';
|
import { exportModels, type ExportModels$Params } from '../api/fn/models/export-models';
|
||||||
import { importModels } from '../api/fn/models/import-models';
|
import { importModels } from '../api/fn/models/import-models';
|
||||||
@@ -45,19 +48,19 @@ export function download(blob: Blob, filename: string): void {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-governance-bundles',
|
selector: 'app-governance-bundles',
|
||||||
imports: [FormsModule, MatButtonModule],
|
imports: [FormsModule, MatButtonModule, MatFormFieldModule, MatInputModule, MatSelectModule],
|
||||||
template: `
|
template: `
|
||||||
<section class="card">
|
<section class="card" aria-labelledby="bundles-heading">
|
||||||
<h3>Bundles</h3>
|
<h2 id="bundles-heading">Bundles</h2>
|
||||||
<form (ngSubmit)="export()">
|
<form (ngSubmit)="export()">
|
||||||
<label
|
<mat-form-field appearance="outline">
|
||||||
>Versiones
|
<mat-label>Versiones</mat-label>
|
||||||
<select name="versions" [(ngModel)]="selection">
|
<mat-select name="versions" [(ngModel)]="selection">
|
||||||
<option value="champion">En producción</option>
|
<mat-option value="champion">En producción</mat-option>
|
||||||
<option value="latest">Últimas</option>
|
<mat-option value="latest">Últimas</mat-option>
|
||||||
<option value="all">Todas</option>
|
<mat-option value="all">Todas</mat-option>
|
||||||
</select>
|
</mat-select>
|
||||||
</label>
|
</mat-form-field>
|
||||||
<button mat-stroked-button type="submit" [disabled]="exporting()">Exportar bundle</button>
|
<button mat-stroked-button type="submit" [disabled]="exporting()">Exportar bundle</button>
|
||||||
</form>
|
</form>
|
||||||
@if (exportedHash()) {
|
@if (exportedHash()) {
|
||||||
@@ -66,9 +69,28 @@ export function download(blob: Blob, filename: string): void {
|
|||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
<form (ngSubmit)="import(file)">
|
<form (ngSubmit)="import(file)">
|
||||||
<label>Archivo ZIP <input #file type="file" accept=".zip" required /></label>
|
<input
|
||||||
<label>SHA-256 esperado <input name="hash" [(ngModel)]="hash" required /></label>
|
#file
|
||||||
<button mat-stroked-button type="submit" [disabled]="importing() || disabled()">
|
type="file"
|
||||||
|
accept=".zip"
|
||||||
|
required
|
||||||
|
hidden
|
||||||
|
aria-label="Archivo ZIP"
|
||||||
|
(change)="zipFiles.set(file.files)"
|
||||||
|
/>
|
||||||
|
<button mat-stroked-button type="button" (click)="file.click()">Archivo ZIP</button>
|
||||||
|
@for (file of zipFiles(); track $index) {
|
||||||
|
<span>{{ file.name }}</span>
|
||||||
|
}
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>SHA-256 esperado</mat-label>
|
||||||
|
<input matInput name="hash" [(ngModel)]="hash" required />
|
||||||
|
</mat-form-field>
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="submit"
|
||||||
|
[disabled]="importing() || disabled() || !zipFiles()?.length"
|
||||||
|
>
|
||||||
Importar bundle
|
Importar bundle
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -85,6 +107,7 @@ export class Bundles {
|
|||||||
readonly started = output<string>();
|
readonly started = output<string>();
|
||||||
protected readonly selection = signal<NonNullable<ExportModels$Params['versions']>>('champion');
|
protected readonly selection = signal<NonNullable<ExportModels$Params['versions']>>('champion');
|
||||||
protected readonly exportedHash = signal('');
|
protected readonly exportedHash = signal('');
|
||||||
|
protected readonly zipFiles = signal<FileList | null>(null);
|
||||||
protected readonly hash = signal('');
|
protected readonly hash = signal('');
|
||||||
protected readonly message = signal('');
|
protected readonly message = signal('');
|
||||||
protected readonly exporting = signal(false);
|
protected readonly exporting = signal(false);
|
||||||
@@ -125,6 +148,7 @@ export class Bundles {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
input.value = '';
|
input.value = '';
|
||||||
|
this.zipFiles.set(null);
|
||||||
if (domain === this.domain()) this.started.emit(run_id);
|
if (domain === this.domain()) this.started.emit(run_id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.message.set(errorText(error));
|
this.message.set(errorText(error));
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { DOCUMENT } from '@angular/common';
|
import { DOCUMENT } from '@angular/common';
|
||||||
import { Component, computed, effect, inject, model, resource, signal } from '@angular/core';
|
import { Component, computed, effect, inject, model, resource, signal } from '@angular/core';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatInputModule } from '@angular/material/input';
|
||||||
|
import { MatSelectModule } from '@angular/material/select';
|
||||||
import { Api } from '../api/api';
|
import { Api } from '../api/api';
|
||||||
import { executionHealth } from '../api/fn/execution/execution-health';
|
import { executionHealth } from '../api/fn/execution/execution-health';
|
||||||
import { executionOptions } from '../api/fn/execution/execution-options';
|
import { executionOptions } from '../api/fn/execution/execution-options';
|
||||||
@@ -8,28 +12,30 @@ import type { Health } from '../api/models/health';
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-execution',
|
selector: 'app-execution',
|
||||||
|
imports: [MatButtonModule, MatFormFieldModule, MatInputModule, MatSelectModule],
|
||||||
template: `
|
template: `
|
||||||
<section class="card">
|
<section class="card" aria-labelledby="execution-heading">
|
||||||
<h2>Ejecución</h2>
|
<h2 id="execution-heading">Ejecución</h2>
|
||||||
@if (options.hasValue()) {
|
@if (options.hasValue()) {
|
||||||
<label
|
<mat-form-field appearance="outline">
|
||||||
>Modo
|
<mat-label>Modo</mat-label>
|
||||||
<select #mode [value]="choice().mode ?? ''" (change)="select($any(mode.value))">
|
<mat-select [value]="choice().mode ?? ''" (selectionChange)="select($event.value)">
|
||||||
<option value="sync">Sync</option>
|
<mat-option value="sync">Sync</mat-option>
|
||||||
<option value="local">Local</option>
|
<mat-option value="local">Local</mat-option>
|
||||||
<option value="remote">Remoto</option>
|
<mat-option value="remote">Remoto</mat-option>
|
||||||
</select>
|
</mat-select>
|
||||||
</label>
|
</mat-form-field>
|
||||||
@if (choice().mode === 'remote') {
|
@if (choice().mode === 'remote') {
|
||||||
<label
|
<mat-form-field appearance="outline">
|
||||||
>Scheduler
|
<mat-label>Scheduler</mat-label>
|
||||||
<input
|
<input
|
||||||
|
matInput
|
||||||
#scheduler
|
#scheduler
|
||||||
list="execution-schedulers"
|
list="execution-schedulers"
|
||||||
[value]="choice().scheduler ?? ''"
|
[value]="choice().scheduler ?? ''"
|
||||||
(change)="address.set(scheduler.value)"
|
(change)="address.set(scheduler.value)"
|
||||||
/>
|
/>
|
||||||
</label>
|
</mat-form-field>
|
||||||
<datalist id="execution-schedulers">
|
<datalist id="execution-schedulers">
|
||||||
@for (host of options.value().schedulers; track host) {
|
@for (host of options.value().schedulers; track host) {
|
||||||
<option [value]="host"></option>
|
<option [value]="host"></option>
|
||||||
@@ -52,7 +58,9 @@ import type { Health } from '../api/models/health';
|
|||||||
}
|
}
|
||||||
</p>
|
</p>
|
||||||
@if (h.dashboard_url && h.dashboard_ok !== false) {
|
@if (h.dashboard_url && h.dashboard_ok !== false) {
|
||||||
<a [href]="h.dashboard_url" target="_blank" rel="noopener">Panel de Dask</a>
|
<a mat-stroked-button [href]="h.dashboard_url" target="_blank" rel="noopener"
|
||||||
|
>Panel de Dask</a
|
||||||
|
>
|
||||||
}
|
}
|
||||||
} @else if (health.error() || options.error()) {
|
} @else if (health.error() || options.error()) {
|
||||||
<p role="alert">No se pudo consultar la ejecución.</p>
|
<p role="alert">No se pudo consultar la ejecución.</p>
|
||||||
|
|||||||
@@ -1,305 +1,44 @@
|
|||||||
<section class="page">
|
<section class="page">
|
||||||
<h1>Gobernanza de modelos</h1>
|
<h1>Gobernanza de modelos</h1>
|
||||||
|
<p class="subtitle">Administra la ejecución, las versiones y el entrenamiento por dominio.</p>
|
||||||
<nav class="domains" aria-label="Dominios">
|
<nav class="domains" aria-label="Dominios">
|
||||||
@for (d of domains.hasValue() ? domains.value() : []; track d) {
|
@for (d of domains.hasValue() ? domains.value() : []; track d) {
|
||||||
<a [routerLink]="['/gobernanza', d]" [class.active]="d === domain()">{{ labels[d] ?? d }}</a>
|
<a mat-stroked-button [routerLink]="['/gobernanza', d]" [class.active]="d === domain()">
|
||||||
|
{{ labels[d] ?? d }}
|
||||||
|
</a>
|
||||||
}
|
}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<app-execution [(execution)]="execution" />
|
<div class="sections">
|
||||||
|
<app-execution #execution />
|
||||||
<section>
|
<app-governance-models
|
||||||
<h2>Modelos</h2>
|
#models
|
||||||
<div class="card actions">
|
[domain]="domainKey()"
|
||||||
<button mat-flat-button type="button" (click)="training.set('all')">Entrenar modelos</button>
|
[execution]="execution.execution()"
|
||||||
<button
|
(trainingRequested)="training.focus()"
|
||||||
mat-stroked-button
|
/>
|
||||||
type="button"
|
<app-governance-training
|
||||||
[disabled]="starting() || running()"
|
#training
|
||||||
(click)="start('score')"
|
[domain]="domainKey()"
|
||||||
>
|
[name]="models.training()"
|
||||||
Calcular riesgos
|
[execution]="execution.execution()"
|
||||||
</button>
|
[(busy)]="models.starting"
|
||||||
@if (domain() === 'tea') {
|
[disabled]="models.running() || !execution.execution()"
|
||||||
<button
|
(started)="models.follow($event.id, 'Entrenamiento', $event.autoPromote)"
|
||||||
mat-stroked-button
|
/>
|
||||||
type="button"
|
|
||||||
[disabled]="starting() || running() || !execution()"
|
|
||||||
(click)="start('analyze')"
|
|
||||||
>
|
|
||||||
Analizar EEG
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
<button
|
|
||||||
mat-stroked-button
|
|
||||||
type="button"
|
|
||||||
[disabled]="editing() || !models.hasValue()"
|
|
||||||
(click)="prepareCandidates(bulkDialog)"
|
|
||||||
>
|
|
||||||
Promover candidatas
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
@if (training(); as name) {
|
|
||||||
<app-governance-training
|
|
||||||
[domain]="domainKey()"
|
|
||||||
[name]="name"
|
|
||||||
[execution]="execution()"
|
|
||||||
[(busy)]="starting"
|
|
||||||
[disabled]="running() || !execution()"
|
|
||||||
(started)="follow($event.id, 'Entrenamiento', $event.autoPromote)"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
<app-governance-bundles
|
<app-governance-bundles
|
||||||
[domain]="domainKey()"
|
[domain]="domainKey()"
|
||||||
[(importing)]="starting"
|
[(importing)]="models.starting"
|
||||||
[disabled]="running()"
|
[disabled]="models.running()"
|
||||||
(started)="follow($event, 'Importación')"
|
(started)="models.follow($event, 'Importación')"
|
||||||
/>
|
/>
|
||||||
@if (run(); as current) {
|
@if (domain() === 'tea') {
|
||||||
<section class="card">
|
<app-eeg-studies
|
||||||
<h3>{{ current.label }}</h3>
|
[execution]="execution.execution()"
|
||||||
<app-run-monitor [runId]="current.id" (finished)="finish($event)" />
|
[refresh]="models.refreshed()"
|
||||||
</section>
|
(changed)="models.refresh()"
|
||||||
|
/>
|
||||||
|
<app-eeg-preview />
|
||||||
}
|
}
|
||||||
@if (message()) {
|
</div>
|
||||||
<p class="message" role="status">{{ message() }}</p>
|
|
||||||
}
|
|
||||||
|
|
||||||
@if (models.isLoading()) {
|
|
||||||
<p class="muted">Cargando modelos…</p>
|
|
||||||
} @else if (models.error(); as error) {
|
|
||||||
<p role="alert">{{ errorText(error) }}</p>
|
|
||||||
} @else if (!models.hasValue() || !models.value().length) {
|
|
||||||
<p class="muted empty">Este dominio todavía no tiene modelos entrenados.</p>
|
|
||||||
}
|
|
||||||
@for (m of models.hasValue() ? models.value() : []; track m.name) {
|
|
||||||
<section class="card model">
|
|
||||||
<h3>{{ m.title }}</h3>
|
|
||||||
<button mat-stroked-button type="button" (click)="training.set(m.name)">Reentrenar</button>
|
|
||||||
<table class="plain">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Versión</th>
|
|
||||||
<th>Creada</th>
|
|
||||||
<th>Entrenamiento / prueba</th>
|
|
||||||
<th>Informes</th>
|
|
||||||
<th>Validación clínica</th>
|
|
||||||
<th>Comprobaciones y linaje</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@for (v of m.versions; track v.version) {
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
v{{ v.version }} <span class="badge">{{ v.status }}</span>
|
|
||||||
</td>
|
|
||||||
<td>{{ v.created | date: 'yyyy-MM-dd HH:mm' }}</td>
|
|
||||||
<td class="num">
|
|
||||||
{{ v.metrics['n_train'] | number }} / {{ v.metrics['n_test'] | number }}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@for (report of v.reports; track report) {
|
|
||||||
<button
|
|
||||||
mat-button
|
|
||||||
type="button"
|
|
||||||
(click)="reportDownload(m.name, v.version, report)"
|
|
||||||
>
|
|
||||||
{{ reportNames[report] ?? report }}
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
@if (v.reports.includes('interpretability')) {
|
|
||||||
<button
|
|
||||||
mat-button
|
|
||||||
type="button"
|
|
||||||
(click)="chooseReport({ name: m.name, version: v.version })"
|
|
||||||
>
|
|
||||||
Ver gráficas
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@if (!v.reports.includes('clinical_validation')) {
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
[attr.aria-label]="'Validación clínica de ' + m.name + ' v' + v.version"
|
|
||||||
(change)="upload(m.name, v.version, $event)"
|
|
||||||
/>
|
|
||||||
} @else {
|
|
||||||
Agregada
|
|
||||||
}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<button
|
|
||||||
mat-stroked-button
|
|
||||||
type="button"
|
|
||||||
(click)="
|
|
||||||
showVersion('checks', { name: m.name, version: v.version }, checksDialog)
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Comprobaciones
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
mat-stroked-button
|
|
||||||
type="button"
|
|
||||||
(click)="
|
|
||||||
showVersion('lineage', { name: m.name, version: v.version }, lineageDialog)
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Linaje
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</section>
|
|
||||||
}
|
|
||||||
|
|
||||||
@if (chosen(); as version) {
|
|
||||||
<section class="card">
|
|
||||||
<h3>Interpretabilidad · {{ version.name }} v{{ version.version }}</h3>
|
|
||||||
@if (feature(); as current) {
|
|
||||||
@if (ageFeatures().length > 1) {
|
|
||||||
<label
|
|
||||||
>Característica
|
|
||||||
<select [ngModel]="current" (ngModelChange)="selectedFeature.set($event)">
|
|
||||||
@for (feature of ageFeatures(); track feature) {
|
|
||||||
<option [value]="feature">{{ feature }}</option>
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
}
|
|
||||||
<label><input type="checkbox" [(ngModel)]="overlay" /> Superponer estudios</label>
|
|
||||||
}
|
|
||||||
@if (report.error() || band.error() || analysed.error(); as error) {
|
|
||||||
<p role="alert">{{ errorText(error) }}</p>
|
|
||||||
}
|
|
||||||
@for (f of figures(); track f.title) {
|
|
||||||
<h4>{{ f.title }}</h4>
|
|
||||||
<app-plot
|
|
||||||
[figure]="f.figure"
|
|
||||||
[height]="
|
|
||||||
report.hasValue() && report.value()['kind'] === 'forest'
|
|
||||||
? forestHeight(f.figure.data.length)
|
|
||||||
: 360
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
} @empty {
|
|
||||||
@if (report.isLoading() || band.isLoading()) {
|
|
||||||
<p class="muted">Cargando…</p>
|
|
||||||
} @else if (!report.error() && !band.error()) {
|
|
||||||
<p class="muted">Este informe no tiene gráficas.</p>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</section>
|
|
||||||
}
|
|
||||||
</section>
|
|
||||||
|
|
||||||
@if (domain() === 'tea') {
|
|
||||||
<app-eeg-studies [execution]="execution()" [refresh]="refreshed()" (changed)="refresh()" />
|
|
||||||
}
|
|
||||||
|
|
||||||
<dialog #checksDialog aria-label="Comprobaciones" (close)="checksFor.set(undefined)">
|
|
||||||
@if (checksFor(); as key) {
|
|
||||||
<h3>Comprobaciones · {{ key.name }} v{{ key.version }}</h3>
|
|
||||||
@if (checks.hasValue()) {
|
|
||||||
@let details = checks.value();
|
|
||||||
@let actions = checkActions(details);
|
|
||||||
<ul>
|
|
||||||
@for (check of details.checks; track check.report) {
|
|
||||||
<li>
|
|
||||||
{{ reportNames[check.report] ?? check.report }} ·
|
|
||||||
{{ check.present ? 'Presente' : 'Falta' }}
|
|
||||||
</li>
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
<button
|
|
||||||
mat-stroked-button
|
|
||||||
type="button"
|
|
||||||
[disabled]="editing() || !actions.promote"
|
|
||||||
(click)="changeVersion(key, 'promote')"
|
|
||||||
>
|
|
||||||
Promover
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
mat-stroked-button
|
|
||||||
type="button"
|
|
||||||
[disabled]="editing() || !actions.retire"
|
|
||||||
(click)="changeVersion(key, 'retire')"
|
|
||||||
>
|
|
||||||
Retirar
|
|
||||||
</button>
|
|
||||||
} @else if (checks.error(); as error) {
|
|
||||||
<p role="alert">{{ errorText(error) }}</p>
|
|
||||||
} @else {
|
|
||||||
<p>Cargando…</p>
|
|
||||||
}
|
|
||||||
@if (message()) {
|
|
||||||
<p role="status">{{ message() }}</p>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<form method="dialog"><button mat-stroked-button>Cerrar</button></form>
|
|
||||||
</dialog>
|
|
||||||
|
|
||||||
<dialog #lineageDialog aria-label="Linaje" (close)="lineageFor.set(undefined)">
|
|
||||||
@if (lineageFor(); as key) {
|
|
||||||
<h3>Linaje · {{ key.name }} v{{ key.version }}</h3>
|
|
||||||
@if (lineage.hasValue()) {
|
|
||||||
@let details = lineage.value();
|
|
||||||
<h4>Parámetros</h4>
|
|
||||||
<dl>
|
|
||||||
@for (entry of details.params | keyvalue; track entry.key) {
|
|
||||||
<dt>{{ entry.key }}</dt>
|
|
||||||
<dd>{{ entry.value }}</dd>
|
|
||||||
}
|
|
||||||
</dl>
|
|
||||||
<h4>Métricas</h4>
|
|
||||||
<dl>
|
|
||||||
@for (entry of details.metrics | keyvalue; track entry.key) {
|
|
||||||
<dt>{{ entry.key }}</dt>
|
|
||||||
<dd>{{ entry.value }}</dd>
|
|
||||||
}
|
|
||||||
</dl>
|
|
||||||
<h4>Etiquetas</h4>
|
|
||||||
<dl>
|
|
||||||
@for (entry of details.tags | keyvalue; track entry.key) {
|
|
||||||
<dt>{{ entry.key }}</dt>
|
|
||||||
<dd>{{ entry.value }}</dd>
|
|
||||||
}
|
|
||||||
</dl>
|
|
||||||
@if (details.imported; as imported) {
|
|
||||||
<h4>Importado de</h4>
|
|
||||||
<dl>
|
|
||||||
@for (entry of imported | keyvalue; track entry.key) {
|
|
||||||
<dt>{{ entry.key }}</dt>
|
|
||||||
<dd>{{ entry.value }}</dd>
|
|
||||||
}
|
|
||||||
</dl>
|
|
||||||
}
|
|
||||||
} @else if (lineage.error(); as error) {
|
|
||||||
<p role="alert">{{ errorText(error) }}</p>
|
|
||||||
} @else {
|
|
||||||
<p>Cargando…</p>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<form method="dialog"><button mat-stroked-button>Cerrar</button></form>
|
|
||||||
</dialog>
|
|
||||||
|
|
||||||
<dialog #bulkDialog aria-label="Promover candidatas">
|
|
||||||
<h3>Promover candidatas</h3>
|
|
||||||
<ul>
|
|
||||||
@for (candidate of candidates(); track candidate.name) {
|
|
||||||
<li>{{ candidate.name }} v{{ candidate.version }}</li>
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
<button
|
|
||||||
mat-flat-button
|
|
||||||
type="button"
|
|
||||||
[disabled]="editing()"
|
|
||||||
(click)="promoteCandidates(bulkDialog)"
|
|
||||||
>
|
|
||||||
Promover
|
|
||||||
</button>
|
|
||||||
<form method="dialog"><button mat-stroked-button>Cancelar</button></form>
|
|
||||||
</dialog>
|
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,56 +1,20 @@
|
|||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
h1 {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.domains {
|
.domains {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
flex-wrap: wrap;
|
||||||
gap: var(--space-4);
|
gap: var(--space-3);
|
||||||
margin-bottom: var(--space-4);
|
margin-bottom: var(--space-4);
|
||||||
}
|
}
|
||||||
.domains a.active {
|
.domains a.active {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
.actions {
|
.sections {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-wrap: wrap;
|
gap: var(--space-4);
|
||||||
align-items: center;
|
|
||||||
gap: var(--space-3);
|
|
||||||
margin-bottom: var(--space-4);
|
|
||||||
}
|
}
|
||||||
.model {
|
.sections > * {
|
||||||
margin-bottom: var(--space-4);
|
min-width: 0;
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
.num {
|
|
||||||
text-align: right;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
.badge {
|
|
||||||
margin-left: var(--space-2);
|
|
||||||
padding: 2px 8px;
|
|
||||||
border-radius: 999px;
|
|
||||||
background: var(--color-primary);
|
|
||||||
color: #fff;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
td a {
|
|
||||||
margin-right: var(--space-3);
|
|
||||||
color: var(--color-action);
|
|
||||||
}
|
|
||||||
.empty {
|
|
||||||
padding: 48px 0;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.message {
|
|
||||||
white-space: pre-line;
|
|
||||||
}
|
|
||||||
dialog {
|
|
||||||
max-width: min(90vw, 64rem);
|
|
||||||
}
|
|
||||||
dialog form {
|
|
||||||
margin-top: var(--space-3);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,79 +1,28 @@
|
|||||||
import { DatePipe, DecimalPipe, KeyValuePipe } from '@angular/common';
|
import { Component, computed, inject, input, resource } from '@angular/core';
|
||||||
import { Component, computed, effect, inject, input, resource, signal } from '@angular/core';
|
|
||||||
import { FormsModule } from '@angular/forms';
|
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { RouterLink } from '@angular/router';
|
import { RouterLink } from '@angular/router';
|
||||||
import { Api } from '../api/api';
|
import { Api } from '../api/api';
|
||||||
import { studies } from '../api/fn/eeg/studies';
|
|
||||||
import { study } from '../api/fn/eeg/study';
|
|
||||||
import { addClinicalValidation } from '../api/fn/models/add-clinical-validation';
|
|
||||||
import { analyze } from '../api/fn/models/analyze';
|
|
||||||
import { curve } from '../api/fn/models/curve';
|
|
||||||
import { lineage } from '../api/fn/models/lineage';
|
|
||||||
import { models } from '../api/fn/models/models';
|
|
||||||
import { promote } from '../api/fn/models/promote';
|
|
||||||
import { readReport$Any } from '../api/fn/models/read-report-any';
|
|
||||||
import { readReport$Json } from '../api/fn/models/read-report-json';
|
|
||||||
import { retire } from '../api/fn/models/retire';
|
|
||||||
import { score } from '../api/fn/models/score';
|
|
||||||
import { versionChecks } from '../api/fn/models/version-checks';
|
|
||||||
import { versions } from '../api/fn/models/versions';
|
|
||||||
import { domains } from '../api/fn/operations/domains';
|
import { domains } from '../api/fn/operations/domains';
|
||||||
import type { Domain } from '../api/models/domain';
|
import type { Domain } from '../api/models/domain';
|
||||||
import type { Execution as Choice } from '../api/models/execution';
|
|
||||||
import type { Run } from '../api/models/run';
|
|
||||||
import { DOMAINS } from '../app';
|
import { DOMAINS } from '../app';
|
||||||
import { Plot } from '../plot';
|
import { Bundles } from './bundles';
|
||||||
import { Bundles, download } from './bundles';
|
|
||||||
import { Execution } from './execution';
|
import { Execution } from './execution';
|
||||||
import { interpretabilityFigures, studyPoints, type Centile } from './figures';
|
import { Models } from './models';
|
||||||
import { errorText, RunMonitor } from './run-monitor';
|
import { EegPreview } from './tea/preview';
|
||||||
import { EegStudies } from './tea/studies';
|
import { EegStudies } from './tea/studies';
|
||||||
import { Training } from './training';
|
import { Training } from './training';
|
||||||
|
|
||||||
const REPORTS: Record<string, string> = {
|
|
||||||
technical_validation: 'Validación técnica',
|
|
||||||
interpretability: 'Interpretabilidad',
|
|
||||||
clinical_validation: 'Validación clínica',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface VersionKey {
|
|
||||||
name: string;
|
|
||||||
version: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Checks {
|
|
||||||
status: 'candidate' | 'champion' | 'retired';
|
|
||||||
promotable: boolean;
|
|
||||||
checks: { report: string; present: boolean }[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Lineage {
|
|
||||||
params: Record<string, string>;
|
|
||||||
metrics: Record<string, number>;
|
|
||||||
tags: Record<string, string>;
|
|
||||||
imported: Record<string, string> | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function checkActions(checks: Checks) {
|
|
||||||
return { promote: checks.promotable, retire: checks.status !== 'champion' };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-gobernanza',
|
selector: 'app-gobernanza',
|
||||||
imports: [
|
imports: [
|
||||||
DatePipe,
|
|
||||||
DecimalPipe,
|
|
||||||
KeyValuePipe,
|
|
||||||
FormsModule,
|
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
RouterLink,
|
RouterLink,
|
||||||
Plot,
|
|
||||||
Bundles,
|
|
||||||
Execution,
|
Execution,
|
||||||
RunMonitor,
|
Models,
|
||||||
EegStudies,
|
|
||||||
Training,
|
Training,
|
||||||
|
Bundles,
|
||||||
|
EegStudies,
|
||||||
|
EegPreview,
|
||||||
],
|
],
|
||||||
templateUrl: './gobernanza.html',
|
templateUrl: './gobernanza.html',
|
||||||
styleUrl: './gobernanza.scss',
|
styleUrl: './gobernanza.scss',
|
||||||
@@ -82,322 +31,6 @@ export class Gobernanza {
|
|||||||
private readonly api = inject(Api);
|
private readonly api = inject(Api);
|
||||||
readonly domain = input.required<string>();
|
readonly domain = input.required<string>();
|
||||||
protected readonly domainKey = computed(() => this.domain() as Domain);
|
protected readonly domainKey = computed(() => this.domain() as Domain);
|
||||||
protected readonly execution = signal<Choice | undefined>(undefined);
|
|
||||||
protected readonly labels = DOMAINS as Record<string, string>;
|
protected readonly labels = DOMAINS as Record<string, string>;
|
||||||
protected readonly reportNames = REPORTS;
|
|
||||||
protected readonly errorText = errorText;
|
|
||||||
protected readonly domains = resource({ loader: () => this.api.invoke(domains) });
|
protected readonly domains = resource({ loader: () => this.api.invoke(domains) });
|
||||||
protected readonly refreshed = signal(0);
|
|
||||||
|
|
||||||
protected refresh(): void {
|
|
||||||
this.refreshed.update((value) => value + 1);
|
|
||||||
}
|
|
||||||
protected readonly models = resource({
|
|
||||||
params: () => ({ domain: this.domainKey(), at: this.refreshed() }),
|
|
||||||
loader: async ({ params: { domain } }) => {
|
|
||||||
const found = await this.api.invoke(models, { domain });
|
|
||||||
return Promise.all(
|
|
||||||
found.map(async ({ name, title }) => ({
|
|
||||||
name,
|
|
||||||
title,
|
|
||||||
versions: await this.api.invoke(versions, { domain, name }),
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
protected readonly training = signal('');
|
|
||||||
protected readonly run = signal<{ id: string; label: string; autoPromote?: boolean } | undefined>(
|
|
||||||
undefined,
|
|
||||||
);
|
|
||||||
protected readonly starting = signal(false);
|
|
||||||
protected readonly running = signal(false);
|
|
||||||
protected readonly editing = signal(false);
|
|
||||||
protected readonly message = signal('');
|
|
||||||
protected readonly chosen = signal<VersionKey | undefined>(undefined);
|
|
||||||
protected readonly checksFor = signal<VersionKey | undefined>(undefined);
|
|
||||||
protected readonly lineageFor = signal<VersionKey | undefined>(undefined);
|
|
||||||
protected readonly checks = resource({
|
|
||||||
params: () => {
|
|
||||||
const key = this.checksFor();
|
|
||||||
return key ? { ...key, domain: this.domainKey(), at: this.refreshed() } : undefined;
|
|
||||||
},
|
|
||||||
loader: async ({ params: { at, ...params } }) => this.getChecks(params.domain, params),
|
|
||||||
});
|
|
||||||
protected readonly checkActions = checkActions;
|
|
||||||
protected readonly lineage = resource({
|
|
||||||
params: () => {
|
|
||||||
const key = this.lineageFor();
|
|
||||||
return key ? { ...key, domain: this.domainKey() } : undefined;
|
|
||||||
},
|
|
||||||
loader: async ({ params }) => (await this.api.invoke(lineage, params)) as Lineage,
|
|
||||||
});
|
|
||||||
protected readonly candidates = signal<VersionKey[]>([]);
|
|
||||||
protected readonly report = resource({
|
|
||||||
params: () => {
|
|
||||||
const key = this.chosen();
|
|
||||||
return key ? { ...key, domain: this.domainKey() } : undefined;
|
|
||||||
},
|
|
||||||
loader: ({ params }) =>
|
|
||||||
this.api.invoke(readReport$Json, { ...params, report: 'interpretability' }),
|
|
||||||
});
|
|
||||||
protected readonly ageFeatures = computed<string[]>(() => {
|
|
||||||
const report = this.report.hasValue() ? this.report.value() : undefined;
|
|
||||||
return report?.kind === 'age_curves' ? Object.keys(report['curves']) : [];
|
|
||||||
});
|
|
||||||
protected readonly selectedFeature = signal('');
|
|
||||||
protected readonly feature = computed(() => {
|
|
||||||
const keys = this.ageFeatures();
|
|
||||||
return keys.includes(this.selectedFeature())
|
|
||||||
? this.selectedFeature()
|
|
||||||
: keys.includes('value')
|
|
||||||
? 'value'
|
|
||||||
: keys[0];
|
|
||||||
});
|
|
||||||
protected readonly band = resource({
|
|
||||||
params: () => {
|
|
||||||
const key = this.chosen();
|
|
||||||
const feature = this.feature();
|
|
||||||
if (!key || !feature || !this.report.hasValue()) return undefined;
|
|
||||||
if (this.report.value()['curves'][feature].kind === 'count_rate') return undefined;
|
|
||||||
return { ...key, domain: this.domainKey(), feature };
|
|
||||||
},
|
|
||||||
loader: async ({ params }) => (await this.api.invoke(curve, params)) as Centile[],
|
|
||||||
});
|
|
||||||
protected readonly overlay = signal(false);
|
|
||||||
protected readonly analysed = resource({
|
|
||||||
params: () =>
|
|
||||||
this.overlay() && this.domainKey() === 'tea' && this.feature()
|
|
||||||
? this.refreshed() + 1
|
|
||||||
: undefined,
|
|
||||||
loader: async () => {
|
|
||||||
const found = await this.api.invoke(studies);
|
|
||||||
return Promise.all(
|
|
||||||
found
|
|
||||||
.filter((entry) => entry.analysed)
|
|
||||||
.map(({ id }) => this.api.invoke(study, { eeg_id: id })),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
protected readonly figures = computed(() => {
|
|
||||||
if (!this.report.hasValue()) return [];
|
|
||||||
const report = this.report.value();
|
|
||||||
const feature = this.feature();
|
|
||||||
const points =
|
|
||||||
this.analysed.hasValue() && feature
|
|
||||||
? studyPoints(this.analysed.value(), report['model'], feature)
|
|
||||||
: [];
|
|
||||||
return interpretabilityFigures(report, {
|
|
||||||
feature,
|
|
||||||
centiles: this.band.hasValue() ? this.band.value() : undefined,
|
|
||||||
points,
|
|
||||||
waitForCentiles: report['kind'] === 'age_curves',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
effect(() => {
|
|
||||||
this.domain();
|
|
||||||
this.training.set('');
|
|
||||||
this.run.set(undefined);
|
|
||||||
this.running.set(false);
|
|
||||||
this.starting.set(false);
|
|
||||||
this.editing.set(false);
|
|
||||||
this.message.set('');
|
|
||||||
this.chosen.set(undefined);
|
|
||||||
this.checksFor.set(undefined);
|
|
||||||
this.lineageFor.set(undefined);
|
|
||||||
this.overlay.set(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async reportDownload(name: string, version: number, report: string): Promise<void> {
|
|
||||||
try {
|
|
||||||
const response = await this.api.invoke$Response(readReport$Any, {
|
|
||||||
domain: this.domainKey(),
|
|
||||||
name,
|
|
||||||
version,
|
|
||||||
report,
|
|
||||||
});
|
|
||||||
const filename = /filename="([^"]+)"/.exec(
|
|
||||||
response.headers.get('Content-Disposition') ?? '',
|
|
||||||
)?.[1];
|
|
||||||
download(response.body, filename ?? report);
|
|
||||||
} catch (error) {
|
|
||||||
this.message.set(errorText(error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async upload(name: string, version: number, event: Event): Promise<void> {
|
|
||||||
const input = event.target as HTMLInputElement;
|
|
||||||
const file = input.files?.[0];
|
|
||||||
if (!file) return;
|
|
||||||
const domain = this.domainKey();
|
|
||||||
try {
|
|
||||||
await this.api.invoke(addClinicalValidation, {
|
|
||||||
domain,
|
|
||||||
name,
|
|
||||||
version,
|
|
||||||
body: { file: file as unknown as string },
|
|
||||||
});
|
|
||||||
input.value = '';
|
|
||||||
if (domain !== this.domainKey()) return;
|
|
||||||
this.message.set(`Validación clínica agregada a ${name} v${version}.`);
|
|
||||||
this.refresh();
|
|
||||||
} catch (error) {
|
|
||||||
this.message.set(errorText(error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected showVersion(
|
|
||||||
kind: 'checks' | 'lineage',
|
|
||||||
key: VersionKey,
|
|
||||||
dialog: HTMLDialogElement,
|
|
||||||
): void {
|
|
||||||
(kind === 'checks' ? this.checksFor : this.lineageFor).set(key);
|
|
||||||
dialog.showModal();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async changeVersion(key: VersionKey, action: 'promote' | 'retire'): Promise<void> {
|
|
||||||
const domain = this.domainKey();
|
|
||||||
this.editing.set(true);
|
|
||||||
this.message.set('');
|
|
||||||
try {
|
|
||||||
if (action === 'promote') await this.api.invoke(promote, { domain, ...key });
|
|
||||||
else await this.api.invoke(retire, { domain, ...key });
|
|
||||||
this.message.set(
|
|
||||||
`${key.name} v${key.version}: ${action === 'promote' ? 'en producción' : 'retirada'}.`,
|
|
||||||
);
|
|
||||||
this.refresh();
|
|
||||||
} catch (error) {
|
|
||||||
this.message.set(errorText(error));
|
|
||||||
} finally {
|
|
||||||
this.editing.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async prepareCandidates(dialog: HTMLDialogElement): Promise<void> {
|
|
||||||
if (!this.models.hasValue()) return;
|
|
||||||
const domain = this.domainKey();
|
|
||||||
this.editing.set(true);
|
|
||||||
this.message.set('');
|
|
||||||
try {
|
|
||||||
const latest = this.models.value().flatMap(({ name, versions }) => {
|
|
||||||
const newest = versions.reduce<(typeof versions)[number] | undefined>(
|
|
||||||
(current, version) => (!current || version.version > current.version ? version : current),
|
|
||||||
undefined,
|
|
||||||
);
|
|
||||||
return newest?.status === 'candidate' ? [{ name, version: newest.version }] : [];
|
|
||||||
});
|
|
||||||
const allowed = await Promise.all(
|
|
||||||
latest.map(async (key) => (await this.getChecks(domain, key)).promotable),
|
|
||||||
);
|
|
||||||
if (domain !== this.domainKey()) return;
|
|
||||||
const found = latest.filter((_, index) => allowed[index]);
|
|
||||||
this.candidates.set(found);
|
|
||||||
if (found.length) dialog.showModal();
|
|
||||||
else this.message.set('No hay candidatas que se puedan promover.');
|
|
||||||
} catch (error) {
|
|
||||||
this.message.set(errorText(error));
|
|
||||||
} finally {
|
|
||||||
this.editing.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async promoteCandidates(dialog: HTMLDialogElement): Promise<void> {
|
|
||||||
this.editing.set(true);
|
|
||||||
this.message.set('');
|
|
||||||
try {
|
|
||||||
await this.promoteVersions(this.domainKey(), this.candidates());
|
|
||||||
dialog.close();
|
|
||||||
} finally {
|
|
||||||
this.editing.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected forestHeight(rows: number): number {
|
|
||||||
return Math.max(360, rows * 24 + 72);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected chooseReport(key: VersionKey): void {
|
|
||||||
this.overlay.set(false);
|
|
||||||
this.selectedFeature.set('');
|
|
||||||
this.chosen.set(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected follow(id: string, label: string, autoPromote = false): void {
|
|
||||||
this.message.set('');
|
|
||||||
this.run.set({ id, label, autoPromote });
|
|
||||||
this.running.set(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async start(kind: 'score' | 'analyze'): Promise<void> {
|
|
||||||
const domain = this.domainKey();
|
|
||||||
this.starting.set(true);
|
|
||||||
this.message.set('');
|
|
||||||
try {
|
|
||||||
const { run_id } =
|
|
||||||
kind === 'score'
|
|
||||||
? await this.api.invoke(score, { domain })
|
|
||||||
: await this.api.invoke(analyze, { domain, body: { execution: this.execution() } });
|
|
||||||
if (domain === this.domainKey())
|
|
||||||
this.follow(run_id, kind === 'score' ? 'Cálculo de riesgos' : 'Análisis de EEG');
|
|
||||||
} catch (error) {
|
|
||||||
this.message.set(errorText(error));
|
|
||||||
} finally {
|
|
||||||
this.starting.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async finish(run: Run): Promise<void> {
|
|
||||||
const domain = this.domainKey();
|
|
||||||
const active = this.run();
|
|
||||||
if (active?.id !== run.id) return;
|
|
||||||
try {
|
|
||||||
if (!active.autoPromote) return;
|
|
||||||
if (run.state !== 'succeeded') {
|
|
||||||
this.message.set('No se promovió: el entrenamiento no terminó correctamente.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const newVersions = run.info.flatMap((line) => {
|
|
||||||
const match = /^train_models: tea\.(.+): version (\d+)$/.exec(line);
|
|
||||||
return match ? [{ name: match[1], version: Number(match[2]) }] : [];
|
|
||||||
});
|
|
||||||
if (newVersions.length) await this.promoteVersions(domain, newVersions);
|
|
||||||
else this.message.set('No se promovió: el entrenamiento no registró versiones nuevas.');
|
|
||||||
} finally {
|
|
||||||
if (domain === this.domainKey() && this.run()?.id === run.id) {
|
|
||||||
this.refresh();
|
|
||||||
this.running.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getChecks(domain: Domain, key: VersionKey): Promise<Checks> {
|
|
||||||
return (await this.api.invoke(versionChecks, { domain, ...key })) as Checks;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async promoteVersions(domain: Domain, keys: VersionKey[]): Promise<void> {
|
|
||||||
const messages = await Promise.all(
|
|
||||||
keys.map(async (key) => {
|
|
||||||
const label = `${key.name} v${key.version}`;
|
|
||||||
try {
|
|
||||||
const checks = await this.getChecks(domain, key);
|
|
||||||
if (!checks.promotable) {
|
|
||||||
const missing = checks.checks
|
|
||||||
.filter((check) => !check.present)
|
|
||||||
.map((check) => REPORTS[check.report] ?? check.report);
|
|
||||||
const reason = missing.length ? `faltan ${missing.join(', ')}` : checks.status;
|
|
||||||
return `No se promovió ${label}: ${reason}.`;
|
|
||||||
}
|
|
||||||
await this.api.invoke(promote, { domain, ...key });
|
|
||||||
return `${label}: en producción.`;
|
|
||||||
} catch (error) {
|
|
||||||
return `No se promovió ${label}: ${errorText(error)}`;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
if (domain !== this.domainKey()) return;
|
|
||||||
this.message.set(messages.join('\n'));
|
|
||||||
this.refresh();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,279 @@
|
|||||||
|
<section class="card" aria-labelledby="models-heading">
|
||||||
|
<h2 id="models-heading">Modelos</h2>
|
||||||
|
<div class="actions">
|
||||||
|
<button mat-flat-button type="button" (click)="selectTraining('all')">Entrenar modelos</button>
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
[disabled]="starting() || running()"
|
||||||
|
(click)="start('score')"
|
||||||
|
>
|
||||||
|
Calcular riesgos
|
||||||
|
</button>
|
||||||
|
@if (domain() === 'tea') {
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
[disabled]="starting() || running() || !execution()"
|
||||||
|
(click)="start('analyze')"
|
||||||
|
>
|
||||||
|
Analizar EEG
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
[disabled]="editing() || !models.hasValue()"
|
||||||
|
(click)="prepareCandidates(bulkDialog)"
|
||||||
|
>
|
||||||
|
Promover candidatas
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@if (run(); as current) {
|
||||||
|
<section>
|
||||||
|
<h3>{{ current.label }}</h3>
|
||||||
|
<app-run-monitor [runId]="current.id" (finished)="finish($event)" />
|
||||||
|
</section>
|
||||||
|
}
|
||||||
|
@if (message()) {
|
||||||
|
<p class="message" role="status">{{ message() }}</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (models.isLoading()) {
|
||||||
|
<p class="muted">Cargando modelos…</p>
|
||||||
|
} @else if (models.error(); as error) {
|
||||||
|
<p role="alert">{{ errorText(error) }}</p>
|
||||||
|
} @else if (!models.hasValue() || !models.value().length) {
|
||||||
|
<p class="muted empty">Este dominio todavía no tiene modelos entrenados.</p>
|
||||||
|
}
|
||||||
|
@for (m of models.hasValue() ? models.value() : []; track m.name) {
|
||||||
|
<section class="model">
|
||||||
|
<h3>{{ m.title }}</h3>
|
||||||
|
<button mat-stroked-button type="button" (click)="selectTraining(m.name)">Reentrenar</button>
|
||||||
|
<table class="plain">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Versión</th>
|
||||||
|
<th>Creada</th>
|
||||||
|
<th>Entrenamiento / prueba</th>
|
||||||
|
<th>Informes</th>
|
||||||
|
<th>Validación clínica</th>
|
||||||
|
<th>Comprobaciones y linaje</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@for (v of m.versions; track v.version) {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
v{{ v.version }} <span class="badge">{{ v.status }}</span>
|
||||||
|
</td>
|
||||||
|
<td>{{ v.created | date: 'yyyy-MM-dd HH:mm' }}</td>
|
||||||
|
<td class="num">
|
||||||
|
{{ v.metrics['n_train'] | number }} / {{ v.metrics['n_test'] | number }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@for (report of v.reports; track report) {
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
(click)="reportDownload(m.name, v.version, report)"
|
||||||
|
>
|
||||||
|
{{ reportNames[report] ?? report }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
@if (v.reports.includes('interpretability')) {
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
(click)="chooseReport({ name: m.name, version: v.version })"
|
||||||
|
>
|
||||||
|
Ver gráficas
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@if (!v.reports.includes('clinical_validation')) {
|
||||||
|
<input
|
||||||
|
#validation
|
||||||
|
type="file"
|
||||||
|
hidden
|
||||||
|
[attr.aria-label]="'Validación clínica de ' + m.name + ' v' + v.version"
|
||||||
|
(change)="upload(m.name, v.version, $event)"
|
||||||
|
/>
|
||||||
|
<button mat-stroked-button type="button" (click)="validation.click()">
|
||||||
|
Validación clínica
|
||||||
|
</button>
|
||||||
|
} @else {
|
||||||
|
Agregada
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
(click)="
|
||||||
|
showVersion('checks', { name: m.name, version: v.version }, checksDialog)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
Comprobaciones
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
(click)="
|
||||||
|
showVersion('lineage', { name: m.name, version: v.version }, lineageDialog)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
Linaje
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (chosen(); as version) {
|
||||||
|
<section>
|
||||||
|
<h3>Interpretabilidad · {{ version.name }} v{{ version.version }}</h3>
|
||||||
|
@if (feature(); as current) {
|
||||||
|
@if (ageFeatures().length > 1) {
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Característica</mat-label>
|
||||||
|
<mat-select [ngModel]="current" (ngModelChange)="selectedFeature.set($event)">
|
||||||
|
@for (feature of ageFeatures(); track feature) {
|
||||||
|
<mat-option [value]="feature">{{ feature }}</mat-option>
|
||||||
|
}
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
|
}
|
||||||
|
<mat-checkbox [(ngModel)]="overlay">Superponer estudios</mat-checkbox>
|
||||||
|
}
|
||||||
|
@if (report.error() || band.error() || analysed.error(); as error) {
|
||||||
|
<p role="alert">{{ errorText(error) }}</p>
|
||||||
|
}
|
||||||
|
@for (f of figures(); track f.title) {
|
||||||
|
<h4>{{ f.title }}</h4>
|
||||||
|
<app-plot
|
||||||
|
[figure]="f.figure"
|
||||||
|
[height]="
|
||||||
|
report.hasValue() && report.value()['kind'] === 'forest'
|
||||||
|
? forestHeight(f.figure.data.length)
|
||||||
|
: 360
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
} @empty {
|
||||||
|
@if (report.isLoading() || band.isLoading()) {
|
||||||
|
<p class="muted">Cargando…</p>
|
||||||
|
} @else if (!report.error() && !band.error()) {
|
||||||
|
<p class="muted">Este informe no tiene gráficas.</p>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
}
|
||||||
|
|
||||||
|
<dialog #checksDialog aria-label="Comprobaciones" (close)="checksFor.set(undefined)">
|
||||||
|
@if (checksFor(); as key) {
|
||||||
|
<h3>Comprobaciones · {{ key.name }} v{{ key.version }}</h3>
|
||||||
|
@if (checks.hasValue()) {
|
||||||
|
@let details = checks.value();
|
||||||
|
@let actions = checkActions(details);
|
||||||
|
<ul>
|
||||||
|
@for (check of details.checks; track check.report) {
|
||||||
|
<li>
|
||||||
|
{{ reportNames[check.report] ?? check.report }} ·
|
||||||
|
{{ check.present ? 'Presente' : 'Falta' }}
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
[disabled]="editing() || !actions.promote"
|
||||||
|
(click)="changeVersion(key, 'promote')"
|
||||||
|
>
|
||||||
|
Promover
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
[disabled]="editing() || !actions.retire"
|
||||||
|
(click)="changeVersion(key, 'retire')"
|
||||||
|
>
|
||||||
|
Retirar
|
||||||
|
</button>
|
||||||
|
} @else if (checks.error(); as error) {
|
||||||
|
<p role="alert">{{ errorText(error) }}</p>
|
||||||
|
} @else {
|
||||||
|
<p>Cargando…</p>
|
||||||
|
}
|
||||||
|
@if (message()) {
|
||||||
|
<p role="status">{{ message() }}</p>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<form method="dialog"><button mat-stroked-button>Cerrar</button></form>
|
||||||
|
</dialog>
|
||||||
|
|
||||||
|
<dialog #lineageDialog aria-label="Linaje" (close)="lineageFor.set(undefined)">
|
||||||
|
@if (lineageFor(); as key) {
|
||||||
|
<h3>Linaje · {{ key.name }} v{{ key.version }}</h3>
|
||||||
|
@if (lineage.hasValue()) {
|
||||||
|
@let details = lineage.value();
|
||||||
|
<h4>Parámetros</h4>
|
||||||
|
<dl>
|
||||||
|
@for (entry of details.params | keyvalue; track entry.key) {
|
||||||
|
<dt>{{ entry.key }}</dt>
|
||||||
|
<dd>{{ entry.value }}</dd>
|
||||||
|
}
|
||||||
|
</dl>
|
||||||
|
<h4>Métricas</h4>
|
||||||
|
<dl>
|
||||||
|
@for (entry of details.metrics | keyvalue; track entry.key) {
|
||||||
|
<dt>{{ entry.key }}</dt>
|
||||||
|
<dd>{{ entry.value }}</dd>
|
||||||
|
}
|
||||||
|
</dl>
|
||||||
|
<h4>Etiquetas</h4>
|
||||||
|
<dl>
|
||||||
|
@for (entry of details.tags | keyvalue; track entry.key) {
|
||||||
|
<dt>{{ entry.key }}</dt>
|
||||||
|
<dd>{{ entry.value }}</dd>
|
||||||
|
}
|
||||||
|
</dl>
|
||||||
|
@if (details.imported; as imported) {
|
||||||
|
<h4>Importado de</h4>
|
||||||
|
<dl>
|
||||||
|
@for (entry of imported | keyvalue; track entry.key) {
|
||||||
|
<dt>{{ entry.key }}</dt>
|
||||||
|
<dd>{{ entry.value }}</dd>
|
||||||
|
}
|
||||||
|
</dl>
|
||||||
|
}
|
||||||
|
} @else if (lineage.error(); as error) {
|
||||||
|
<p role="alert">{{ errorText(error) }}</p>
|
||||||
|
} @else {
|
||||||
|
<p>Cargando…</p>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<form method="dialog"><button mat-stroked-button>Cerrar</button></form>
|
||||||
|
</dialog>
|
||||||
|
|
||||||
|
<dialog #bulkDialog aria-label="Promover candidatas">
|
||||||
|
<h3>Promover candidatas</h3>
|
||||||
|
<ul>
|
||||||
|
@for (candidate of candidates(); track candidate.name) {
|
||||||
|
<li>{{ candidate.name }} v{{ candidate.version }}</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
<button
|
||||||
|
mat-flat-button
|
||||||
|
type="button"
|
||||||
|
[disabled]="editing()"
|
||||||
|
(click)="promoteCandidates(bulkDialog)"
|
||||||
|
>
|
||||||
|
Promover
|
||||||
|
</button>
|
||||||
|
<form method="dialog"><button mat-stroked-button>Cancelar</button></form>
|
||||||
|
</dialog>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
.actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-3);
|
||||||
|
margin-bottom: var(--space-4);
|
||||||
|
}
|
||||||
|
.model {
|
||||||
|
margin-bottom: var(--space-4);
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
.num {
|
||||||
|
text-align: right;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.badge {
|
||||||
|
margin-left: var(--space-2);
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--color-primary);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.empty {
|
||||||
|
padding: 48px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.message {
|
||||||
|
white-space: pre-line;
|
||||||
|
}
|
||||||
|
dialog {
|
||||||
|
max-width: min(90vw, 64rem);
|
||||||
|
}
|
||||||
|
dialog form {
|
||||||
|
margin-top: var(--space-3);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { checkActions } from './gobernanza';
|
import { checkActions } from './models';
|
||||||
|
|
||||||
describe('version checks', () => {
|
describe('version checks', () => {
|
||||||
it('enables promotion only when the API says the version is promotable', () => {
|
it('enables promotion only when the API says the version is promotable', () => {
|
||||||
@@ -0,0 +1,410 @@
|
|||||||
|
import { DatePipe, DecimalPipe, KeyValuePipe } from '@angular/common';
|
||||||
|
import {
|
||||||
|
Component,
|
||||||
|
computed,
|
||||||
|
effect,
|
||||||
|
inject,
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
resource,
|
||||||
|
signal,
|
||||||
|
} from '@angular/core';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatSelectModule } from '@angular/material/select';
|
||||||
|
import { Api } from '../api/api';
|
||||||
|
import { studies } from '../api/fn/eeg/studies';
|
||||||
|
import { study } from '../api/fn/eeg/study';
|
||||||
|
import { addClinicalValidation } from '../api/fn/models/add-clinical-validation';
|
||||||
|
import { analyze } from '../api/fn/models/analyze';
|
||||||
|
import { curve } from '../api/fn/models/curve';
|
||||||
|
import { lineage } from '../api/fn/models/lineage';
|
||||||
|
import { models } from '../api/fn/models/models';
|
||||||
|
import { promote } from '../api/fn/models/promote';
|
||||||
|
import { readReport$Any } from '../api/fn/models/read-report-any';
|
||||||
|
import { readReport$Json } from '../api/fn/models/read-report-json';
|
||||||
|
import { retire } from '../api/fn/models/retire';
|
||||||
|
import { score } from '../api/fn/models/score';
|
||||||
|
import { versionChecks } from '../api/fn/models/version-checks';
|
||||||
|
import { versions } from '../api/fn/models/versions';
|
||||||
|
import type { Domain } from '../api/models/domain';
|
||||||
|
import type { Execution as Choice } from '../api/models/execution';
|
||||||
|
import type { Run } from '../api/models/run';
|
||||||
|
import { Plot } from '../plot';
|
||||||
|
import { download } from './bundles';
|
||||||
|
import { interpretabilityFigures, studyPoints, type Centile } from './figures';
|
||||||
|
import { errorText, RunMonitor } from './run-monitor';
|
||||||
|
|
||||||
|
const REPORTS: Record<string, string> = {
|
||||||
|
technical_validation: 'Validación técnica',
|
||||||
|
interpretability: 'Interpretabilidad',
|
||||||
|
clinical_validation: 'Validación clínica',
|
||||||
|
};
|
||||||
|
|
||||||
|
interface VersionKey {
|
||||||
|
name: string;
|
||||||
|
version: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Checks {
|
||||||
|
status: 'candidate' | 'champion' | 'retired';
|
||||||
|
promotable: boolean;
|
||||||
|
checks: { report: string; present: boolean }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Lineage {
|
||||||
|
params: Record<string, string>;
|
||||||
|
metrics: Record<string, number>;
|
||||||
|
tags: Record<string, string>;
|
||||||
|
imported: Record<string, string> | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkActions(checks: Checks) {
|
||||||
|
return { promote: checks.promotable, retire: checks.status !== 'champion' };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-governance-models',
|
||||||
|
imports: [
|
||||||
|
DatePipe,
|
||||||
|
DecimalPipe,
|
||||||
|
KeyValuePipe,
|
||||||
|
FormsModule,
|
||||||
|
MatButtonModule,
|
||||||
|
MatCheckboxModule,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatSelectModule,
|
||||||
|
Plot,
|
||||||
|
RunMonitor,
|
||||||
|
],
|
||||||
|
templateUrl: './models.html',
|
||||||
|
styleUrl: './models.scss',
|
||||||
|
})
|
||||||
|
export class Models {
|
||||||
|
private readonly api = inject(Api);
|
||||||
|
readonly domain = input.required<Domain>();
|
||||||
|
readonly execution = input<Choice>();
|
||||||
|
readonly trainingRequested = output<void>();
|
||||||
|
protected readonly reportNames = REPORTS;
|
||||||
|
protected readonly errorText = errorText;
|
||||||
|
readonly refreshed = signal(0);
|
||||||
|
|
||||||
|
refresh(): void {
|
||||||
|
this.refreshed.update((value) => value + 1);
|
||||||
|
}
|
||||||
|
protected readonly models = resource({
|
||||||
|
params: () => ({ domain: this.domain(), at: this.refreshed() }),
|
||||||
|
loader: async ({ params: { domain } }) => {
|
||||||
|
const found = await this.api.invoke(models, { domain });
|
||||||
|
return Promise.all(
|
||||||
|
found.map(async ({ name, title }) => ({
|
||||||
|
name,
|
||||||
|
title,
|
||||||
|
versions: await this.api.invoke(versions, { domain, name }),
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
readonly training = signal('all');
|
||||||
|
protected readonly run = signal<{ id: string; label: string; autoPromote?: boolean } | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
readonly starting = signal(false);
|
||||||
|
readonly running = signal(false);
|
||||||
|
protected readonly editing = signal(false);
|
||||||
|
protected readonly message = signal('');
|
||||||
|
protected readonly chosen = signal<VersionKey | undefined>(undefined);
|
||||||
|
protected readonly checksFor = signal<VersionKey | undefined>(undefined);
|
||||||
|
protected readonly lineageFor = signal<VersionKey | undefined>(undefined);
|
||||||
|
protected readonly checks = resource({
|
||||||
|
params: () => {
|
||||||
|
const key = this.checksFor();
|
||||||
|
return key ? { ...key, domain: this.domain(), at: this.refreshed() } : undefined;
|
||||||
|
},
|
||||||
|
loader: async ({ params: { at, ...params } }) => this.getChecks(params.domain, params),
|
||||||
|
});
|
||||||
|
protected readonly checkActions = checkActions;
|
||||||
|
protected readonly lineage = resource({
|
||||||
|
params: () => {
|
||||||
|
const key = this.lineageFor();
|
||||||
|
return key ? { ...key, domain: this.domain() } : undefined;
|
||||||
|
},
|
||||||
|
loader: async ({ params }) => (await this.api.invoke(lineage, params)) as Lineage,
|
||||||
|
});
|
||||||
|
protected readonly candidates = signal<VersionKey[]>([]);
|
||||||
|
protected readonly report = resource({
|
||||||
|
params: () => {
|
||||||
|
const key = this.chosen();
|
||||||
|
return key ? { ...key, domain: this.domain() } : undefined;
|
||||||
|
},
|
||||||
|
loader: ({ params }) =>
|
||||||
|
this.api.invoke(readReport$Json, { ...params, report: 'interpretability' }),
|
||||||
|
});
|
||||||
|
protected readonly ageFeatures = computed<string[]>(() => {
|
||||||
|
const report = this.report.hasValue() ? this.report.value() : undefined;
|
||||||
|
return report?.kind === 'age_curves' ? Object.keys(report['curves']) : [];
|
||||||
|
});
|
||||||
|
protected readonly selectedFeature = signal('');
|
||||||
|
protected readonly feature = computed(() => {
|
||||||
|
const keys = this.ageFeatures();
|
||||||
|
return keys.includes(this.selectedFeature())
|
||||||
|
? this.selectedFeature()
|
||||||
|
: keys.includes('value')
|
||||||
|
? 'value'
|
||||||
|
: keys[0];
|
||||||
|
});
|
||||||
|
protected readonly band = resource({
|
||||||
|
params: () => {
|
||||||
|
const key = this.chosen();
|
||||||
|
const feature = this.feature();
|
||||||
|
if (!key || !feature || !this.report.hasValue()) return undefined;
|
||||||
|
if (this.report.value()['curves'][feature].kind === 'count_rate') return undefined;
|
||||||
|
return { ...key, domain: this.domain(), feature };
|
||||||
|
},
|
||||||
|
loader: async ({ params }) => (await this.api.invoke(curve, params)) as Centile[],
|
||||||
|
});
|
||||||
|
protected readonly overlay = signal(false);
|
||||||
|
protected readonly analysed = resource({
|
||||||
|
params: () =>
|
||||||
|
this.overlay() && this.domain() === 'tea' && this.feature()
|
||||||
|
? this.refreshed() + 1
|
||||||
|
: undefined,
|
||||||
|
loader: async () => {
|
||||||
|
const found = await this.api.invoke(studies);
|
||||||
|
return Promise.all(
|
||||||
|
found
|
||||||
|
.filter((entry) => entry.analysed)
|
||||||
|
.map(({ id }) => this.api.invoke(study, { eeg_id: id })),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
protected readonly figures = computed(() => {
|
||||||
|
if (!this.report.hasValue()) return [];
|
||||||
|
const report = this.report.value();
|
||||||
|
const feature = this.feature();
|
||||||
|
const points =
|
||||||
|
this.analysed.hasValue() && feature
|
||||||
|
? studyPoints(this.analysed.value(), report['model'], feature)
|
||||||
|
: [];
|
||||||
|
return interpretabilityFigures(report, {
|
||||||
|
feature,
|
||||||
|
centiles: this.band.hasValue() ? this.band.value() : undefined,
|
||||||
|
points,
|
||||||
|
waitForCentiles: report['kind'] === 'age_curves',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
effect(() => {
|
||||||
|
this.domain();
|
||||||
|
this.training.set('all');
|
||||||
|
this.run.set(undefined);
|
||||||
|
this.running.set(false);
|
||||||
|
this.starting.set(false);
|
||||||
|
this.editing.set(false);
|
||||||
|
this.message.set('');
|
||||||
|
this.chosen.set(undefined);
|
||||||
|
this.checksFor.set(undefined);
|
||||||
|
this.lineageFor.set(undefined);
|
||||||
|
this.overlay.set(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected selectTraining(name: string): void {
|
||||||
|
this.training.set(name);
|
||||||
|
this.trainingRequested.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async reportDownload(name: string, version: number, report: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response = await this.api.invoke$Response(readReport$Any, {
|
||||||
|
domain: this.domain(),
|
||||||
|
name,
|
||||||
|
version,
|
||||||
|
report,
|
||||||
|
});
|
||||||
|
const filename = /filename="([^"]+)"/.exec(
|
||||||
|
response.headers.get('Content-Disposition') ?? '',
|
||||||
|
)?.[1];
|
||||||
|
download(response.body, filename ?? report);
|
||||||
|
} catch (error) {
|
||||||
|
this.message.set(errorText(error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async upload(name: string, version: number, event: Event): Promise<void> {
|
||||||
|
const input = event.target as HTMLInputElement;
|
||||||
|
const file = input.files?.[0];
|
||||||
|
if (!file) return;
|
||||||
|
const domain = this.domain();
|
||||||
|
try {
|
||||||
|
await this.api.invoke(addClinicalValidation, {
|
||||||
|
domain,
|
||||||
|
name,
|
||||||
|
version,
|
||||||
|
body: { file: file as unknown as string },
|
||||||
|
});
|
||||||
|
input.value = '';
|
||||||
|
if (domain !== this.domain()) return;
|
||||||
|
this.message.set(`Validación clínica agregada a ${name} v${version}.`);
|
||||||
|
this.refresh();
|
||||||
|
} catch (error) {
|
||||||
|
this.message.set(errorText(error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected showVersion(
|
||||||
|
kind: 'checks' | 'lineage',
|
||||||
|
key: VersionKey,
|
||||||
|
dialog: HTMLDialogElement,
|
||||||
|
): void {
|
||||||
|
(kind === 'checks' ? this.checksFor : this.lineageFor).set(key);
|
||||||
|
dialog.showModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async changeVersion(key: VersionKey, action: 'promote' | 'retire'): Promise<void> {
|
||||||
|
const domain = this.domain();
|
||||||
|
this.editing.set(true);
|
||||||
|
this.message.set('');
|
||||||
|
try {
|
||||||
|
if (action === 'promote') await this.api.invoke(promote, { domain, ...key });
|
||||||
|
else await this.api.invoke(retire, { domain, ...key });
|
||||||
|
this.message.set(
|
||||||
|
`${key.name} v${key.version}: ${action === 'promote' ? 'en producción' : 'retirada'}.`,
|
||||||
|
);
|
||||||
|
this.refresh();
|
||||||
|
} catch (error) {
|
||||||
|
this.message.set(errorText(error));
|
||||||
|
} finally {
|
||||||
|
this.editing.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async prepareCandidates(dialog: HTMLDialogElement): Promise<void> {
|
||||||
|
if (!this.models.hasValue()) return;
|
||||||
|
const domain = this.domain();
|
||||||
|
this.editing.set(true);
|
||||||
|
this.message.set('');
|
||||||
|
try {
|
||||||
|
const latest = this.models.value().flatMap(({ name, versions }) => {
|
||||||
|
const newest = versions.reduce<(typeof versions)[number] | undefined>(
|
||||||
|
(current, version) => (!current || version.version > current.version ? version : current),
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
return newest?.status === 'candidate' ? [{ name, version: newest.version }] : [];
|
||||||
|
});
|
||||||
|
const allowed = await Promise.all(
|
||||||
|
latest.map(async (key) => (await this.getChecks(domain, key)).promotable),
|
||||||
|
);
|
||||||
|
if (domain !== this.domain()) return;
|
||||||
|
const found = latest.filter((_, index) => allowed[index]);
|
||||||
|
this.candidates.set(found);
|
||||||
|
if (found.length) dialog.showModal();
|
||||||
|
else this.message.set('No hay candidatas que se puedan promover.');
|
||||||
|
} catch (error) {
|
||||||
|
this.message.set(errorText(error));
|
||||||
|
} finally {
|
||||||
|
this.editing.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async promoteCandidates(dialog: HTMLDialogElement): Promise<void> {
|
||||||
|
this.editing.set(true);
|
||||||
|
this.message.set('');
|
||||||
|
try {
|
||||||
|
await this.promoteVersions(this.domain(), this.candidates());
|
||||||
|
dialog.close();
|
||||||
|
} finally {
|
||||||
|
this.editing.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected forestHeight(rows: number): number {
|
||||||
|
return Math.max(360, rows * 24 + 72);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected chooseReport(key: VersionKey): void {
|
||||||
|
this.overlay.set(false);
|
||||||
|
this.selectedFeature.set('');
|
||||||
|
this.chosen.set(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
follow(id: string, label: string, autoPromote = false): void {
|
||||||
|
this.message.set('');
|
||||||
|
this.run.set({ id, label, autoPromote });
|
||||||
|
this.running.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async start(kind: 'score' | 'analyze'): Promise<void> {
|
||||||
|
const domain = this.domain();
|
||||||
|
this.starting.set(true);
|
||||||
|
this.message.set('');
|
||||||
|
try {
|
||||||
|
const { run_id } =
|
||||||
|
kind === 'score'
|
||||||
|
? await this.api.invoke(score, { domain })
|
||||||
|
: await this.api.invoke(analyze, { domain, body: { execution: this.execution() } });
|
||||||
|
if (domain === this.domain())
|
||||||
|
this.follow(run_id, kind === 'score' ? 'Cálculo de riesgos' : 'Análisis de EEG');
|
||||||
|
} catch (error) {
|
||||||
|
this.message.set(errorText(error));
|
||||||
|
} finally {
|
||||||
|
this.starting.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async finish(run: Run): Promise<void> {
|
||||||
|
const domain = this.domain();
|
||||||
|
const active = this.run();
|
||||||
|
if (active?.id !== run.id) return;
|
||||||
|
try {
|
||||||
|
if (!active.autoPromote) return;
|
||||||
|
if (run.state !== 'succeeded') {
|
||||||
|
this.message.set('No se promovió: el entrenamiento no terminó correctamente.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newVersions = run.info.flatMap((line) => {
|
||||||
|
const match = /^train_models: tea\.(.+): version (\d+)$/.exec(line);
|
||||||
|
return match ? [{ name: match[1], version: Number(match[2]) }] : [];
|
||||||
|
});
|
||||||
|
if (newVersions.length) await this.promoteVersions(domain, newVersions);
|
||||||
|
else this.message.set('No se promovió: el entrenamiento no registró versiones nuevas.');
|
||||||
|
} finally {
|
||||||
|
if (domain === this.domain() && this.run()?.id === run.id) {
|
||||||
|
this.refresh();
|
||||||
|
this.running.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getChecks(domain: Domain, key: VersionKey): Promise<Checks> {
|
||||||
|
return (await this.api.invoke(versionChecks, { domain, ...key })) as Checks;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async promoteVersions(domain: Domain, keys: VersionKey[]): Promise<void> {
|
||||||
|
const messages = await Promise.all(
|
||||||
|
keys.map(async (key) => {
|
||||||
|
const label = `${key.name} v${key.version}`;
|
||||||
|
try {
|
||||||
|
const checks = await this.getChecks(domain, key);
|
||||||
|
if (!checks.promotable) {
|
||||||
|
const missing = checks.checks
|
||||||
|
.filter((check) => !check.present)
|
||||||
|
.map((check) => REPORTS[check.report] ?? check.report);
|
||||||
|
const reason = missing.length ? `faltan ${missing.join(', ')}` : checks.status;
|
||||||
|
return `No se promovió ${label}: ${reason}.`;
|
||||||
|
}
|
||||||
|
await this.api.invoke(promote, { domain, ...key });
|
||||||
|
return `${label}: en producción.`;
|
||||||
|
} catch (error) {
|
||||||
|
return `No se promovió ${label}: ${errorText(error)}`;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (domain !== this.domain()) return;
|
||||||
|
this.message.set(messages.join('\n'));
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ import { KeyValuePipe } from '@angular/common';
|
|||||||
import { Component, inject, signal } from '@angular/core';
|
import { Component, inject, signal } from '@angular/core';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { Api } from '../../api/api';
|
import { Api } from '../../api/api';
|
||||||
import { previewStatus } from '../../api/fn/preview/preview-status';
|
import { previewStatus } from '../../api/fn/preview/preview-status';
|
||||||
import { startPreview } from '../../api/fn/preview/start-preview';
|
import { startPreview } from '../../api/fn/preview/start-preview';
|
||||||
@@ -12,15 +14,50 @@ import { downloadPreviewPdf } from './preview-pdf';
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-eeg-preview',
|
selector: 'app-eeg-preview',
|
||||||
imports: [FormsModule, KeyValuePipe, MatButtonModule, RunMonitor],
|
imports: [
|
||||||
|
FormsModule,
|
||||||
|
KeyValuePipe,
|
||||||
|
MatButtonModule,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatInputModule,
|
||||||
|
RunMonitor,
|
||||||
|
],
|
||||||
template: `
|
template: `
|
||||||
<section>
|
<section class="card" aria-labelledby="preview-heading">
|
||||||
<h3>Vista previa</h3>
|
<h2 id="preview-heading">Vista previa</h2>
|
||||||
<form (ngSubmit)="start(edf.files?.[0], ados.files?.[0], birth.value)">
|
<form (ngSubmit)="start(edf.files?.[0], ados.files?.[0], birth.value)">
|
||||||
<label>EDF <input #edf type="file" accept=".edf" required /></label>
|
<input
|
||||||
<label>ADOS-2 (PDF) <input #ados type="file" accept=".pdf" /></label>
|
#edf
|
||||||
<label>Fecha de nacimiento <input #birth type="date" /></label>
|
type="file"
|
||||||
<button mat-stroked-button type="submit" [disabled]="busy()">Vista previa</button>
|
accept=".edf"
|
||||||
|
required
|
||||||
|
hidden
|
||||||
|
aria-label="EDF"
|
||||||
|
(change)="edfFiles.set(edf.files)"
|
||||||
|
/>
|
||||||
|
<button mat-stroked-button type="button" (click)="edf.click()">EDF</button>
|
||||||
|
@for (file of edfFiles(); track $index) {
|
||||||
|
<span>{{ file.name }}</span>
|
||||||
|
}
|
||||||
|
<input
|
||||||
|
#ados
|
||||||
|
type="file"
|
||||||
|
accept=".pdf"
|
||||||
|
hidden
|
||||||
|
aria-label="ADOS-2 (PDF)"
|
||||||
|
(change)="adosFiles.set(ados.files)"
|
||||||
|
/>
|
||||||
|
<button mat-stroked-button type="button" (click)="ados.click()">ADOS-2 (PDF)</button>
|
||||||
|
@for (file of adosFiles(); track $index) {
|
||||||
|
<span>{{ file.name }}</span>
|
||||||
|
}
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Fecha de nacimiento</mat-label>
|
||||||
|
<input matInput #birth type="date" />
|
||||||
|
</mat-form-field>
|
||||||
|
<button mat-stroked-button type="submit" [disabled]="busy() || !edfFiles()?.length">
|
||||||
|
Vista previa
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@if (error()) {
|
@if (error()) {
|
||||||
<p role="alert">{{ error() }}</p>
|
<p role="alert">{{ error() }}</p>
|
||||||
@@ -151,6 +188,8 @@ import { downloadPreviewPdf } from './preview-pdf';
|
|||||||
})
|
})
|
||||||
export class EegPreview {
|
export class EegPreview {
|
||||||
private readonly api = inject(Api);
|
private readonly api = inject(Api);
|
||||||
|
protected readonly edfFiles = signal<FileList | null>(null);
|
||||||
|
protected readonly adosFiles = signal<FileList | null>(null);
|
||||||
protected readonly busy = signal(false);
|
protected readonly busy = signal(false);
|
||||||
protected readonly error = signal('');
|
protected readonly error = signal('');
|
||||||
protected readonly runId = signal('');
|
protected readonly runId = signal('');
|
||||||
|
|||||||
@@ -1,29 +1,46 @@
|
|||||||
<section class="card model">
|
<section class="card" aria-labelledby="studies-heading">
|
||||||
<h2>Estudios EEG</h2>
|
<h2 id="studies-heading">Estudios EEG</h2>
|
||||||
<form (ngSubmit)="analyze()">
|
<form (ngSubmit)="analyze()">
|
||||||
<label
|
<mat-form-field appearance="outline">
|
||||||
>Alcance
|
<mat-label>Alcance</mat-label>
|
||||||
<select name="scope" [(ngModel)]="mode">
|
<mat-select name="scope" [(ngModel)]="mode">
|
||||||
<option value="pending">Pendientes</option>
|
<mat-option value="pending">Pendientes</mat-option>
|
||||||
<option value="first_n">Primeros N</option>
|
<mat-option value="first_n">Primeros N</mat-option>
|
||||||
<option value="ids">Por ID</option>
|
<mat-option value="ids">Por ID</mat-option>
|
||||||
</select>
|
</mat-select>
|
||||||
</label>
|
</mat-form-field>
|
||||||
@if (mode() === 'first_n') {
|
@if (mode() === 'first_n') {
|
||||||
<label
|
<mat-form-field appearance="outline">
|
||||||
>Número de estudios <input type="number" name="count" min="1" required [(ngModel)]="count"
|
<mat-label>Número de estudios</mat-label>
|
||||||
/></label>
|
<input matInput type="number" name="count" min="1" required [(ngModel)]="count" />
|
||||||
|
</mat-form-field>
|
||||||
}
|
}
|
||||||
@if (mode() === 'ids') {
|
@if (mode() === 'ids') {
|
||||||
<label
|
<mat-form-field appearance="outline">
|
||||||
>ID de estudios (uno por línea) <textarea name="ids" required [(ngModel)]="ids"></textarea>
|
<mat-label>ID de estudios (uno por línea)</mat-label>
|
||||||
</label>
|
<textarea matInput name="ids" required [(ngModel)]="ids"></textarea>
|
||||||
|
</mat-form-field>
|
||||||
}
|
}
|
||||||
<button mat-flat-button type="submit" [disabled]="busy() || !execution()">Analizar</button>
|
<button mat-flat-button type="submit" [disabled]="busy() || !execution()">Analizar</button>
|
||||||
</form>
|
</form>
|
||||||
<form (ngSubmit)="upload(files)">
|
<form (ngSubmit)="upload(files)">
|
||||||
<label>Archivos EDF <input #files type="file" accept=".edf" multiple required /></label>
|
<input
|
||||||
<button mat-stroked-button type="submit" [disabled]="busy()">Subir EDF</button>
|
#files
|
||||||
|
type="file"
|
||||||
|
accept=".edf"
|
||||||
|
multiple
|
||||||
|
required
|
||||||
|
hidden
|
||||||
|
aria-label="Archivos EDF"
|
||||||
|
(change)="selectedFiles.set(files.files)"
|
||||||
|
/>
|
||||||
|
<button mat-stroked-button type="button" (click)="files.click()">Archivos EDF</button>
|
||||||
|
@for (file of selectedFiles(); track $index) {
|
||||||
|
<span>{{ file.name }}</span>
|
||||||
|
}
|
||||||
|
<button mat-stroked-button type="submit" [disabled]="busy() || !selectedFiles()?.length">
|
||||||
|
Subir EDF
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@if (error()) {
|
@if (error()) {
|
||||||
<p role="alert">{{ error() }}</p>
|
<p role="alert">{{ error() }}</p>
|
||||||
@@ -31,7 +48,6 @@
|
|||||||
@if (runId(); as id) {
|
@if (runId(); as id) {
|
||||||
<app-run-monitor [runId]="id" (finished)="finish()" />
|
<app-run-monitor [runId]="id" (finished)="finish()" />
|
||||||
}
|
}
|
||||||
<app-eeg-preview />
|
|
||||||
<h3>Resumen</h3>
|
<h3>Resumen</h3>
|
||||||
@if (summary.hasValue()) {
|
@if (summary.hasValue()) {
|
||||||
<dl>
|
<dl>
|
||||||
@@ -81,7 +97,12 @@
|
|||||||
@for (e of eegs.hasValue() ? eegs.value() : []; track e.id) {
|
@for (e of eegs.hasValue() ? eegs.value() : []; track e.id) {
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<button mat-button type="button" [disabled]="!e.analysed" (click)="eeg.set(e.id)">
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="button"
|
||||||
|
[disabled]="!e.analysed"
|
||||||
|
(click)="eeg.set(e.id)"
|
||||||
|
>
|
||||||
{{ e.study_date }}
|
{{ e.study_date }}
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ import { HttpErrorResponse } from '@angular/common/http';
|
|||||||
import { Component, inject, input, output, resource, signal } from '@angular/core';
|
import { Component, inject, input, output, resource, signal } from '@angular/core';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatInputModule } from '@angular/material/input';
|
||||||
|
import { MatSelectModule } from '@angular/material/select';
|
||||||
import { Api } from '../../api/api';
|
import { Api } from '../../api/api';
|
||||||
import { analyzeEegs } from '../../api/fn/eeg/analyze-eegs';
|
import { analyzeEegs } from '../../api/fn/eeg/analyze-eegs';
|
||||||
import { eegStudiesSummary } from '../../api/fn/eeg/eeg-studies-summary';
|
import { eegStudiesSummary } from '../../api/fn/eeg/eeg-studies-summary';
|
||||||
@@ -15,7 +18,6 @@ import { runHistory } from '../../api/fn/runs/run-history';
|
|||||||
import type { Execution } from '../../api/models/execution';
|
import type { Execution } from '../../api/models/execution';
|
||||||
import type { Scope } from '../../api/models/scope';
|
import type { Scope } from '../../api/models/scope';
|
||||||
import { errorText, RunMonitor } from '../run-monitor';
|
import { errorText, RunMonitor } from '../run-monitor';
|
||||||
import { EegPreview } from './preview';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-eeg-studies',
|
selector: 'app-eeg-studies',
|
||||||
@@ -25,8 +27,10 @@ import { EegPreview } from './preview';
|
|||||||
KeyValuePipe,
|
KeyValuePipe,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatInputModule,
|
||||||
|
MatSelectModule,
|
||||||
RunMonitor,
|
RunMonitor,
|
||||||
EegPreview,
|
|
||||||
],
|
],
|
||||||
templateUrl: './studies.html',
|
templateUrl: './studies.html',
|
||||||
})
|
})
|
||||||
@@ -94,6 +98,7 @@ export class EegStudies {
|
|||||||
protected readonly mode = signal<NonNullable<Scope['mode']>>('pending');
|
protected readonly mode = signal<NonNullable<Scope['mode']>>('pending');
|
||||||
protected readonly count = signal<number | null>(null);
|
protected readonly count = signal<number | null>(null);
|
||||||
protected readonly ids = signal('');
|
protected readonly ids = signal('');
|
||||||
|
protected readonly selectedFiles = signal<FileList | null>(null);
|
||||||
protected readonly busy = signal(false);
|
protected readonly busy = signal(false);
|
||||||
protected readonly error = signal('');
|
protected readonly error = signal('');
|
||||||
protected readonly runId = signal('');
|
protected readonly runId = signal('');
|
||||||
@@ -129,6 +134,7 @@ export class EegStudies {
|
|||||||
await this.api.invoke(upload, { body: { files: files as unknown as string[] } });
|
await this.api.invoke(upload, { body: { files: files as unknown as string[] } });
|
||||||
const run = await this.api.invoke(startRun, { pipeline_id: 'tea', body: {} });
|
const run = await this.api.invoke(startRun, { pipeline_id: 'tea', body: {} });
|
||||||
input.value = '';
|
input.value = '';
|
||||||
|
this.selectedFiles.set(null);
|
||||||
return run;
|
return run;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof HttpErrorResponse && error.status === 404) {
|
if (error instanceof HttpErrorResponse && error.status === 404) {
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { Component, inject, input, model, output, resource, signal } from '@angular/core';
|
import {
|
||||||
|
Component,
|
||||||
|
ElementRef,
|
||||||
|
inject,
|
||||||
|
input,
|
||||||
|
linkedSignal,
|
||||||
|
model,
|
||||||
|
output,
|
||||||
|
resource,
|
||||||
|
signal,
|
||||||
|
viewChild,
|
||||||
|
} from '@angular/core';
|
||||||
import { FormsModule, ReactiveFormsModule, UntypedFormGroup } from '@angular/forms';
|
import { FormsModule, ReactiveFormsModule, UntypedFormGroup } from '@angular/forms';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { FormlyForm, provideFormlyCore } from '@ngx-formly/core';
|
import { FormlyForm, provideFormlyCore } from '@ngx-formly/core';
|
||||||
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
|
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
|
||||||
import { withFormlyMaterial } from '@ngx-formly/material';
|
import { withFormlyMaterial } from '@ngx-formly/material';
|
||||||
@@ -65,19 +79,29 @@ function allowedFile(file: File, allowed: string[]): boolean {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-governance-training',
|
selector: 'app-governance-training',
|
||||||
imports: [FormsModule, ReactiveFormsModule, FormlyForm, MatButtonModule],
|
imports: [
|
||||||
|
FormsModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
FormlyForm,
|
||||||
|
MatButtonModule,
|
||||||
|
MatCheckboxModule,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatInputModule,
|
||||||
|
],
|
||||||
providers: [provideFormlyCore([...withFormlyMaterial(), FORMLY_TYPES])],
|
providers: [provideFormlyCore([...withFormlyMaterial(), FORMLY_TYPES])],
|
||||||
template: `
|
template: `
|
||||||
<section class="card">
|
<section class="card" aria-labelledby="training-heading">
|
||||||
<h3>{{ name() === 'all' ? 'Entrenar modelos' : 'Reentrenar ' + name() }}</h3>
|
<h2 #heading id="training-heading" tabindex="-1">Entrenamiento</h2>
|
||||||
|
@if (name() !== 'all') {
|
||||||
|
<p>Reentrenar {{ name() }}</p>
|
||||||
|
}
|
||||||
@if (config.hasValue()) {
|
@if (config.hasValue()) {
|
||||||
@let form = config.value();
|
@let form = config.value();
|
||||||
<form (ngSubmit)="start(form.model)">
|
<form (ngSubmit)="start(form.model)">
|
||||||
<formly-form [form]="form.form" [fields]="form.fields" [model]="form.model" />
|
<formly-form [form]="form.form" [fields]="form.fields" [model]="form.model" />
|
||||||
@if (domain() === 'tea') {
|
@if (domain() === 'tea') {
|
||||||
<label
|
<mat-checkbox name="promote" [(ngModel)]="autoPromote"
|
||||||
><input type="checkbox" name="promote" [(ngModel)]="autoPromote" /> Promover al
|
>Promover al terminar</mat-checkbox
|
||||||
terminar</label
|
|
||||||
>
|
>
|
||||||
}
|
}
|
||||||
<button
|
<button
|
||||||
@@ -103,20 +127,36 @@ function allowedFile(file: File, allowed: string[]): boolean {
|
|||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
<form (ngSubmit)="upload(setName.value, files)">
|
<form (ngSubmit)="upload(setName.value, files)">
|
||||||
<label
|
<mat-form-field appearance="outline">
|
||||||
>Conjunto
|
<mat-label>Conjunto</mat-label>
|
||||||
<input #setName list="training-input-sets" required />
|
<input matInput #setName list="training-input-sets" required />
|
||||||
</label>
|
</mat-form-field>
|
||||||
<datalist id="training-input-sets">
|
<datalist id="training-input-sets">
|
||||||
@for (set of sets.sets; track set.name) {
|
@for (set of sets.sets; track set.name) {
|
||||||
<option [value]="set.name"></option>
|
<option [value]="set.name"></option>
|
||||||
}
|
}
|
||||||
</datalist>
|
</datalist>
|
||||||
<label
|
<input
|
||||||
>Archivos
|
#files
|
||||||
<input #files type="file" multiple required [accept]="accept(sets.allowed)" />
|
type="file"
|
||||||
</label>
|
multiple
|
||||||
<button mat-stroked-button type="submit" [disabled]="uploading()">Subir archivos</button>
|
required
|
||||||
|
[accept]="accept(sets.allowed)"
|
||||||
|
hidden
|
||||||
|
aria-label="Archivos"
|
||||||
|
(change)="selectedFiles.set(files.files)"
|
||||||
|
/>
|
||||||
|
<button mat-stroked-button type="button" (click)="files.click()">Archivos</button>
|
||||||
|
@for (file of selectedFiles(); track $index) {
|
||||||
|
<span>{{ file.name }}</span>
|
||||||
|
}
|
||||||
|
<button
|
||||||
|
mat-stroked-button
|
||||||
|
type="submit"
|
||||||
|
[disabled]="uploading() || !selectedFiles()?.length"
|
||||||
|
>
|
||||||
|
Subir archivos
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
} @else if (inputs.error(); as error) {
|
} @else if (inputs.error(); as error) {
|
||||||
<p role="alert">{{ errorText(error) }}</p>
|
<p role="alert">{{ errorText(error) }}</p>
|
||||||
@@ -128,6 +168,7 @@ function allowedFile(file: File, allowed: string[]): boolean {
|
|||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
export class Training {
|
export class Training {
|
||||||
|
private readonly heading = viewChild.required<ElementRef<HTMLHeadingElement>>('heading');
|
||||||
private readonly api = inject(Api);
|
private readonly api = inject(Api);
|
||||||
private readonly jsonschema = inject(FormlyJsonschema);
|
private readonly jsonschema = inject(FormlyJsonschema);
|
||||||
readonly domain = input.required<Domain>();
|
readonly domain = input.required<Domain>();
|
||||||
@@ -142,6 +183,7 @@ export class Training {
|
|||||||
const fields = [
|
const fields = [
|
||||||
this.jsonschema.toFieldConfig(schema, {
|
this.jsonschema.toFieldConfig(schema, {
|
||||||
map: (field, source) => {
|
map: (field, source) => {
|
||||||
|
field.props = { ...field.props, appearance: 'outline' };
|
||||||
if (source.format === 'date') {
|
if (source.format === 'date') {
|
||||||
field.props = { ...field.props, type: 'date' };
|
field.props = { ...field.props, type: 'date' };
|
||||||
}
|
}
|
||||||
@@ -184,11 +226,19 @@ export class Training {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
readonly busy = model(false);
|
readonly busy = model(false);
|
||||||
|
protected readonly selectedFiles = linkedSignal({
|
||||||
|
source: () => (this.inputs.hasValue() ? this.inputs.value() : undefined),
|
||||||
|
computation: (): FileList | null => null,
|
||||||
|
});
|
||||||
protected readonly uploading = signal(false);
|
protected readonly uploading = signal(false);
|
||||||
protected readonly message = signal('');
|
protected readonly message = signal('');
|
||||||
protected readonly autoPromote = signal(false);
|
protected readonly autoPromote = linkedSignal({ source: this.domain, computation: () => false });
|
||||||
protected readonly errorText = errorText;
|
protected readonly errorText = errorText;
|
||||||
|
|
||||||
|
focus(): void {
|
||||||
|
this.heading().nativeElement.focus();
|
||||||
|
}
|
||||||
|
|
||||||
protected async start(model: TrainingConfig['defaults']): Promise<void> {
|
protected async start(model: TrainingConfig['defaults']): Promise<void> {
|
||||||
if (this.busy() || this.disabled()) return;
|
if (this.busy() || this.disabled()) return;
|
||||||
this.busy.set(true);
|
this.busy.set(true);
|
||||||
@@ -206,11 +256,11 @@ export class Training {
|
|||||||
...(name === 'all' ? {} : { models: [name] }),
|
...(name === 'all' ? {} : { models: [name] }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.started.emit({ id: run_id, autoPromote });
|
if (domain === this.domain()) this.started.emit({ id: run_id, autoPromote });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.message.set(errorText(error));
|
if (domain === this.domain()) this.message.set(errorText(error));
|
||||||
} finally {
|
} finally {
|
||||||
this.busy.set(false);
|
if (domain === this.domain()) this.busy.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,6 +289,7 @@ export class Training {
|
|||||||
body: { files },
|
body: { files },
|
||||||
});
|
});
|
||||||
input.value = '';
|
input.value = '';
|
||||||
|
this.selectedFiles.set(null);
|
||||||
this.inputs.reload();
|
this.inputs.reload();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.message.set(errorText(error));
|
this.message.set(errorText(error));
|
||||||
|
|||||||
Reference in New Issue
Block a user