T3: training form edits the training source; kind and mains as selects
This commit is contained in:
@@ -1,24 +1,27 @@
|
|||||||
import { trainingForm } from './training';
|
import { trainingForm } from './training';
|
||||||
|
|
||||||
describe('training form', () => {
|
describe('training form', () => {
|
||||||
it('removes execution and resolves the TEA reference fields with their defaults', () => {
|
it('removes execution and resolves the TEA training source with its defaults', () => {
|
||||||
const { schema, model } = trainingForm({
|
const { schema, model } = trainingForm({
|
||||||
name: 'all',
|
name: 'all',
|
||||||
domain: 'tea',
|
domain: 'tea',
|
||||||
defaults: { execution: { mode: 'local', scheduler: null }, reference: { line_hz: 50 } },
|
defaults: {
|
||||||
|
execution: { mode: 'local', scheduler: null },
|
||||||
|
source: { kind: 'site', line_hz: 50 },
|
||||||
|
},
|
||||||
json_schema: {
|
json_schema: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
execution: { type: 'object' },
|
execution: { type: 'object' },
|
||||||
as_of: { anyOf: [{ type: 'string', format: 'date' }, { type: 'null' }] },
|
as_of: { anyOf: [{ type: 'string', format: 'date' }, { type: 'null' }] },
|
||||||
reference: { anyOf: [{ $ref: '#/$defs/Reference' }, { type: 'null' }] },
|
source: { anyOf: [{ $ref: '#/$defs/TrainingSource' }, { type: 'null' }] },
|
||||||
},
|
},
|
||||||
$defs: {
|
$defs: {
|
||||||
Reference: {
|
TrainingSource: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['name'],
|
|
||||||
properties: {
|
properties: {
|
||||||
name: { type: 'string' },
|
kind: { type: 'string', enum: ['site', 'folder'], default: 'site' },
|
||||||
|
folder: { anyOf: [{ type: 'string' }, { type: 'null' }] },
|
||||||
line_hz: { type: 'integer', enum: [50, 60], default: 50 },
|
line_hz: { type: 'integer', enum: [50, 60], default: 50 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -31,10 +34,14 @@ describe('training form', () => {
|
|||||||
type: ['string', 'null'],
|
type: ['string', 'null'],
|
||||||
format: 'date',
|
format: 'date',
|
||||||
});
|
});
|
||||||
expect(schema.properties?.['reference']).toMatchObject({
|
expect(schema.properties?.['source']).toMatchObject({
|
||||||
type: ['object', 'null'],
|
type: ['object', 'null'],
|
||||||
properties: { name: { type: 'string' }, line_hz: { enum: [50, 60] } },
|
properties: {
|
||||||
|
kind: { enum: ['site', 'folder'] },
|
||||||
|
folder: { type: ['string', 'null'] },
|
||||||
|
line_hz: { enum: [50, 60] },
|
||||||
|
},
|
||||||
});
|
});
|
||||||
expect(model).toEqual({ reference: { line_hz: 50 } });
|
expect(model).toEqual({ source: { kind: 'site', line_hz: 50 } });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -53,10 +53,7 @@ export function trainingForm(config: TrainingConfig) {
|
|||||||
}
|
}
|
||||||
return schema;
|
return schema;
|
||||||
};
|
};
|
||||||
const schema = normalize(raw);
|
return { schema: normalize(raw), model };
|
||||||
const reference = schema.properties?.['reference'] as Schema | undefined;
|
|
||||||
if (reference) reference.required = reference.required?.filter((key) => key !== 'name');
|
|
||||||
return { schema, model };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function allowedFile(file: File, allowed: string[]): boolean {
|
function allowedFile(file: File, allowed: string[]): boolean {
|
||||||
@@ -148,6 +145,16 @@ export class Training {
|
|||||||
if (source.format === 'date') {
|
if (source.format === 'date') {
|
||||||
field.props = { ...field.props, type: 'date' };
|
field.props = { ...field.props, type: 'date' };
|
||||||
}
|
}
|
||||||
|
if (field.key === 'kind') {
|
||||||
|
field.type = 'select';
|
||||||
|
field.props = {
|
||||||
|
...field.props,
|
||||||
|
options: [
|
||||||
|
{ value: 'site', label: 'Niños del sitio sin el diagnóstico' },
|
||||||
|
{ value: 'folder', label: 'Carpeta de EDF con edades' },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
if (field.key === 'line_hz') {
|
if (field.key === 'line_hz') {
|
||||||
field.type = 'select';
|
field.type = 'select';
|
||||||
field.props = {
|
field.props = {
|
||||||
@@ -189,13 +196,12 @@ export class Training {
|
|||||||
const domain = this.domain();
|
const domain = this.domain();
|
||||||
const name = this.name();
|
const name = this.name();
|
||||||
const autoPromote = domain === 'tea' && this.autoPromote();
|
const autoPromote = domain === 'tea' && this.autoPromote();
|
||||||
const reference = model['reference'];
|
|
||||||
try {
|
try {
|
||||||
const { run_id } = await this.api.invoke(train, {
|
const { run_id } = await this.api.invoke(train, {
|
||||||
domain,
|
domain,
|
||||||
body: {
|
body: {
|
||||||
as_of: model['as_of'] || undefined,
|
as_of: model['as_of'] || undefined,
|
||||||
reference: reference?.name ? reference : undefined,
|
source: model['source'] ?? undefined,
|
||||||
execution: this.execution(),
|
execution: this.execution(),
|
||||||
...(name === 'all' ? {} : { models: [name] }),
|
...(name === 'all' ? {} : { models: [name] }),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user