fix governance reqs; allow for sandboxed jupyter notebooks for testing
This commit is contained in:
@@ -2,6 +2,10 @@ import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import {
|
||||
CohortBuildFile,
|
||||
Experiment,
|
||||
ExperimentDetail,
|
||||
ExperimentRequest,
|
||||
ModelLineage,
|
||||
ModelVersion,
|
||||
PromotionCheck,
|
||||
@@ -12,7 +16,7 @@ import {
|
||||
OcrRunSummary,
|
||||
} from './governance.types';
|
||||
|
||||
/** `/governance/*`: model versions, artifacts, and the OCR review queue. */
|
||||
/** `/governance/*`: model versions and their files, notebooks run on a cohort build, and the OCR review queue. */
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class GovernanceApi {
|
||||
private readonly http = inject(HttpClient);
|
||||
@@ -44,13 +48,44 @@ export class GovernanceApi {
|
||||
return this.http.patch<ModelVersion>(`/governance/model-versions/${domain}/${scenario}/${version}/reports`, reports);
|
||||
}
|
||||
|
||||
/** Logs the file to the version's MLflow run. Browsing/downloading a
|
||||
* logged artifact goes through the MLflow tracking server directly. */
|
||||
uploadArtifact(domain: string, scenario: string, version: string, kind: string, file: File): Observable<ModelVersion> {
|
||||
/** Where a file the version's run stored downloads from; a folder comes as a zip. */
|
||||
artifactUrl(domain: string, scenario: string, version: string, path: string): string {
|
||||
return `/governance/model-versions/${domain}/${scenario}/${version}/artifacts/${encodePath(path)}`;
|
||||
}
|
||||
|
||||
/** The domain's cohort builds that have their file. */
|
||||
cohortFiles(domain: string): Observable<{ builds: CohortBuildFile[] }> {
|
||||
return this.http.get<{ builds: CohortBuildFile[] }>('/governance/cohort-files', { params: toParams({ domain }) });
|
||||
}
|
||||
|
||||
listExperiments(filters: { domain?: string; scenario?: string } = {}): Observable<{ experiments: Experiment[] }> {
|
||||
return this.http.get<{ experiments: Experiment[] }>('/governance/experiments', { params: toParams(filters) });
|
||||
}
|
||||
|
||||
/** Starts the notebook on the build in the background; answers with the run while it is still `en_curso`. */
|
||||
runExperiment(request: ExperimentRequest): Observable<ExperimentDetail> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
form.append('kind', kind);
|
||||
return this.http.post<ModelVersion>(`/governance/model-versions/${domain}/${scenario}/${version}/artifacts`, form);
|
||||
form.append('file', request.file);
|
||||
form.append('domain', request.domain);
|
||||
form.append('scenario', request.scenario);
|
||||
form.append('url', request.build.url);
|
||||
form.append('source', request.build.source);
|
||||
form.append('build', String(request.build.build));
|
||||
if (request.version) form.append('version', request.version);
|
||||
return this.http.post<ExperimentDetail>('/governance/experiments', form);
|
||||
}
|
||||
|
||||
getExperiment(runId: string): Observable<ExperimentDetail> {
|
||||
return this.http.get<ExperimentDetail>(`/governance/experiments/${runId}`);
|
||||
}
|
||||
|
||||
/** The rendered page, served sandboxed; opened in its own tab. */
|
||||
experimentPageUrl(runId: string): string {
|
||||
return `/governance/experiments/${runId}/page`;
|
||||
}
|
||||
|
||||
experimentArtifactUrl(runId: string, path: string): string {
|
||||
return `/governance/experiments/${runId}/artifacts/${encodePath(path)}`;
|
||||
}
|
||||
|
||||
listOcrJobs(): Observable<{ jobs: OcrJob[] }> {
|
||||
@@ -80,6 +115,10 @@ export class GovernanceApi {
|
||||
}
|
||||
}
|
||||
|
||||
function encodePath(path: string): string {
|
||||
return path.split('/').map(encodeURIComponent).join('/');
|
||||
}
|
||||
|
||||
function toParams(filters: Record<string, string | number | boolean | undefined>): HttpParams {
|
||||
let params = new HttpParams();
|
||||
for (const [key, value] of Object.entries(filters)) {
|
||||
|
||||
@@ -27,19 +27,66 @@ export interface PromotionCheck {
|
||||
detail: string;
|
||||
}
|
||||
|
||||
/** A logged artifact's path within the run, e.g. `ONNX_CHECKPOINT/model.onnx`
|
||||
* — browsing/downloading the file itself goes through MLflow directly. */
|
||||
export type ArtifactPath = string;
|
||||
/** A file a run stored, by its path within the run (`rutinas/MUESTREO.json`, `model/MLmodel`). */
|
||||
export interface ArtifactFile {
|
||||
path: string;
|
||||
size: number | null;
|
||||
}
|
||||
|
||||
/** The routines training records as it runs (ML-01a), each under its kind. */
|
||||
export type RoutineKind = 'MUESTREO' | 'DATOS_FALTANTES' | 'METODO_ANALITICO' | 'BALANCE_CLASES' | 'CONFIANZA_SALIDA';
|
||||
|
||||
export interface ModelLineage {
|
||||
model_version: ModelVersion;
|
||||
cohorte_armado: CohorteArmado | null;
|
||||
cohorte_exclusiones: CohorteExclusion[];
|
||||
artifacts: ArtifactPath[];
|
||||
artifacts: ArtifactFile[];
|
||||
/** What each routine did, as its run recorded it; a kind is missing when the run didn't record it. */
|
||||
routines: Partial<Record<RoutineKind, Record<string, unknown>>>;
|
||||
predictions: number;
|
||||
checks: PromotionCheck[];
|
||||
}
|
||||
|
||||
/** A cohort build that has its file, the data a notebook can run on. */
|
||||
export interface CohortBuildFile {
|
||||
url: string;
|
||||
source: 'kit' | 'dbt';
|
||||
build: number;
|
||||
datos_as_of: string | null;
|
||||
n_members: string | null;
|
||||
}
|
||||
|
||||
export type ExperimentStatus = 'en_curso' | 'terminado' | 'fallido' | 'interrumpido';
|
||||
|
||||
/** A notebook run on a cohort build, kept as an MLflow run. */
|
||||
export interface Experiment {
|
||||
run_id: string;
|
||||
notebook: string;
|
||||
domain: Domain;
|
||||
scenario: string;
|
||||
version: string | null;
|
||||
cohort: { url: string; source: string; build: string };
|
||||
notebook_sha256: string;
|
||||
/** Where it ran: `contenedor` (isolated: no network, no server files) or `local` (in the API's own process). */
|
||||
sandbox: 'contenedor' | 'local' | null;
|
||||
status: ExperimentStatus;
|
||||
started_at: string | null;
|
||||
ended_at: string | null;
|
||||
}
|
||||
|
||||
export interface ExperimentDetail extends Experiment {
|
||||
artifacts: ArtifactFile[];
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
export interface ExperimentRequest {
|
||||
file: File;
|
||||
domain: Domain;
|
||||
scenario: string;
|
||||
build: CohortBuildFile;
|
||||
version?: string | null;
|
||||
}
|
||||
|
||||
/** The indicator kit's cohort build the version was trained on. */
|
||||
export interface CohorteArmado {
|
||||
armado_id: number;
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<div class="experiments">
|
||||
<div class="experiments__toolbar">
|
||||
<mat-button-toggle-group hideSingleSelectionIndicator [value]="domain()" (change)="setDomain($event.value)" aria-label="Dominio">
|
||||
@for (option of domains; track option.id) {
|
||||
<mat-button-toggle [value]="option.id">{{ option.label }}</mat-button-toggle>
|
||||
}
|
||||
</mat-button-toggle-group>
|
||||
<span class="experiments__spacer"></span>
|
||||
<button mat-icon-button type="button" (click)="reload()" aria-label="Recargar" matTooltip="Recargar">
|
||||
<mat-icon aria-hidden="true">refresh</mat-icon>
|
||||
</button>
|
||||
<button mat-flat-button type="button" (click)="start()">
|
||||
<mat-icon aria-hidden="true">upload_file</mat-icon>Correr un notebook
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (loading()) {
|
||||
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
|
||||
}
|
||||
@if (loadError(); as error) {
|
||||
<p class="experiments__alert" role="alert"><mat-icon aria-hidden="true">error</mat-icon>{{ error }}</p>
|
||||
}
|
||||
|
||||
<table mat-table [dataSource]="experiments()" multiTemplateDataRows class="experiments__table">
|
||||
<ng-container matColumnDef="notebook">
|
||||
<th mat-header-cell *matHeaderCellDef>Notebook</th>
|
||||
<td mat-cell *matCellDef="let run">
|
||||
<div class="experiments__name">{{ run.notebook }}</div>
|
||||
@if (run.version) {
|
||||
<div class="experiments__muted">con la versión {{ run.version }}</div>
|
||||
}
|
||||
@if (run.sandbox === 'local') {
|
||||
<div class="experiments__warning" matTooltip="Corrió en el proceso de la API, sin contenedor aislado">
|
||||
<mat-icon aria-hidden="true">warning</mat-icon>Sin aislar
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="scenario">
|
||||
<th mat-header-cell *matHeaderCellDef>Dominio · escenario</th>
|
||||
<td mat-cell *matCellDef="let run">{{ run.domain }} · {{ run.scenario }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="cohort">
|
||||
<th mat-header-cell *matHeaderCellDef>Cohorte</th>
|
||||
<td mat-cell *matCellDef="let run">{{ run.cohort.url }} · {{ run.cohort.source }} {{ run.cohort.build }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="status">
|
||||
<th mat-header-cell *matHeaderCellDef>Estatus</th>
|
||||
<td mat-cell *matCellDef="let run">
|
||||
<span class="experiments__status" [class]="'experiments__status experiments__status--' + run.status">
|
||||
<mat-icon aria-hidden="true">{{ status(run.status).icon }}</mat-icon>{{ status(run.status).label }}
|
||||
</span>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="started_at">
|
||||
<th mat-header-cell *matHeaderCellDef>Inicio</th>
|
||||
<td mat-cell *matCellDef="let run">{{ run.started_at | date: 'short' }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="acciones">
|
||||
<th mat-header-cell *matHeaderCellDef></th>
|
||||
<td mat-cell *matCellDef="let run" class="experiments__actions">
|
||||
@if (run.status !== 'en_curso') {
|
||||
<a mat-button [href]="api.experimentPageUrl(run.run_id)" target="_blank" rel="noopener">
|
||||
<mat-icon aria-hidden="true">open_in_new</mat-icon>Ver resultados
|
||||
</a>
|
||||
}
|
||||
<button mat-icon-button type="button" (click)="toggle(run)" [attr.aria-expanded]="!!details()[run.run_id]"
|
||||
aria-label="Archivos de la corrida" matTooltip="Archivos de la corrida">
|
||||
<mat-icon aria-hidden="true">{{ details()[run.run_id] ? 'expand_less' : 'expand_more' }}</mat-icon>
|
||||
</button>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="detail">
|
||||
<td mat-cell *matCellDef="let run" [attr.colspan]="displayedColumns.length" class="experiments__detail">
|
||||
@if (details()[run.run_id]; as detail) {
|
||||
@if (detail.error) {
|
||||
<pre class="experiments__error">{{ detail.error }}</pre>
|
||||
}
|
||||
<ul class="experiments__files">
|
||||
@for (file of detail.artifacts; track file.path) {
|
||||
<li>
|
||||
<a [href]="api.experimentArtifactUrl(run.run_id, file.path)" download>
|
||||
<mat-icon aria-hidden="true">download</mat-icon>{{ file.path }}
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
<p class="experiments__muted">Huella del notebook {{ detail.notebook_sha256.slice(0, 12) }}…</p>
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: ['detail']" class="experiments__detail-row" [class.experiments__detail-row--open]="!!details()[row.run_id]"></tr>
|
||||
</table>
|
||||
|
||||
@if (!loading() && experiments().length === 0) {
|
||||
<p class="experiments__empty"><mat-icon aria-hidden="true">science</mat-icon>Aún no se ha corrido ningún notebook.</p>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,146 @@
|
||||
.experiments {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.experiments__toolbar {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.experiments__spacer {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.experiments__alert {
|
||||
align-items: center;
|
||||
background: var(--mat-sys-error-container);
|
||||
color: var(--mat-sys-on-error-container);
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
}
|
||||
|
||||
.experiments__table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.experiments__name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.experiments__muted {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-small);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.experiments__actions {
|
||||
text-align: end;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.experiments__status {
|
||||
align-items: center;
|
||||
border-radius: 999px;
|
||||
display: inline-flex;
|
||||
font: var(--mat-sys-label-medium);
|
||||
gap: 4px;
|
||||
padding: 2px 10px 2px 6px;
|
||||
|
||||
mat-icon {
|
||||
font-size: 16px;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.experiments__status--en_curso,
|
||||
.experiments__status--interrumpido {
|
||||
background: var(--mat-sys-surface-container-high);
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
}
|
||||
|
||||
.experiments__status--terminado {
|
||||
background: var(--mat-sys-primary-container);
|
||||
color: var(--mat-sys-on-primary-container);
|
||||
}
|
||||
|
||||
.experiments__status--fallido {
|
||||
background: var(--mat-sys-error-container);
|
||||
color: var(--mat-sys-on-error-container);
|
||||
}
|
||||
|
||||
.experiments__detail-row {
|
||||
height: 0;
|
||||
|
||||
td {
|
||||
border-bottom-width: 0;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.experiments__detail-row--open td {
|
||||
border-bottom-width: 1px;
|
||||
padding: var(--space-2) var(--space-3) var(--space-3);
|
||||
}
|
||||
|
||||
.experiments__error {
|
||||
background: var(--mat-sys-error-container);
|
||||
color: var(--mat-sys-on-error-container);
|
||||
font: var(--mat-sys-body-small);
|
||||
margin: 0 0 var(--space-2);
|
||||
max-height: 240px;
|
||||
overflow: auto;
|
||||
padding: var(--space-2);
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.experiments__files {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2) var(--space-4);
|
||||
list-style: none;
|
||||
margin: 0 0 var(--space-2);
|
||||
padding: 0;
|
||||
|
||||
a {
|
||||
align-items: center;
|
||||
display: inline-flex;
|
||||
gap: 4px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
mat-icon {
|
||||
font-size: 18px;
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.experiments__empty {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
display: flex;
|
||||
font: var(--mat-sys-body-small);
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.experiments__warning {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-error);
|
||||
display: inline-flex;
|
||||
font: var(--mat-sys-label-small);
|
||||
gap: 2px;
|
||||
|
||||
mat-icon {
|
||||
font-size: 14px;
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Component, DestroyRef, OnInit, inject, signal } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { Subscription, timer } from 'rxjs';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { DOMAINS } from '../../../connect/state/connect-workspace.store';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { Experiment, ExperimentDetail, ExperimentStatus } from '../../api/governance.types';
|
||||
import { NotebookRunDefaults, NotebookRunDialog } from '../notebook-run-dialog/notebook-run-dialog';
|
||||
|
||||
const STATUS: Record<ExperimentStatus, { label: string; icon: string }> = {
|
||||
en_curso: { label: 'En curso', icon: 'hourglass_top' },
|
||||
terminado: { label: 'Terminado', icon: 'check_circle' },
|
||||
fallido: { label: 'Falló', icon: 'error' },
|
||||
interrumpido: { label: 'Interrumpido', icon: 'block' },
|
||||
};
|
||||
const POLL_MS = 5000;
|
||||
|
||||
/**
|
||||
* Notebooks run on cohort builds: upload one, follow it while it runs, and
|
||||
* open its page or download its files. The list refreshes on its own while
|
||||
* a run is in progress.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-experiments-panel',
|
||||
imports: [DatePipe, MatButtonModule, MatButtonToggleModule, MatIconModule, MatProgressBarModule, MatTableModule, MatTooltipModule],
|
||||
templateUrl: './experiments-panel.html',
|
||||
styleUrl: './experiments-panel.scss',
|
||||
})
|
||||
export class ExperimentsPanel implements OnInit {
|
||||
readonly api = inject(GovernanceApi);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
readonly domains = [{ id: null, label: 'Todos' }, ...DOMAINS.map((d) => ({ id: d.id as string | null, label: d.label }))];
|
||||
readonly domain = signal<string | null>(null);
|
||||
readonly experiments = signal<Experiment[]>([]);
|
||||
readonly details = signal<Record<string, ExperimentDetail>>({});
|
||||
readonly loading = signal(false);
|
||||
readonly loadError = signal<string | null>(null);
|
||||
readonly displayedColumns = ['notebook', 'scenario', 'cohort', 'status', 'started_at', 'acciones'];
|
||||
private poll?: Subscription;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.reload();
|
||||
}
|
||||
|
||||
status(status: ExperimentStatus): { label: string; icon: string } {
|
||||
return STATUS[status] ?? { label: status, icon: 'help' };
|
||||
}
|
||||
|
||||
setDomain(domain: string | null): void {
|
||||
this.domain.set(domain);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
start(defaults: NotebookRunDefaults = {}): void {
|
||||
this.dialog
|
||||
.open<NotebookRunDialog, NotebookRunDefaults, ExperimentDetail>(NotebookRunDialog, {
|
||||
data: defaults,
|
||||
width: '640px',
|
||||
maxWidth: '96vw',
|
||||
autoFocus: false,
|
||||
})
|
||||
.afterClosed()
|
||||
.subscribe((run) => {
|
||||
if (run) this.reload();
|
||||
});
|
||||
}
|
||||
|
||||
/** Loads a run's files and error the first time it's expanded. */
|
||||
toggle(run: Experiment): void {
|
||||
const current = { ...this.details() };
|
||||
if (current[run.run_id]) {
|
||||
delete current[run.run_id];
|
||||
this.details.set(current);
|
||||
return;
|
||||
}
|
||||
this.api.getExperiment(run.run_id).subscribe((detail) => this.details.set({ ...this.details(), [run.run_id]: detail }));
|
||||
}
|
||||
|
||||
reload(quiet = false): void {
|
||||
if (!quiet) this.loading.set(true);
|
||||
this.loadError.set(null);
|
||||
this.api
|
||||
.listExperiments(this.domain() ? { domain: this.domain()! } : {})
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: ({ experiments }) => {
|
||||
this.loading.set(false);
|
||||
this.experiments.set(experiments);
|
||||
this.schedule(experiments.some((run) => run.status === 'en_curso'));
|
||||
},
|
||||
error: (error) => {
|
||||
this.loading.set(false);
|
||||
this.loadError.set(apiErrorMessage(error, 'No se pudieron cargar los notebooks.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private schedule(running: boolean): void {
|
||||
this.poll?.unsubscribe();
|
||||
if (!running) return;
|
||||
this.poll = timer(POLL_MS)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(() => this.reload(true));
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,11 @@
|
||||
<app-model-versions-panel></app-model-versions-panel>
|
||||
</div>
|
||||
</mat-tab>
|
||||
<mat-tab label="Notebooks">
|
||||
<div class="governance__panel">
|
||||
<app-experiments-panel></app-experiments-panel>
|
||||
</div>
|
||||
</mat-tab>
|
||||
<mat-tab label="Revisión de OCR">
|
||||
<div class="governance__panel">
|
||||
<app-ocr-review-panel></app-ocr-review-panel>
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { ExperimentsPanel } from '../experiments-panel/experiments-panel';
|
||||
import { ModelVersionsPanel } from '../model-versions-panel/model-versions-panel';
|
||||
import { OcrReviewPanel } from '../ocr-review-panel/ocr-review-panel';
|
||||
|
||||
/**
|
||||
* The "Gobernanza de modelos" page (route `/gobernanza`): model versions
|
||||
* and the OCR review queue, one tab each. Every tab is a
|
||||
* The "Gobernanza de modelos" page (route `/gobernanza`): model versions,
|
||||
* notebooks run on cohort builds and the OCR review queue, one tab each. Every tab is a
|
||||
* self-contained panel that loads its own data.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-governance-page',
|
||||
imports: [MatTabsModule, MatToolbarModule, ModelVersionsPanel, OcrReviewPanel],
|
||||
imports: [ExperimentsPanel, MatTabsModule, MatToolbarModule, ModelVersionsPanel, OcrReviewPanel],
|
||||
templateUrl: './governance-page.html',
|
||||
styleUrl: './governance-page.scss',
|
||||
})
|
||||
|
||||
@@ -81,33 +81,48 @@
|
||||
}
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="artifacts-title">
|
||||
<h3 id="artifacts-title">Artefactos</h3>
|
||||
<p class="muted">Guardados en la corrida de MLflow; ábrelos desde el servidor de MLflow.</p>
|
||||
<section aria-labelledby="routines-title">
|
||||
<h3 id="routines-title">Rutinas del entrenamiento</h3>
|
||||
<p class="muted">Lo que cada rutina hizo, registrado por la corrida mientras entrenaba (ML-01a).</p>
|
||||
<ul class="artifacts">
|
||||
@for (artifact of l.artifacts; track artifact) {
|
||||
@for (routine of routineKinds; track routine.kind) {
|
||||
@let record = l.routines[routine.kind];
|
||||
<li [class.checks__fail]="!record">
|
||||
<mat-icon aria-hidden="true">{{ record ? 'check_circle' : 'cancel' }}</mat-icon>
|
||||
<span class="artifacts__kind">{{ routine.label }}</span>
|
||||
@if (record) {
|
||||
<details class="routine">
|
||||
<summary>{{ record['method'] ?? 'Ver registro' }}</summary>
|
||||
<pre>{{ record | json }}</pre>
|
||||
</details>
|
||||
} @else {
|
||||
<span class="muted">La corrida no la registró.</span>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="artifacts-title">
|
||||
<h3 id="artifacts-title">Archivos de la corrida</h3>
|
||||
<ul class="artifacts">
|
||||
@for (file of files(l.artifacts); track file.path) {
|
||||
<li>
|
||||
<mat-icon aria-hidden="true">description</mat-icon>
|
||||
<span class="artifacts__kind">{{ artifactKindOf(artifact) }}</span>
|
||||
<span class="artifacts__name">{{ artifactName(artifact) }}</span>
|
||||
<a class="artifacts__name" [href]="artifactUrl(file.path)" download>{{ file.label }}</a>
|
||||
@if (file.size !== null) {
|
||||
<span class="muted">{{ file.size | number }} B</span>
|
||||
}
|
||||
</li>
|
||||
} @empty {
|
||||
<li class="muted">Sin artefactos.</li>
|
||||
<li class="muted">Sin archivos.</li>
|
||||
}
|
||||
</ul>
|
||||
<div class="upload">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Tipo</mat-label>
|
||||
<mat-select [value]="artifactKind()" (valueChange)="artifactKind.set($event)">
|
||||
@for (kind of artifactKinds; track kind.id) {
|
||||
<mat-option [value]="kind.id">{{ kind.label }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<button mat-stroked-button type="button" [disabled]="busy()" (click)="fileInput.click()">
|
||||
<mat-icon aria-hidden="true">upload_file</mat-icon>Subir artefacto
|
||||
<button mat-stroked-button type="button" (click)="tryInNotebook()">
|
||||
<mat-icon aria-hidden="true">science</mat-icon>Probar en un notebook
|
||||
</button>
|
||||
<input #fileInput type="file" hidden (change)="uploadArtifact($event)" />
|
||||
<span class="muted">Corre un notebook propio sobre una cohorte, con esta versión cargada.</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
.upload {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3);
|
||||
margin-top: var(--space-2);
|
||||
}
|
||||
@@ -126,3 +127,21 @@
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
||||
.routine {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
summary {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
pre {
|
||||
background: var(--mat-sys-surface-container);
|
||||
font: var(--mat-sys-body-small);
|
||||
margin: 4px 0 0;
|
||||
max-height: 240px;
|
||||
overflow: auto;
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,47 @@
|
||||
import { DatePipe, DecimalPipe } from '@angular/common';
|
||||
import { DatePipe, DecimalPipe, JsonPipe } 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 { MAT_DIALOG_DATA, MatDialog, 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 { ArtifactFile, ModelLineage, ModelVersion, PromotionCheck, RoutineKind } from '../../api/governance.types';
|
||||
import { ModelStatusChip } from '../model-status-chip/model-status-chip';
|
||||
import { NotebookRunDefaults, NotebookRunDialog } from '../notebook-run-dialog/notebook-run-dialog';
|
||||
|
||||
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' },
|
||||
/** The routines training records as it runs (ML-01a), in the order they happen. */
|
||||
export const ROUTINES: { kind: RoutineKind; label: string }[] = [
|
||||
{ kind: 'MUESTREO', label: 'Muestreo' },
|
||||
{ kind: 'DATOS_FALTANTES', label: 'Datos faltantes' },
|
||||
{ kind: 'METODO_ANALITICO', label: 'Método analítico' },
|
||||
{ kind: 'BALANCE_CLASES', label: 'Balance de clases' },
|
||||
{ kind: 'CONFIANZA_SALIDA', label: 'Confianza de la salida' },
|
||||
];
|
||||
|
||||
/**
|
||||
* One model version: what it was trained on (the kit's cohort build and its attrition),
|
||||
* 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.
|
||||
* what each routine did as it trained, the files its run stored, 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,
|
||||
JsonPipe,
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressBarModule,
|
||||
MatSelectModule,
|
||||
MatTooltipModule,
|
||||
ModelStatusChip,
|
||||
ReactiveFormsModule,
|
||||
@@ -54,8 +53,9 @@ export class ModelVersionDialog {
|
||||
private readonly api = inject(GovernanceApi);
|
||||
private readonly dialogRef = inject<MatDialogRef<ModelVersionDialog, boolean>>(MatDialogRef);
|
||||
private readonly version = inject<ModelVersion>(MAT_DIALOG_DATA);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
|
||||
readonly artifactKinds = ARTIFACT_KINDS;
|
||||
readonly routineKinds = ROUTINES;
|
||||
readonly lineage = signal<ModelLineage | null>(null);
|
||||
readonly busy = signal(false);
|
||||
readonly error = signal<string | null>(null);
|
||||
@@ -66,7 +66,6 @@ export class ModelVersionDialog {
|
||||
clinical_validation_report_uri: [''],
|
||||
interpretability_report_uri: [''],
|
||||
});
|
||||
readonly artifactKind = signal('ONNX_CHECKPOINT');
|
||||
|
||||
constructor() {
|
||||
this.load();
|
||||
@@ -93,12 +92,25 @@ export class ModelVersionDialog {
|
||||
return Object.entries(version.metrics ?? {});
|
||||
}
|
||||
|
||||
artifactName(path: string): string {
|
||||
return path.split('/').pop() ?? path;
|
||||
/** The run's files, with the saved model as one folder (it downloads as a zip). */
|
||||
files(artifacts: ArtifactFile[]): { path: string; label: string; size: number | null }[] {
|
||||
const model = artifacts.filter((file) => file.path.startsWith('model/'));
|
||||
const rest = artifacts.filter((file) => !file.path.startsWith('model/'));
|
||||
const folder = model.length ? [{ path: 'model', label: 'model (modelo guardado, .zip)', size: null }] : [];
|
||||
return [...folder, ...rest.map((file) => ({ ...file, label: file.path }))];
|
||||
}
|
||||
|
||||
artifactKindOf(path: string): string {
|
||||
return path.split('/')[0] ?? path;
|
||||
artifactUrl(path: string): string {
|
||||
return this.api.artifactUrl(this.domain, this.scenario, this.version.version, path);
|
||||
}
|
||||
|
||||
tryInNotebook(): void {
|
||||
this.dialog.open<NotebookRunDialog, NotebookRunDefaults>(NotebookRunDialog, {
|
||||
data: { domain: this.domain as NotebookRunDefaults['domain'], scenario: this.scenario, version: this.version.version },
|
||||
width: '640px',
|
||||
maxWidth: '96vw',
|
||||
autoFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
saveReports(): void {
|
||||
@@ -110,13 +122,6 @@ export class ModelVersionDialog {
|
||||
}));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<h2 mat-dialog-title>Correr un notebook</h2>
|
||||
|
||||
<mat-dialog-content class="content">
|
||||
<p class="hint">
|
||||
El notebook corre aislado en el servidor, sin red y con los datos de la cohorte que elija como única información: no
|
||||
ve las bases de datos ni los demás archivos. Dentro usa <code>from models.notebook import experiment</code> para leer
|
||||
la cohorte, cargar la versión elegida o entrenar; lo que entrene se registra como versión de desarrollo al terminar.
|
||||
La corrida guarda el notebook, la página con sus resultados y con qué datos se corrió.
|
||||
</p>
|
||||
|
||||
<div class="file">
|
||||
<button mat-stroked-button type="button" [disabled]="busy()" (click)="fileInput.click()">
|
||||
<mat-icon aria-hidden="true">upload_file</mat-icon>Elegir notebook
|
||||
</button>
|
||||
<span class="file__name">{{ file()?.name ?? 'Ningún archivo (.ipynb)' }}</span>
|
||||
<input #fileInput type="file" accept=".ipynb,application/x-ipynb+json" hidden (change)="pick($event)" />
|
||||
</div>
|
||||
|
||||
<div class="grid">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Dominio</mat-label>
|
||||
<mat-select [ngModel]="domain()" (ngModelChange)="setDomain($event)">
|
||||
@for (option of domains; track option.id) {
|
||||
<mat-option [value]="option.id">{{ option.label }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Escenario</mat-label>
|
||||
<input matInput [ngModel]="scenario()" (ngModelChange)="setScenario($event)" placeholder="cin2_logistic" />
|
||||
@if (scenario() && !scenarioValid()) {
|
||||
<mat-error>Solo letras, números, guion y guion bajo.</mat-error>
|
||||
} @else {
|
||||
<mat-hint>El de un modelo existente o uno nuevo para el experimento.</mat-hint>
|
||||
}
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="grid__wide">
|
||||
<mat-label>Cohorte</mat-label>
|
||||
<mat-select [ngModel]="build()" (ngModelChange)="build.set($event)" [compareWith]="sameBuild">
|
||||
@for (option of builds(); track option.url + option.source + option.build) {
|
||||
<mat-option [value]="option">{{ buildLabel(option) }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
@if (!builds().length) {
|
||||
<mat-hint>Este dominio no tiene cohortes exportadas a archivo.</mat-hint>
|
||||
}
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="grid__wide">
|
||||
<mat-label>Versión de modelo (opcional)</mat-label>
|
||||
<mat-select [ngModel]="version()" (ngModelChange)="version.set($event)">
|
||||
<mat-option value="">Ninguna</mat-option>
|
||||
@for (option of versions(); track option.version) {
|
||||
<mat-option [value]="option.version">{{ option.name }}:{{ option.version }} · {{ option.status }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
<mat-hint>El notebook la carga con <code>experiment().model()</code>.</mat-hint>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
@if (busy()) {
|
||||
<mat-progress-bar mode="indeterminate" aria-label="Iniciando"></mat-progress-bar>
|
||||
}
|
||||
@if (error(); as message) {
|
||||
<p class="alert" role="alert"><mat-icon aria-hidden="true">error</mat-icon>{{ message }}</p>
|
||||
}
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button type="button" mat-dialog-close>Cancelar</button>
|
||||
<button mat-flat-button type="button" [disabled]="!ready()" (click)="run()">
|
||||
<mat-icon aria-hidden="true">play_arrow</mat-icon>Correr
|
||||
</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,41 @@
|
||||
.content {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-medium);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.file {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.file__name {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-medium);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
}
|
||||
|
||||
.grid__wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.alert {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-error);
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { NotebookRunDialog } from './notebook-run-dialog';
|
||||
|
||||
/**
|
||||
* The dialog that uploads a notebook and runs it on a cohort build: it starts
|
||||
* from a version's defaults, offers the domain's exported builds, and sends
|
||||
* the build the person chose. The API is `HttpTestingController`; the dialog
|
||||
* reference is a stub that records how it closed.
|
||||
*/
|
||||
describe('NotebookRunDialog', () => {
|
||||
let http: HttpTestingController;
|
||||
const close = vi.fn();
|
||||
const build = { url: 'cacu/cohorte_vigilancia', source: 'dbt', build: 4, datos_as_of: '2025-12-31', n_members: '10' };
|
||||
|
||||
function open(data: object) {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [NotebookRunDialog],
|
||||
providers: [
|
||||
provideHttpClient(),
|
||||
provideHttpClientTesting(),
|
||||
{ provide: MAT_DIALOG_DATA, useValue: data },
|
||||
{ provide: MatDialogRef, useValue: { close } },
|
||||
],
|
||||
});
|
||||
http = TestBed.inject(HttpTestingController);
|
||||
const fixture = TestBed.createComponent(NotebookRunDialog);
|
||||
fixture.detectChanges();
|
||||
return fixture;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
http.verify();
|
||||
close.mockReset();
|
||||
});
|
||||
|
||||
it('sends the chosen build and version with the notebook, and closes with the run', () => {
|
||||
// Fails if the form stops carrying the build's url, source and number, or drops the version it was opened with.
|
||||
const fixture = open({ domain: 'cacu', scenario: 'cin2_logistic', version: '3' });
|
||||
http.expectOne((r) => r.url === '/governance/cohort-files' && r.params.get('domain') === 'cacu').flush({ builds: [build] });
|
||||
http.expectOne((r) => r.url === '/governance/model-versions').flush({ model_versions: [] });
|
||||
const dialog = fixture.componentInstance;
|
||||
expect(dialog.ready()).toBe(false);
|
||||
|
||||
dialog.file.set(new File(['{}'], 'analisis.ipynb'));
|
||||
expect(dialog.ready()).toBe(true);
|
||||
dialog.run();
|
||||
|
||||
const request = http.expectOne('/governance/experiments');
|
||||
const form = request.request.body as FormData;
|
||||
expect([form.get('url'), form.get('source'), form.get('build'), form.get('version')]).toEqual([
|
||||
'cacu/cohorte_vigilancia', 'dbt', '4', '3',
|
||||
]);
|
||||
request.flush({ run_id: 'r1', status: 'en_curso' });
|
||||
expect(close).toHaveBeenCalledWith(expect.objectContaining({ run_id: 'r1' }));
|
||||
});
|
||||
|
||||
it('refuses a scenario that the API would reject', () => {
|
||||
// Fails if `ready` stops checking the scenario's characters before uploading.
|
||||
const fixture = open({});
|
||||
http.expectOne((r) => r.url === '/governance/cohort-files').flush({ builds: [build] });
|
||||
const dialog = fixture.componentInstance;
|
||||
dialog.file.set(new File(['{}'], 'a.ipynb'));
|
||||
dialog.setScenario("x' OR 1=1");
|
||||
expect(dialog.ready()).toBe(false);
|
||||
dialog.setScenario('exploracion');
|
||||
http.expectOne((r) => r.url === '/governance/model-versions').flush({ model_versions: [] });
|
||||
expect(dialog.ready()).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,133 @@
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { FormsModule } 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 { Domain, apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { DOMAINS } from '../../../connect/state/connect-workspace.store';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { CohortBuildFile, ExperimentDetail, ModelVersion } from '../../api/governance.types';
|
||||
|
||||
/** What the dialog starts with: a version's dialog passes its own domain, scenario and version. */
|
||||
export interface NotebookRunDefaults {
|
||||
domain?: Domain;
|
||||
scenario?: string;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
const SCENARIO = /^[\w-]{1,100}$/;
|
||||
|
||||
/**
|
||||
* Uploads a Jupyter notebook and runs it on a cohort build's file, optionally
|
||||
* with a registered version to try. Closes with the run once it has started.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-notebook-run-dialog',
|
||||
imports: [
|
||||
FormsModule,
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressBarModule,
|
||||
MatSelectModule,
|
||||
],
|
||||
templateUrl: './notebook-run-dialog.html',
|
||||
styleUrl: './notebook-run-dialog.scss',
|
||||
})
|
||||
export class NotebookRunDialog {
|
||||
private readonly api = inject(GovernanceApi);
|
||||
private readonly dialogRef = inject<MatDialogRef<NotebookRunDialog, ExperimentDetail>>(MatDialogRef);
|
||||
private readonly defaults = inject<NotebookRunDefaults | null>(MAT_DIALOG_DATA, { optional: true }) ?? {};
|
||||
|
||||
readonly domains = DOMAINS;
|
||||
readonly domain = signal<Domain>(this.defaults.domain ?? 'cacu');
|
||||
readonly scenario = signal(this.defaults.scenario ?? '');
|
||||
readonly version = signal<string>(this.defaults.version ?? '');
|
||||
readonly file = signal<File | null>(null);
|
||||
readonly builds = signal<CohortBuildFile[]>([]);
|
||||
readonly build = signal<CohortBuildFile | null>(null);
|
||||
readonly versions = signal<ModelVersion[]>([]);
|
||||
readonly busy = signal(false);
|
||||
readonly error = signal<string | null>(null);
|
||||
|
||||
readonly scenarioValid = computed(() => SCENARIO.test(this.scenario()));
|
||||
readonly ready = computed(() => !!this.file() && !!this.build() && this.scenarioValid() && !this.busy());
|
||||
|
||||
constructor() {
|
||||
this.loadBuilds();
|
||||
this.loadVersions();
|
||||
}
|
||||
|
||||
buildLabel(build: CohortBuildFile): string {
|
||||
const members = build.n_members ? ` · ${build.n_members} miembros` : '';
|
||||
const asOf = build.datos_as_of ? ` · datos al ${build.datos_as_of}` : '';
|
||||
return `${build.url} · ${build.source} ${build.build}${members}${asOf}`;
|
||||
}
|
||||
|
||||
sameBuild(a: CohortBuildFile | null, b: CohortBuildFile | null): boolean {
|
||||
return !!a && !!b && a.url === b.url && a.source === b.source && a.build === b.build;
|
||||
}
|
||||
|
||||
setDomain(domain: Domain): void {
|
||||
this.domain.set(domain);
|
||||
this.version.set('');
|
||||
this.loadBuilds();
|
||||
this.loadVersions();
|
||||
}
|
||||
|
||||
setScenario(scenario: string): void {
|
||||
this.scenario.set(scenario.trim());
|
||||
this.version.set('');
|
||||
this.loadVersions();
|
||||
}
|
||||
|
||||
pick(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
this.file.set(input.files?.[0] ?? null);
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
run(): void {
|
||||
const file = this.file();
|
||||
const build = this.build();
|
||||
if (!file || !build || !this.ready()) return;
|
||||
this.busy.set(true);
|
||||
this.error.set(null);
|
||||
this.api
|
||||
.runExperiment({ file, domain: this.domain(), scenario: this.scenario(), build, version: this.version() || null })
|
||||
.subscribe({
|
||||
next: (run) => this.dialogRef.close(run),
|
||||
error: (error) => {
|
||||
this.busy.set(false);
|
||||
this.error.set(apiErrorMessage(error, 'No se pudo iniciar el notebook.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private loadBuilds(): void {
|
||||
this.builds.set([]);
|
||||
this.build.set(null);
|
||||
this.api.cohortFiles(this.domain()).subscribe({
|
||||
next: ({ builds }) => {
|
||||
this.builds.set(builds);
|
||||
this.build.set(builds[0] ?? null);
|
||||
},
|
||||
error: (error) => this.error.set(apiErrorMessage(error, 'No se pudieron cargar las cohortes exportadas.')),
|
||||
});
|
||||
}
|
||||
|
||||
private loadVersions(): void {
|
||||
this.versions.set([]);
|
||||
if (!this.scenarioValid()) return;
|
||||
this.api.listModelVersions({ domain: this.domain(), scenario: this.scenario() }).subscribe({
|
||||
next: ({ model_versions }) => this.versions.set(model_versions),
|
||||
error: () => this.versions.set([]),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user