feat(indicadores): habilitar dashboards Angular TEA CaCu y CaMa

This commit is contained in:
Angel Capetillo Zavala
2026-10-12 16:39:37 -06:00
parent a66205b725
commit b1c4b78f32
15 changed files with 5036 additions and 41 deletions
@@ -1,6 +1,7 @@
import { Component, DestroyRef, inject, signal } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
@@ -9,8 +10,9 @@ import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { catchError, map, of, startWith, Subject, switchMap } from 'rxjs';
import { FigureSelection, hasNoVisibleValues, Indicador, parsePeriodos, PlotlyFigure, Tema } from './indicadores.models';
import { Dominio, DOMINIOS, isDominio, TipoPeriodo, FigureSelection, hasNoVisibleValues, Indicador, parsePeriodos, PlotlyFigure, Tema } from './indicadores.models';
import { IndicadoresService } from './indicadores.service';
import { figureTitle, presentationFigure } from './indicadores.presentation';
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
export function httpMessage(error: unknown, catalog = false): string {
@@ -25,7 +27,7 @@ export function httpMessage(error: unknown, catalog = false): string {
const CONTRACT_INTERPRETATIONS: Readonly<Record<string, readonly string[]>> = {
C1: [
'El punto representa la proporción observada.',
'La línea vertical representa el intervalo de confianza Wilson al 95 %.',
'En las figuras TEA con intervalos calculados, la línea vertical representa el intervalo de confianza Wilson al 95 %. No se infieren intervalos cuando faltan.',
'Los intervalos amplios pueden deberse a denominadores pequeños.',
'Un porcentaje observado del 100 % no implica certeza poblacional.',
],
@@ -42,16 +44,21 @@ const CONTRACT_INTERPRETATIONS: Readonly<Record<string, readonly string[]>> = {
};
const UNKNOWN_INTERPRETATION = ['No hay una explicación específica disponible para este contrato. Consulta las notas de la figura; no se infiere su significado estadístico.'];
type FigureState = { status: 'idle' | 'loading' | 'ready' | 'error'; figure?: PlotlyFigure; message?: string };
type FigureState = { status: 'idle' | 'loading' | 'ready' | 'error'; figure?: PlotlyFigure; presentationFigure?: PlotlyFigure; message?: string };
@Component({
selector: 'app-indicadores-page',
imports: [FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatSelectModule, MatProgressBarModule, PlotlyChart],
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatSelectModule, MatProgressBarModule, PlotlyChart],
templateUrl: './indicadores-page.html',
styleUrl: './indicadores-page.scss',
})
export class IndicadoresPage {
private readonly service = inject(IndicadoresService);
private readonly destroyRef = inject(DestroyRef);
private readonly route = inject(ActivatedRoute, { optional: true });
readonly dominios = DOMINIOS;
dominio: Dominio = 'tea';
readonly domainLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'CaCu', cama: 'CaMa' };
tipoPeriodo: TipoPeriodo = 'semestre';
private readonly catalogRequests = new Subject<void>();
private readonly figureRequests = new Subject<FigureSelection | null>();
readonly catalog = signal<Indicador[]>([]);
@@ -59,6 +66,7 @@ export class IndicadoresPage {
readonly catalogError = signal('');
readonly result = signal<FigureState>({ status: 'idle' });
readonly hasNoVisibleValues = hasNoVisibleValues;
readonly figureTitle = figureTitle;
indicadorId = '';
figuraId = '';
periodMode: 'todos' | 'manual' = 'todos';
@@ -68,15 +76,30 @@ export class IndicadoresPage {
get selected(): Indicador | undefined { return this.catalog().find(item => item.id === this.indicadorId); }
get interpretation(): readonly string[] {
const contract = this.selected?.contrato;
const contract = this.figuraId.startsWith('fig_c1') ? 'C1'
: this.figuraId.startsWith('fig_c2') ? 'C2'
: this.figuraId.startsWith('fig_c3r') ? 'C3r' : this.selected?.contrato;
if (contract === 'C2' && this.dominio !== 'tea') return [
'Las barras muestran la composición porcentual de las categorías publicadas para cada periodo.',
'SIN_DATO, cuando aparece, es una categoría legítima de la representación.',
'Los valores nulos o suprimidos no representan porcentajes observados de 0 %.',
];
if (contract === 'C1' && this.dominio !== 'tea') return [
'Los puntos representan porcentajes observados; el eje horizontal muestra el periodo.',
'Estas figuras no entregan intervalos Wilson efectivos; no se interpretan sus barras como intervalos al 95 %.',
'Los puntos suprimidos no representan tasas observadas de 0 %. Consulta las notas del servicio.',
'Un porcentaje observado del 100 % no implica certeza poblacional.',
];
return contract && Object.hasOwn(CONTRACT_INTERPRETATIONS, contract)
? CONTRACT_INTERPRETATIONS[contract] : UNKNOWN_INTERPRETATION;
? [...CONTRACT_INTERPRETATIONS[contract], 'Los puntos suprimidos no representan tasas observadas de 0 %.'] : UNKNOWN_INTERPRETATION;
}
constructor() {
const initialDomain: unknown = this.route?.snapshot.data['dominio'];
if (isDominio(initialDomain)) this.dominio = initialDomain;
this.figureRequests.pipe(switchMap(selection => selection
? this.service.figura(selection).pipe(
map(figure => ({ status: 'ready', figure }) as FigureState),
map(figure => ({ status: 'ready', figure, presentationFigure: presentationFigure(figure, selection) }) as FigureState),
catchError(error => of({ status: 'error', message: httpMessage(error) } as FigureState)),
startWith({ status: 'loading' } as FigureState))
: of({ status: 'idle' } as FigureState)), takeUntilDestroyed(this.destroyRef))
@@ -86,8 +109,9 @@ export class IndicadoresPage {
this.catalogError.set('');
this.catalog.set([]);
this.indicadorId = this.figuraId = '';
this.resetPeriodos('semestre');
this.figureRequests.next(null);
return this.service.catalogo().pipe(map(items => ({ items, error: '' })),
return this.service.catalogo(this.dominio).pipe(map(items => ({ items, error: '' })),
catchError(error => of({ items: [] as Indicador[], error: httpMessage(error, true) })));
}), takeUntilDestroyed(this.destroyRef)).subscribe(({ items, error }) => {
this.catalogLoading.set(false);
@@ -96,10 +120,31 @@ export class IndicadoresPage {
if (items.length) this.selectIndicador(items[0].id);
});
}
changeDominio(dominio: Dominio) {
if (!isDominio(dominio) || dominio === this.dominio) return;
this.dominio = dominio;
this.catalogRequests.next();
}
private resetPeriodos(tipo: TipoPeriodo) {
this.tipoPeriodo = tipo;
this.periodText = this.periodError = '';
this.periodMode = 'todos';
}
changeTipoPeriodo(tipo: TipoPeriodo) {
if (!this.selected?.tipos_periodo.includes(tipo)) return;
this.resetPeriodos(tipo);
if (tipo !== this.selected.tipos_periodo[0]) this.periodMode = 'manual';
this.requestFigure();
}
get periodLabel(): string { return this.tipoPeriodo === 'mes' ? 'Meses (AAAA-MM)' : 'Semestres (AAAA-S1,AAAA-S2)'; }
retryCatalog() { this.catalogRequests.next(); }
selectIndicador(id: string) {
this.indicadorId = id;
this.figuraId = this.selected?.figuras[0] ?? '';
if (!this.selected?.tipos_periodo.includes(this.tipoPeriodo)
|| (this.periodMode === 'todos' && this.tipoPeriodo !== this.selected?.tipos_periodo[0])) {
this.resetPeriodos(this.selected?.tipos_periodo[0] ?? 'semestre');
}
this.requestFigure();
}
selectFigura(id: string) { this.figuraId = id; this.requestFigure(); }
@@ -108,12 +153,17 @@ export class IndicadoresPage {
changeTema(tema: Tema) { this.tema = tema; this.requestFigure(); }
requestFigure() {
this.periodError = '';
const periodos = this.periodMode === 'manual' ? parsePeriodos(this.periodText) : undefined;
if (periodos === null) this.periodError = 'Introduce semestres AAAA-S1 o AAAA-S2 separados por comas.';
if (!this.selected || !this.selected.figuras.includes(this.figuraId) || periodos === null) {
const periodos = this.periodMode === 'manual' ? parsePeriodos(this.periodText, this.tipoPeriodo) : undefined;
if (periodos === null) this.periodError = this.tipoPeriodo === 'mes'
? 'Introduce meses AAAA-MM del 01 al 12 separados por comas.'
: 'Introduce semestres AAAA-S1 o AAAA-S2 separados por comas.';
if (this.periodMode === 'todos' && this.tipoPeriodo !== this.selected?.tipos_periodo[0]) {
this.periodError = 'Selecciona periodos explícitos para este tipo; el servicio usa solo el primer tipo publicado al omitir periodos.';
}
if (!this.selected || !this.selected.figuras.includes(this.figuraId) || !this.selected.tipos_periodo.includes(this.tipoPeriodo) || periodos === null || !!this.periodError) {
this.figureRequests.next(null);
return;
}
this.figureRequests.next({ indicador: this.indicadorId, figura: this.figuraId, tema: this.tema, periodos });
this.figureRequests.next({ dominio: this.dominio, tipoPeriodo: this.tipoPeriodo, indicador: this.indicadorId, figura: this.figuraId, tema: this.tema, periodos });
}
}