integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
import { DatePipe, DecimalPipe } from '@angular/common';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { Observable } from 'rxjs';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { ModelLineage, ModelVersion, PromotionCheck } from '../../api/governance.types';
|
||||
import { ModelStatusChip } from '../model-status-chip/model-status-chip';
|
||||
|
||||
export const ARTIFACT_KINDS: { id: string; label: string }[] = [
|
||||
{ id: 'ONNX_CHECKPOINT', label: 'Checkpoint ONNX' },
|
||||
{ id: 'MUESTREO', label: 'Muestreo' },
|
||||
{ id: 'DATOS_FALTANTES', label: 'Datos faltantes' },
|
||||
{ id: 'METODO_ANALITICO', label: 'Método analítico' },
|
||||
{ id: 'BALANCE_CLASES', label: 'Balance de clases' },
|
||||
{ id: 'CONFIANZA_SALIDA', label: 'Confianza de la salida' },
|
||||
{ id: 'OTRO', label: 'Otro' },
|
||||
];
|
||||
|
||||
/**
|
||||
* One model version: what it was trained on (cohort hash and exclusions),
|
||||
* its artifacts and their integrity, its validation reports, and the
|
||||
* checklist that must pass before it can serve predictions. Closes with
|
||||
* `true` when the version changed.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-model-version-dialog',
|
||||
imports: [
|
||||
DatePipe,
|
||||
DecimalPipe,
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressBarModule,
|
||||
MatSelectModule,
|
||||
MatTooltipModule,
|
||||
ModelStatusChip,
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
templateUrl: './model-version-dialog.html',
|
||||
styleUrl: './model-version-dialog.scss',
|
||||
})
|
||||
export class ModelVersionDialog {
|
||||
private readonly api = inject(GovernanceApi);
|
||||
private readonly dialogRef = inject<MatDialogRef<ModelVersionDialog, boolean>>(MatDialogRef);
|
||||
private readonly version = inject<ModelVersion>(MAT_DIALOG_DATA);
|
||||
|
||||
readonly artifactKinds = ARTIFACT_KINDS;
|
||||
readonly lineage = signal<ModelLineage | null>(null);
|
||||
readonly busy = signal(false);
|
||||
readonly error = signal<string | null>(null);
|
||||
private changed = false;
|
||||
|
||||
readonly reports = inject(FormBuilder).nonNullable.group({
|
||||
technical_validation_report_uri: [''],
|
||||
clinical_validation_report_uri: [''],
|
||||
interpretability_report_uri: [''],
|
||||
});
|
||||
readonly artifactKind = signal('ONNX_CHECKPOINT');
|
||||
|
||||
constructor() {
|
||||
this.load();
|
||||
}
|
||||
|
||||
private get domain(): string {
|
||||
return this.version.tags.domain!;
|
||||
}
|
||||
|
||||
private get scenario(): string {
|
||||
return this.version.tags.scenario!;
|
||||
}
|
||||
|
||||
get title(): string {
|
||||
const v = this.lineage()?.model_version ?? this.version;
|
||||
return `${v.name}:${v.version}`;
|
||||
}
|
||||
|
||||
ready(checks: PromotionCheck[]): boolean {
|
||||
return checks.every((check) => check.passed);
|
||||
}
|
||||
|
||||
metrics(version: ModelVersion): [string, unknown][] {
|
||||
return Object.entries(version.metrics ?? {});
|
||||
}
|
||||
|
||||
artifactName(path: string): string {
|
||||
return path.split('/').pop() ?? path;
|
||||
}
|
||||
|
||||
artifactKindOf(path: string): string {
|
||||
return path.split('/')[0] ?? path;
|
||||
}
|
||||
|
||||
saveReports(): void {
|
||||
const values = this.reports.getRawValue();
|
||||
this.run(this.api.attachReports(this.domain, this.scenario, this.version.version, {
|
||||
technical_validation_report_uri: values.technical_validation_report_uri.trim() || null,
|
||||
clinical_validation_report_uri: values.clinical_validation_report_uri.trim() || null,
|
||||
interpretability_report_uri: values.interpretability_report_uri.trim() || null,
|
||||
}));
|
||||
}
|
||||
|
||||
uploadArtifact(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (file) this.run(this.api.uploadArtifact(this.domain, this.scenario, this.version.version, this.artifactKind(), file));
|
||||
}
|
||||
|
||||
promote(): void {
|
||||
this.run(this.api.promoteModelVersion(this.domain, this.scenario, this.version.version));
|
||||
}
|
||||
|
||||
retire(): void {
|
||||
this.run(this.api.retireModelVersion(this.domain, this.scenario, this.version.version));
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.dialogRef.close(this.changed);
|
||||
}
|
||||
|
||||
private run(request: Observable<unknown>): void {
|
||||
this.busy.set(true);
|
||||
this.error.set(null);
|
||||
request.subscribe({
|
||||
next: () => {
|
||||
this.changed = true;
|
||||
this.load();
|
||||
},
|
||||
error: (error) => {
|
||||
this.busy.set(false);
|
||||
this.error.set(apiErrorMessage(error, 'La operación no se pudo completar.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private load(): void {
|
||||
this.busy.set(true);
|
||||
this.api.lineage(this.domain, this.scenario, this.version.version).subscribe({
|
||||
next: (lineage) => {
|
||||
this.lineage.set(lineage);
|
||||
const tags = lineage.model_version.tags;
|
||||
this.reports.setValue({
|
||||
technical_validation_report_uri: tags.technical_validation_report_uri ?? '',
|
||||
clinical_validation_report_uri: tags.clinical_validation_report_uri ?? '',
|
||||
interpretability_report_uri: tags.interpretability_report_uri ?? '',
|
||||
});
|
||||
this.reports.markAsPristine();
|
||||
this.busy.set(false);
|
||||
},
|
||||
error: (error) => {
|
||||
this.busy.set(false);
|
||||
this.error.set(apiErrorMessage(error, 'No se pudo cargar la versión.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user