Gobernanza: execution, models (training, run monitor, checks, lineage, bundles, interpretability), EEG studies
Share one execution selection across training and analysis. Use the first configured scheduler for a remote default and let the API validate typed addresses. Suspend health polling when the document is hidden. Poll each run serially, retry status reads on transient errors, and compute ETA from completed items and elapsed seconds. Reuse the Conectar Formly types with nullable fields and inlined references. Omit the optional cohort when its name is blank, and offer the declared input sets in a datalist with filename validation before upload. Identify the versions created by a training run from its version log lines, then check each exact version before promotion. Use native dialogs for checks, lineage, bulk confirmation and preview. Recheck promotion eligibility before submitting changes, and list results per version. Verify bundle hashes using SubtleCrypto before upload. Use blob downloads for bundles and reports. Read age centiles from the curve endpoint and keep the count-rate reference line from the report. Join study metrics by code and regional values by feature, skipping absent ages and values. Use one Plotly trace per association pair and scale the forest plot height by row count. Preflight the TEA pipeline before staging EDFs, then start the pipeline once for the batch. Refresh studies, their overlays and summary on completed runs. Page through analyze history to compare its end times against the latest tea_eeg result. The branch base lacks export/pdf.ts, so the preview uses the specified TODO and omits the PDF action. Added Vitest coverage for execution and run polling, ETA and cancellation, training schema, version actions, bundle digest verification, study overlays and the association forest. Ruff check, Ruff format --check, Prettier, strict Angular and TypeScript diagnostics for Gobernanza and git diff --check passed. npm ci, ng build and vitest run are assigned to the test machines.
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
import { KeyValuePipe } from '@angular/common';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { Api } from '../../api/api';
|
||||
import { previewStatus } from '../../api/fn/preview/preview-status';
|
||||
import { startPreview } from '../../api/fn/preview/start-preview';
|
||||
import type { PreviewResult } from '../../api/models/preview-result';
|
||||
import type { Run } from '../../api/models/run';
|
||||
import { RunMonitor, errorText } from '../run-monitor';
|
||||
|
||||
@Component({
|
||||
selector: 'app-eeg-preview',
|
||||
imports: [FormsModule, KeyValuePipe, MatButtonModule, RunMonitor],
|
||||
template: `
|
||||
<section>
|
||||
<h3>Vista previa</h3>
|
||||
<form (ngSubmit)="start(edf.files?.[0], ados.files?.[0], birth.value)">
|
||||
<label>EDF <input #edf type="file" accept=".edf" required /></label>
|
||||
<label>ADOS-2 (PDF) <input #ados type="file" accept=".pdf" /></label>
|
||||
<label>Fecha de nacimiento <input #birth type="date" /></label>
|
||||
<button mat-stroked-button type="submit" [disabled]="busy()">Vista previa</button>
|
||||
</form>
|
||||
@if (error()) {
|
||||
<p role="alert">{{ error() }}</p>
|
||||
}
|
||||
@if (runId(); as id) {
|
||||
<app-run-monitor [runId]="id" (finished)="finish($event, dialog)" />
|
||||
}
|
||||
<dialog #dialog aria-label="Vista previa del estudio">
|
||||
@if (result(); as r) {
|
||||
<h3>Resultado de la vista previa</h3>
|
||||
<p>
|
||||
{{ r.eeg.level }} ·
|
||||
{{ r.eeg.valid === true ? 'Válido' : r.eeg.valid === false ? 'No válido' : '—' }}
|
||||
</p>
|
||||
@if (r.eeg.error) {
|
||||
<p role="alert">{{ r.eeg.error }}</p>
|
||||
}
|
||||
<h4>Comprobaciones</h4>
|
||||
<table class="plain">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Comprobación</th>
|
||||
<th>Electrodo</th>
|
||||
<th>Resultado</th>
|
||||
<th>Rango</th>
|
||||
<th>Anormal</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (check of r.eeg.checks; track $index) {
|
||||
<tr>
|
||||
<td>{{ check['code'] }}</td>
|
||||
<td>{{ check['electrode'] ?? '—' }}</td>
|
||||
<td>{{ check['value'] ?? check['text'] ?? '—' }} {{ check['unit'] }}</td>
|
||||
<td>{{ check['low'] ?? '—' }} / {{ check['high'] ?? '—' }}</td>
|
||||
<td>
|
||||
{{
|
||||
check['abnormal'] === true ? 'Sí' : check['abnormal'] === false ? 'No' : '—'
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<h4>Métricas</h4>
|
||||
<table class="plain">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Métrica</th>
|
||||
<th>Valor</th>
|
||||
<th>z</th>
|
||||
<th>p5 / mediana / p95</th>
|
||||
<th>Fuera de rango</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (metric of r.eeg.metrics; track metric.code) {
|
||||
<tr>
|
||||
<th>{{ metric.code }}</th>
|
||||
<td>{{ metric.value ?? '—' }}</td>
|
||||
<td>{{ metric.score?.z ?? '—' }}</td>
|
||||
<td>
|
||||
{{ metric.score?.p5 ?? '—' }} / {{ metric.score?.median ?? '—' }} /
|
||||
{{ metric.score?.p95 ?? '—' }}
|
||||
</td>
|
||||
<td>{{ metric.score?.outside ?? '—' }}</td>
|
||||
</tr>
|
||||
@for (site of metric.electrodes | keyvalue; track site.key) {
|
||||
<tr>
|
||||
<td>{{ site.key }}</td>
|
||||
<td>{{ site.value.value ?? '—' }}</td>
|
||||
<td>{{ site.value.score?.z ?? '—' }}</td>
|
||||
<td>
|
||||
{{ site.value.score?.p5 ?? '—' }} / {{ site.value.score?.median ?? '—' }} /
|
||||
{{ site.value.score?.p95 ?? '—' }}
|
||||
</td>
|
||||
<td>{{ site.value.score?.outside ?? '—' }}</td>
|
||||
</tr>
|
||||
}
|
||||
@for (site of metric.zones | keyvalue; track site.key) {
|
||||
<tr>
|
||||
<td>{{ site.key }}</td>
|
||||
<td>{{ site.value.value ?? '—' }}</td>
|
||||
<td>{{ site.value.score?.z ?? '—' }}</td>
|
||||
<td>
|
||||
{{ site.value.score?.p5 ?? '—' }} / {{ site.value.score?.median ?? '—' }} /
|
||||
{{ site.value.score?.p95 ?? '—' }}
|
||||
</td>
|
||||
<td>{{ site.value.score?.outside ?? '—' }}</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@if (r.ados2; as ados2) {
|
||||
<h4>ADOS-2</h4>
|
||||
<p>{{ ados2.classification }} · CSS {{ ados2.css ?? '—' }}</p>
|
||||
<dl>
|
||||
@for (item of ados2.items | keyvalue; track item.key) {
|
||||
<dt>{{ item.key }}</dt>
|
||||
<dd>{{ item.value ?? '—' }}</dd>
|
||||
}
|
||||
</dl>
|
||||
}
|
||||
@if (r.warnings.length) {
|
||||
<h4>Advertencias</h4>
|
||||
<ul>
|
||||
@for (warning of r.warnings; track $index) {
|
||||
<li>{{ warning }}</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
}
|
||||
<form method="dialog"><button mat-stroked-button>Cerrar</button></form>
|
||||
</dialog>
|
||||
</section>
|
||||
`,
|
||||
})
|
||||
export class EegPreview {
|
||||
private readonly api = inject(Api);
|
||||
protected readonly busy = signal(false);
|
||||
protected readonly error = signal('');
|
||||
protected readonly runId = signal('');
|
||||
protected readonly result = signal<PreviewResult | null>(null);
|
||||
|
||||
protected async start(edf?: File, ados2?: File, birth_date?: string): Promise<void> {
|
||||
if (!edf) return;
|
||||
this.busy.set(true);
|
||||
this.error.set('');
|
||||
this.result.set(null);
|
||||
try {
|
||||
const { run_id } = await this.api.invoke(startPreview, {
|
||||
body: { edf, ados2, birth_date: birth_date || undefined },
|
||||
});
|
||||
this.runId.set(run_id);
|
||||
} catch (error) {
|
||||
this.error.set(errorText(error));
|
||||
this.busy.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected async finish(run: Run, dialog: HTMLDialogElement): Promise<void> {
|
||||
try {
|
||||
if (run.state !== 'succeeded') return;
|
||||
const { result } = await this.api.invoke(previewStatus, { run_id: run.id });
|
||||
this.result.set(result);
|
||||
if (result) dialog.showModal();
|
||||
else this.error.set('La vista previa no devolvió un resultado.');
|
||||
} catch (error) {
|
||||
this.error.set(errorText(error));
|
||||
} finally {
|
||||
this.busy.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user