Merge parity/F1a
This commit is contained in:
@@ -15,7 +15,7 @@ export interface TrainingInputs$Params {
|
||||
}
|
||||
|
||||
export function trainingInputs(http: HttpClient, rootUrl: string, params: TrainingInputs$Params, context?: HttpContext): Observable<StrictHttpResponse<{
|
||||
[key: string]: any;
|
||||
[key: string]: Array<string>;
|
||||
}>> {
|
||||
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<any> => r instanceof HttpResponse),
|
||||
map((r: HttpResponse<any>) => {
|
||||
return r as StrictHttpResponse<{
|
||||
[key: string]: any;
|
||||
[key: string]: Array<string>;
|
||||
}>;
|
||||
})
|
||||
);
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/* eslint-disable */
|
||||
/* Code generated by ng-openapi-gen DO NOT EDIT. */
|
||||
|
||||
export interface SiteTrainingSource {
|
||||
kind: 'site';
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
[domain]="domainKey()"
|
||||
[execution]="execution.execution()"
|
||||
(trainingRequested)="training.focus()"
|
||||
(previewRequested)="showPreview.set(true)"
|
||||
/>
|
||||
<app-governance-training
|
||||
#training
|
||||
@@ -38,7 +39,9 @@
|
||||
[refresh]="models.refreshed()"
|
||||
(changed)="models.refresh()"
|
||||
/>
|
||||
<app-eeg-preview />
|
||||
@if (showPreview()) {
|
||||
<app-eeg-preview />
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -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<string>();
|
||||
protected readonly showPreview = linkedSignal({ source: this.domain, computation: () => false });
|
||||
protected readonly domainKey = computed(() => this.domain() as Domain);
|
||||
protected readonly labels = DOMAINS as Record<string, string>;
|
||||
protected readonly domains = resource({ loader: () => this.api.invoke(domains) });
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
>
|
||||
Analizar EEG
|
||||
</button>
|
||||
<button mat-stroked-button type="button" (click)="previewRequested.emit()">
|
||||
Evaluar un solo estudio
|
||||
</button>
|
||||
}
|
||||
<button
|
||||
mat-stroked-button
|
||||
|
||||
@@ -87,6 +87,7 @@ export class Models {
|
||||
readonly domain = input.required<Domain>();
|
||||
readonly execution = input<Choice>();
|
||||
readonly trainingRequested = output<void>();
|
||||
readonly previewRequested = output<void>();
|
||||
protected readonly reportNames = REPORTS;
|
||||
protected readonly errorText = errorText;
|
||||
readonly refreshed = signal(0);
|
||||
|
||||
@@ -23,25 +23,6 @@
|
||||
}
|
||||
<button mat-flat-button type="submit" [disabled]="busy() || !execution()">Analizar</button>
|
||||
</form>
|
||||
<form (ngSubmit)="upload(files)">
|
||||
<input
|
||||
#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>
|
||||
@if (error()) {
|
||||
<p role="alert">{{ error() }}</p>
|
||||
}
|
||||
|
||||
@@ -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<NonNullable<Scope['mode']>>('pending');
|
||||
protected readonly count = signal<number | null>(null);
|
||||
protected readonly ids = signal('');
|
||||
protected readonly selectedFiles = signal<FileList | null>(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<void> {
|
||||
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<void> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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' } });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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<string, Schema> };
|
||||
|
||||
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: `
|
||||
<section class="card" aria-labelledby="training-heading">
|
||||
<h2 #heading id="training-heading" tabindex="-1">Entrenamiento</h2>
|
||||
@@ -115,33 +123,24 @@ function allowedFile(file: File, allowed: string[]): boolean {
|
||||
} @else if (config.error(); as error) {
|
||||
<p role="alert">{{ errorText(error) }}</p>
|
||||
}
|
||||
@if (inputs.hasValue() && inputs.value(); as sets) {
|
||||
<h4>Archivos de entrenamiento</h4>
|
||||
<p>{{ sets.description }}</p>
|
||||
<ul>
|
||||
@for (set of sets.sets; track set.name) {
|
||||
<li>
|
||||
{{ set.name }} · {{ set.edf_files }} EDF ·
|
||||
{{ set.has_ages ? 'Con edades' : 'Sin edades' }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@if (message()) {
|
||||
<p role="status">{{ message() }}</p>
|
||||
}
|
||||
</section>
|
||||
@if (inputs.hasValue() && inputs.value(); as metadata) {
|
||||
<section class="card" aria-labelledby="training-upload-heading">
|
||||
<h2 id="training-upload-heading">Subir archivos</h2>
|
||||
<form (ngSubmit)="upload(setName.value, files)">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Conjunto</mat-label>
|
||||
<input matInput #setName list="training-input-sets" required />
|
||||
<input matInput #setName required />
|
||||
</mat-form-field>
|
||||
<datalist id="training-input-sets">
|
||||
@for (set of sets.sets; track set.name) {
|
||||
<option [value]="set.name"></option>
|
||||
}
|
||||
</datalist>
|
||||
<input
|
||||
#files
|
||||
type="file"
|
||||
multiple
|
||||
required
|
||||
[accept]="accept(sets.allowed)"
|
||||
[accept]="accept(metadata.allowed)"
|
||||
hidden
|
||||
aria-label="Archivos"
|
||||
(change)="selectedFiles.set(files.files)"
|
||||
@@ -158,13 +157,13 @@ function allowedFile(file: File, allowed: string[]): boolean {
|
||||
Subir archivos
|
||||
</button>
|
||||
</form>
|
||||
} @else if (inputs.error(); as error) {
|
||||
<p role="alert">{{ errorText(error) }}</p>
|
||||
}
|
||||
@if (message()) {
|
||||
<p role="status">{{ message() }}</p>
|
||||
}
|
||||
</section>
|
||||
@if (uploadMessage()) {
|
||||
<p role="status">{{ uploadMessage() }}</p>
|
||||
}
|
||||
</section>
|
||||
} @else if (inputs.error(); as error) {
|
||||
<p role="alert">{{ errorText(error) }}</p>
|
||||
}
|
||||
`,
|
||||
})
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user