From 344dafd9fc6faa679ffbaf190eb5968f0b17a5aa Mon Sep 17 00:00:00 2001 From: alberto Date: Tue, 1 Dec 2026 11:32:48 -0600 Subject: [PATCH] F1a: user fixes Keep preview visibility in the domain page and reset it on domain changes. Build the source controls from the folder schema, keep folder edits while hidden, and send only the discriminator for site training. Place the existing upload controls in the next card and use the server-declared file types. Keep shared ingestion endpoints used by Conectar and remove the EEG-page upload flow. Docker socket access was denied and the local environment lacks fastapi-users. Generate the changed OpenAPI route and schemas from the real models router with the production app settings, verify its other routes and schemas against the checked-in document, and run ng-openapi-gen directly from the cached dependencies. --- e2e/pages.spec.ts | 31 +++++- openapi.json | 101 ++++++++++++------- src/app/api/fn/models/training-inputs.ts | 4 +- src/app/api/models.ts | 2 + src/app/api/models/folder-training-source.ts | 12 +++ src/app/api/models/site-training-source.ts | 6 ++ src/app/api/models/training-source.ts | 15 +-- src/app/gobernanza/gobernanza.html | 5 +- src/app/gobernanza/gobernanza.ts | 3 +- src/app/gobernanza/models.html | 3 + src/app/gobernanza/models.ts | 1 + src/app/gobernanza/tea/studies.html | 19 ---- src/app/gobernanza/tea/studies.ts | 45 ++------- src/app/gobernanza/training.spec.ts | 27 +++-- src/app/gobernanza/training.ts | 78 +++++++------- 15 files changed, 197 insertions(+), 155 deletions(-) create mode 100644 src/app/api/models/folder-training-source.ts create mode 100644 src/app/api/models/site-training-source.ts diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index 780cc4a..47477c5 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -89,10 +89,16 @@ test('tea gobernanza: every section in sync mode, and the preview saved as PDF', 'Ejecución', 'Modelos', 'Entrenamiento', + 'Subir archivos', 'Bundles', 'Estudios EEG', - 'Vista previa', ]); + await expect(page.locator('app-eeg-preview')).toHaveCount(0); + await expect(page.getByText('Archivos de entrenamiento', { exact: true })).toHaveCount(0); + const uploads = page.getByRole('region', { name: 'Subir archivos' }); + await expect(uploads.getByLabel('Conjunto')).toBeVisible(); + await expect(uploads.getByRole('button', { name: 'Archivos', exact: true })).toBeVisible(); + await expect(uploads.getByRole('button', { name: 'Subir archivos' })).toBeDisabled(); await page.getByRole('combobox', { name: 'Modo' }).click(); await page.getByRole('option', { name: 'Sync' }).click(); await expect(page.getByRole('status').filter({ hasText: 'Disponible' })).toBeVisible(); @@ -103,6 +109,21 @@ test('tea gobernanza: every section in sync mode, and the preview saved as PDF', await expect(training).toBeFocused(); await expect(page.locator('app-governance-training formly-form')).toBeVisible(); + const source = page.getByRole('combobox', { name: 'Origen' }); + const folder = page.getByLabel('Carpeta', { exact: true }); + const line = page.getByRole('combobox', { name: 'Frecuencia de la red eléctrica (Hz)' }); + await expect(source).toHaveText('Niños del sitio sin el diagnóstico'); + await expect(folder).toBeHidden(); + await expect(line).toBeHidden(); + await source.click(); + await page.getByRole('option', { name: 'Carpeta de EDF con edades' }).click(); + await expect(folder).toBeVisible(); + await expect(line).toBeVisible(); + await source.click(); + await page.getByRole('option', { name: 'Niños del sitio sin el diagnóstico' }).click(); + await expect(folder).toBeHidden(); + await expect(line).toBeHidden(); + const monitor = page.locator('app-governance-models app-run-monitor'); await page.getByRole('button', { name: 'Analizar EEG' }).click(); await expect(page.getByRole('heading', { name: 'Análisis de EEG' })).toBeVisible(); @@ -114,6 +135,7 @@ test('tea gobernanza: every section in sync mode, and the preview saved as PDF', await expect(page.getByText('No hay candidatas que se puedan promover.')).toBeVisible(); const studies = page.locator('app-eeg-studies'); + await expect(studies.locator('input[type=file]')).toHaveCount(0); await expect(studies.locator('table.eegs tbody tr').first()).toContainText(/Válido|No válido/); await studies.locator('table.eegs tbody button:enabled').first().click(); await expect(studies.getByRole('heading', { name: /^EEG .* meses$/ })).toBeVisible(); @@ -123,7 +145,14 @@ test('tea gobernanza: every section in sync mode, and the preview saved as PDF', { timeout: 10 * 60_000 }, ); + await page + .locator('app-governance-models') + .getByRole('button', { + name: 'Evaluar un solo estudio', + }) + .click(); const preview = page.locator('app-eeg-preview'); + await expect(preview.getByRole('heading', { name: 'Vista previa' })).toBeVisible(); await preview.getByLabel('EDF').setInputFiles(process.env['TEA_EDF']!); await preview.getByLabel('ADOS-2 (PDF)').setInputFiles(process.env['TEA_ADOS2']!); await preview.getByLabel('Fecha de nacimiento').fill(process.env['TEA_BIRTH']!); diff --git a/openapi.json b/openapi.json index e3f0dd7..e184e44 100644 --- a/openapi.json +++ b/openapi.json @@ -1077,6 +1077,37 @@ "title": "FieldSpec", "type": "object" }, + "FolderTrainingSource": { + "additionalProperties": false, + "properties": { + "folder": { + "description": "Carpeta dentro de TEA_REFERENCE_ROOT", + "pattern": "^[A-Za-z0-9._-]{1,64}$", + "title": "Carpeta", + "type": "string" + }, + "kind": { + "const": "folder", + "title": "Kind", + "type": "string" + }, + "line_hz": { + "default": 50, + "enum": [ + 50, + 60 + ], + "title": "Frecuencia de la red el\u00e9ctrica (Hz)", + "type": "integer" + } + }, + "required": [ + "kind", + "folder" + ], + "title": "FolderTrainingSource", + "type": "object" + }, "Group": { "additionalProperties": false, "properties": { @@ -2840,6 +2871,21 @@ "title": "Site", "type": "object" }, + "SiteTrainingSource": { + "additionalProperties": false, + "properties": { + "kind": { + "const": "site", + "title": "Kind", + "type": "string" + } + }, + "required": [ + "kind" + ], + "title": "SiteTrainingSource", + "type": "object" + }, "Source": { "additionalProperties": false, "description": "One table, file set or API resource, copied as it is (dlt). Merged on the source's\nown primary key or `primary_key`; replaced whole when it has none.", @@ -3448,43 +3494,21 @@ "type": "object" }, "TrainingSource": { - "additionalProperties": false, - "properties": { - "folder": { - "anyOf": [ - { - "pattern": "^[A-Za-z0-9._-]{1,64}$", - "type": "string" - }, - { - "type": "null" - } - ], - "description": "Carpeta dentro de TEA_REFERENCE_ROOT", - "title": "Carpeta" + "discriminator": { + "mapping": { + "folder": "#/components/schemas/FolderTrainingSource", + "site": "#/components/schemas/SiteTrainingSource" }, - "kind": { - "default": "site", - "description": "site: los ni\u00f1os del sitio sin el diagn\u00f3stico a la fecha de corte; folder: una carpeta de EDF con edades.csv (path, age en meses)", - "enum": [ - "site", - "folder" - ], - "title": "Origen", - "type": "string" - }, - "line_hz": { - "default": 50, - "enum": [ - 50, - 60 - ], - "title": "Frecuencia de la red el\u00e9ctrica (Hz)", - "type": "integer" - } + "propertyName": "kind" }, - "title": "Datos de entrenamiento", - "type": "object" + "oneOf": [ + { + "$ref": "#/components/schemas/SiteTrainingSource" + }, + { + "$ref": "#/components/schemas/FolderTrainingSource" + } + ] }, "Uploaded": { "properties": { @@ -5304,7 +5328,12 @@ "content": { "application/json": { "schema": { - "additionalProperties": true, + "additionalProperties": { + "items": { + "type": "string" + }, + "type": "array" + }, "title": "Response Training Inputs", "type": "object" } diff --git a/src/app/api/fn/models/training-inputs.ts b/src/app/api/fn/models/training-inputs.ts index f4fb379..b27ecf2 100644 --- a/src/app/api/fn/models/training-inputs.ts +++ b/src/app/api/fn/models/training-inputs.ts @@ -15,7 +15,7 @@ export interface TrainingInputs$Params { } export function trainingInputs(http: HttpClient, rootUrl: string, params: TrainingInputs$Params, context?: HttpContext): Observable; }>> { const rb = new RequestBuilder(rootUrl, trainingInputs.PATH, 'get'); if (params) { @@ -29,7 +29,7 @@ export function trainingInputs(http: HttpClient, rootUrl: string, params: Traini filter((r: any): r is HttpResponse => r instanceof HttpResponse), map((r: HttpResponse) => { return r as StrictHttpResponse<{ - [key: string]: any; + [key: string]: Array; }>; }) ); diff --git a/src/app/api/models.ts b/src/app/api/models.ts index c3ee195..da05715 100644 --- a/src/app/api/models.ts +++ b/src/app/api/models.ts @@ -23,6 +23,7 @@ export type { Execution } from './models/execution'; export type { Extract } from './models/extract'; export type { Fhir } from './models/fhir'; export type { FieldSpec } from './models/field-spec'; +export type { FolderTrainingSource } from './models/folder-training-source'; export type { Group } from './models/group'; export type { Guided } from './models/guided'; export type { Health } from './models/health'; @@ -57,6 +58,7 @@ export type { Scope } from './models/scope'; export type { Score } from './models/score'; export type { SignIn } from './models/sign-in'; export type { Site } from './models/site'; +export type { SiteTrainingSource } from './models/site-training-source'; export type { Source } from './models/source'; export type { SourceRef } from './models/source-ref'; export type { SourceType } from './models/source-type'; diff --git a/src/app/api/models/folder-training-source.ts b/src/app/api/models/folder-training-source.ts new file mode 100644 index 0000000..4132452 --- /dev/null +++ b/src/app/api/models/folder-training-source.ts @@ -0,0 +1,12 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +export interface FolderTrainingSource { + + /** + * Carpeta dentro de TEA_REFERENCE_ROOT + */ + folder: string; + kind: 'folder'; + line_hz?: 50 | 60; +} diff --git a/src/app/api/models/site-training-source.ts b/src/app/api/models/site-training-source.ts new file mode 100644 index 0000000..7fdba4b --- /dev/null +++ b/src/app/api/models/site-training-source.ts @@ -0,0 +1,6 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +export interface SiteTrainingSource { + kind: 'site'; +} diff --git a/src/app/api/models/training-source.ts b/src/app/api/models/training-source.ts index 75bf6bc..0ba9583 100644 --- a/src/app/api/models/training-source.ts +++ b/src/app/api/models/training-source.ts @@ -1,16 +1,7 @@ /* eslint-disable */ /* Code generated by ng-openapi-gen DO NOT EDIT. */ -export interface TrainingSource { +import { FolderTrainingSource } from '../models/folder-training-source'; +import { SiteTrainingSource } from '../models/site-training-source'; +export type TrainingSource = (SiteTrainingSource | FolderTrainingSource); - /** - * Carpeta dentro de TEA_REFERENCE_ROOT - */ - folder?: (string | null); - - /** - * site: los niños del sitio sin el diagnóstico a la fecha de corte; folder: una carpeta de EDF con edades.csv (path, age en meses) - */ - kind?: 'site' | 'folder'; - line_hz?: 50 | 60; -} diff --git a/src/app/gobernanza/gobernanza.html b/src/app/gobernanza/gobernanza.html index 11281d9..84159eb 100644 --- a/src/app/gobernanza/gobernanza.html +++ b/src/app/gobernanza/gobernanza.html @@ -16,6 +16,7 @@ [domain]="domainKey()" [execution]="execution.execution()" (trainingRequested)="training.focus()" + (previewRequested)="showPreview.set(true)" /> - + @if (showPreview()) { + + } } diff --git a/src/app/gobernanza/gobernanza.ts b/src/app/gobernanza/gobernanza.ts index c1af590..e6987a6 100644 --- a/src/app/gobernanza/gobernanza.ts +++ b/src/app/gobernanza/gobernanza.ts @@ -1,4 +1,4 @@ -import { Component, computed, inject, input, resource } from '@angular/core'; +import { Component, computed, inject, input, linkedSignal, resource } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { RouterLink } from '@angular/router'; import { Api } from '../api/api'; @@ -30,6 +30,7 @@ import { Training } from './training'; export class Gobernanza { private readonly api = inject(Api); readonly domain = input.required(); + protected readonly showPreview = linkedSignal({ source: this.domain, computation: () => false }); protected readonly domainKey = computed(() => this.domain() as Domain); protected readonly labels = DOMAINS as Record; protected readonly domains = resource({ loader: () => this.api.invoke(domains) }); diff --git a/src/app/gobernanza/models.html b/src/app/gobernanza/models.html index 9da2bef..4060051 100644 --- a/src/app/gobernanza/models.html +++ b/src/app/gobernanza/models.html @@ -19,6 +19,9 @@ > Analizar EEG + } -
- - - @for (file of selectedFiles(); track $index) { - {{ file.name }} - } - -
@if (error()) {

{{ error() }}

} diff --git a/src/app/gobernanza/tea/studies.ts b/src/app/gobernanza/tea/studies.ts index 78f8098..0ad7f74 100644 --- a/src/app/gobernanza/tea/studies.ts +++ b/src/app/gobernanza/tea/studies.ts @@ -1,5 +1,4 @@ import { DatePipe, DecimalPipe, KeyValuePipe } from '@angular/common'; -import { HttpErrorResponse } from '@angular/common/http'; import { Component, inject, input, output, resource, signal } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { MatButtonModule } from '@angular/material/button'; @@ -11,9 +10,6 @@ import { analyzeEegs } from '../../api/fn/eeg/analyze-eegs'; import { eegStudiesSummary } from '../../api/fn/eeg/eeg-studies-summary'; import { studies } from '../../api/fn/eeg/studies'; import { study } from '../../api/fn/eeg/study'; -import { pipeline } from '../../api/fn/ingest/pipeline'; -import { startRun } from '../../api/fn/ingest/start-run'; -import { upload } from '../../api/fn/ingest/upload'; import { runHistory } from '../../api/fn/runs/run-history'; import type { Execution } from '../../api/models/execution'; import type { Scope } from '../../api/models/scope'; @@ -98,7 +94,6 @@ export class EegStudies { protected readonly mode = signal>('pending'); protected readonly count = signal(null); protected readonly ids = signal(''); - protected readonly selectedFiles = signal(null); protected readonly busy = signal(false); protected readonly error = signal(''); protected readonly runId = signal(''); @@ -118,47 +113,19 @@ export class EegStudies { scope.ids = this.ids().split(/\s+/).filter(Boolean); if (!scope.ids.length) return; } - await this.start(() => this.api.invoke(analyzeEegs, { body: { scope, execution } })); - } - - protected async upload(input: HTMLInputElement): Promise { - const files = Array.from(input.files ?? []); - if (!files.length) return; - if (files.some((file) => !file.name.toLowerCase().endsWith('.edf'))) { - this.error.set('Selecciona archivos EDF.'); - return; - } - await this.start(async () => { - try { - await this.api.invoke(pipeline, { pipeline_id: 'tea' }); - await this.api.invoke(upload, { body: { files: files as unknown as string[] } }); - const run = await this.api.invoke(startRun, { pipeline_id: 'tea', body: {} }); - input.value = ''; - this.selectedFiles.set(null); - return run; - } catch (error) { - if (error instanceof HttpErrorResponse && error.status === 404) { - throw new Error('No hay un pipeline TEA configurado'); - } - throw error; - } - }); - } - - protected finish(): void { - this.busy.set(false); - this.changed.emit(); - } - - private async start(submit: () => Promise<{ [key: string]: string }>): Promise { this.busy.set(true); this.error.set(''); try { - const { run_id } = await submit(); + const { run_id } = await this.api.invoke(analyzeEegs, { body: { scope, execution } }); this.runId.set(run_id); } catch (error) { this.error.set(errorText(error)); this.busy.set(false); } } + + protected finish(): void { + this.busy.set(false); + this.changed.emit(); + } } diff --git a/src/app/gobernanza/training.spec.ts b/src/app/gobernanza/training.spec.ts index bde7605..ede0b73 100644 --- a/src/app/gobernanza/training.spec.ts +++ b/src/app/gobernanza/training.spec.ts @@ -1,13 +1,13 @@ import { trainingForm } from './training'; describe('training form', () => { - it('removes execution and resolves the TEA training source with its defaults', () => { + it('builds the source selector from the folder fields and keeps the site payload minimal', () => { const { schema, model } = trainingForm({ name: 'all', domain: 'tea', defaults: { execution: { mode: 'local', scheduler: null }, - source: { kind: 'site', line_hz: 50 }, + source: { kind: 'site' }, }, json_schema: { type: 'object', @@ -18,10 +18,22 @@ describe('training form', () => { }, $defs: { TrainingSource: { + discriminator: { propertyName: 'kind' }, + oneOf: [ + { $ref: '#/$defs/SiteTrainingSource' }, + { $ref: '#/$defs/FolderTrainingSource' }, + ], + }, + SiteTrainingSource: { type: 'object', + properties: { kind: { type: 'string', const: 'site' } }, + }, + FolderTrainingSource: { + type: 'object', + required: ['kind', 'folder'], properties: { - kind: { type: 'string', enum: ['site', 'folder'], default: 'site' }, - folder: { anyOf: [{ type: 'string' }, { type: 'null' }] }, + kind: { type: 'string', const: 'folder' }, + folder: { type: 'string' }, line_hz: { type: 'integer', enum: [50, 60], default: 50 }, }, }, @@ -35,13 +47,14 @@ describe('training form', () => { format: 'date', }); expect(schema.properties?.['source']).toMatchObject({ - type: ['object', 'null'], + type: 'object', + required: ['kind', 'folder'], properties: { kind: { enum: ['site', 'folder'] }, - folder: { type: ['string', 'null'] }, + folder: { type: 'string' }, line_hz: { enum: [50, 60] }, }, }); - expect(model).toEqual({ source: { kind: 'site', line_hz: 50 } }); + expect(model).toEqual({ source: { kind: 'site' } }); }); }); diff --git a/src/app/gobernanza/training.ts b/src/app/gobernanza/training.ts index 9eb881e..cf0af87 100644 --- a/src/app/gobernanza/training.ts +++ b/src/app/gobernanza/training.ts @@ -28,23 +28,30 @@ import { uploadTrainingInputs } from '../api/fn/models/upload-training-inputs'; import type { Domain } from '../api/models/domain'; import type { Execution } from '../api/models/execution'; import type { TrainingConfig } from '../api/models/training-config'; +import type { TrainingSource } from '../api/models/training-source'; import { FORMLY_TYPES } from '../conectar/schema-form'; import { errorText } from './run-monitor'; type Schema = JSONSchema7 & { $defs?: Record }; -interface InputSets { - allowed: string[]; - description: string; - sets: { name: string; edf_files: number; has_ages: boolean }[]; -} - export function trainingForm(config: TrainingConfig) { const raw = structuredClone(config.json_schema) as Schema; const model = structuredClone(config.defaults); delete model['execution']; delete raw.properties?.['execution']; raw.required = raw.required?.filter((key) => key !== 'execution'); + if (raw.properties?.['source']) { + const folder = raw.$defs!['FolderTrainingSource']; + raw.properties['source'] = { + ...folder, + title: 'Datos de entrenamiento', + properties: { + kind: { type: 'string', title: 'Origen', enum: ['site', 'folder'] }, + folder: folder.properties!['folder'], + line_hz: folder.properties!['line_hz'], + }, + }; + } const normalize = (schema: Schema): Schema => { if (schema.$ref) return normalize(raw.$defs![schema.$ref.split('/').pop()!]); if (schema.anyOf) { @@ -89,6 +96,7 @@ function allowedFile(file: File, allowed: string[]): boolean { MatInputModule, ], providers: [provideFormlyCore([...withFormlyMaterial(), FORMLY_TYPES])], + styles: ':host { display: grid; gap: var(--space-4); }', template: `

Entrenamiento

@@ -115,33 +123,24 @@ function allowedFile(file: File, allowed: string[]): boolean { } @else if (config.error(); as error) {

{{ errorText(error) }}

} - @if (inputs.hasValue() && inputs.value(); as sets) { -

Archivos de entrenamiento

-

{{ sets.description }}

-
    - @for (set of sets.sets; track set.name) { -
  • - {{ set.name }} · {{ set.edf_files }} EDF · - {{ set.has_ages ? 'Con edades' : 'Sin edades' }} -
  • - } -
+ @if (message()) { +

{{ message() }}

+ } +
+ @if (inputs.hasValue() && inputs.value(); as metadata) { +
+

Subir archivos

Conjunto - + - - @for (set of sets.sets; track set.name) { - - } -
- } @else if (inputs.error(); as error) { -

{{ errorText(error) }}

- } - @if (message()) { -

{{ message() }}

- } -
+ @if (uploadMessage()) { +

{{ uploadMessage() }}

+ } + + } @else if (inputs.error(); as error) { +

{{ errorText(error) }}

+ } `, }) export class Training { @@ -197,6 +196,10 @@ export class Training { ], }; } + if (field.key === 'folder' || field.key === 'line_hz') { + field.expressions = { hide: (field) => field.model?.kind !== 'folder' }; + field.resetOnHide = false; + } if (field.key === 'line_hz') { field.type = 'select'; field.props = { @@ -218,7 +221,7 @@ export class Training { params: () => ({ domain: this.domain(), name: this.name() }), loader: async ({ params }) => { try { - return (await this.api.invoke(trainingInputs, params)) as InputSets; + return await this.api.invoke(trainingInputs, params); } catch (error) { if (error instanceof HttpErrorResponse && error.status === 404) return undefined; throw error; @@ -232,6 +235,7 @@ export class Training { }); protected readonly uploading = signal(false); protected readonly message = signal(''); + protected readonly uploadMessage = signal(''); protected readonly autoPromote = linkedSignal({ source: this.domain, computation: () => false }); protected readonly errorText = errorText; @@ -245,13 +249,14 @@ export class Training { this.message.set(''); const domain = this.domain(); const name = this.name(); + const source = model['source'] as TrainingSource | undefined; const autoPromote = domain === 'tea' && this.autoPromote(); try { const { run_id } = await this.api.invoke(train, { domain, body: { as_of: model['as_of'] || undefined, - source: model['source'] ?? undefined, + source: source?.kind === 'site' ? { kind: 'site' } : source, execution: this.execution(), ...(name === 'all' ? {} : { models: [name] }), }, @@ -276,11 +281,11 @@ export class Training { const files = Array.from(input.files ?? []); const allowed = this.inputs.hasValue() ? (this.inputs.value()?.allowed ?? []) : []; if (!files.length || files.some((file) => !allowedFile(file, allowed))) { - this.message.set('Archivos permitidos: ' + allowed.join(', ')); + this.uploadMessage.set('Archivos permitidos: ' + allowed.join(', ')); return; } this.uploading.set(true); - this.message.set(''); + this.uploadMessage.set(''); try { await this.api.invoke(uploadTrainingInputs, { domain: this.domain(), @@ -290,9 +295,8 @@ export class Training { }); input.value = ''; this.selectedFiles.set(null); - this.inputs.reload(); } catch (error) { - this.message.set(errorText(error)); + this.uploadMessage.set(errorText(error)); } finally { this.uploading.set(false); }