feat(indicadores): dashboard interactivo multidominio y seguimiento CaCu

This commit is contained in:
Angel Capetillo Zavala
2026-10-22 17:10:35 -06:00
parent 9cc67c0ef2
commit 1fe88dfb45
62 changed files with 4380 additions and 187 deletions
@@ -1,7 +1,7 @@
import { inject, Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { map } from 'rxjs';
import { Dominio, IndicadorDatos, FigureSelection, Indicador, parsePeriodos, PlotlyFigure, requireDominio } from './indicadores.models';
import { DatosScope, Dominio, IndicadorDatos, IndicadorMetadatos, FigureSelection, Indicador, parsePeriodos, PlotlyFigure, requireDominio } from './indicadores.models';
function record(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === 'object' && !Array.isArray(value);
@@ -15,6 +15,7 @@ export class IndicadoresService {
if (!Array.isArray(value) || !value.every(item => record(item)
&& typeof item['id'] === 'string' && item['id'].trim().length > 0 && typeof item['titulo'] === 'string'
&& typeof item['contrato'] === 'string' && Array.isArray(item['figuras'])
&& (item['version'] === undefined || typeof item['version'] === 'string')
&& item['figuras'].every((figure: unknown) => typeof figure === 'string' && figure.trim().length > 0)
&& new Set(item['figuras']).size === item['figuras'].length
&& Array.isArray(item['tipos_periodo']) && item['tipos_periodo'].length > 0
@@ -26,21 +27,44 @@ export class IndicadoresService {
return value as Indicador[];
}));
}
datos(dominio: Dominio, indicador: string, tipo: 'semestre' | 'mes', periodos?: string[]) {
metadatos(dominio: Dominio, indicador: string) {
return this.http.get<unknown>(`/${requireDominio(dominio)}/indicadores/${encodeURIComponent(indicador)}/metadatos`).pipe(map(value => {
if (!record(value)) throw new Error('Metadatos inválidos');
for (const field of ['referencias', 'poblaciones']) {
const list = value[field];
if (list !== undefined && (!Array.isArray(list) || !list.every(v => record(v) && (field === 'referencias'
? typeof v['tipo'] === 'string' && typeof v['etiqueta'] === 'string' && (v['ref'] === null || typeof v['ref'] === 'string')
: typeof v['grupo'] === 'string' && typeof v['codigo'] === 'string' && typeof v['descripcion'] === 'string')))) throw new Error('Metadatos inválidos');
}
return value as IndicadorMetadatos;
}));
}
datos(dominio: Dominio, indicador: string, tipo: 'semestre' | 'mes', periodos?: string[], scope: DatosScope = {}) {
const domain = requireDominio(dominio);
if (periodos && (!periodos.length || parsePeriodos(periodos.join(','), tipo) === null)) {
throw new Error('Periodos inválidos');
}
let params = new HttpParams();
if (scope.estrato) {
if (!['grupo_edad', 'estatus_seguimiento'].includes(scope.estrato)) throw new Error('Dimensión no admitida');
params = params.set('estrato', scope.estrato);
}
for (const filtro of scope.filtros ?? []) params = params.append('filtro', filtro);
if (periodos) params = params.set('periodos', [...new Set(periodos)].join(','));
return this.http.get<unknown>(`/${domain}/indicadores/${encodeURIComponent(indicador)}/datos`, { params }).pipe(map(value => {
if (!record(value) || value['id'] !== indicador || typeof value['contrato'] !== 'string'
|| !['mes', 'semestre'].includes(value['tipo_periodo'] as string)
|| value['tipo_periodo'] !== tipo
|| !Array.isArray(value['periodos']) || !value['periodos'].every(p => typeof p === 'string')
|| !Array.isArray(value['filas']) || !value['filas'].every(record)
|| (value['notas'] !== undefined && (!Array.isArray(value['notas']) || !value['notas'].every(n => typeof n === 'string')))) {
throw new Error('Respuesta de datos inválida');
}
const publishedPeriods = value['periodos'] as string[];
if ((value['estrato'] ?? undefined) !== scope.estrato) throw new Error('Dimensión recibida distinta de la solicitada');
if ((periodos && publishedPeriods.some(p => !periodos.includes(p)))
|| value['filas'].some(row => typeof row['periodo'] !== 'string' || !publishedPeriods.includes(row['periodo']))) {
throw new Error('Los datos recibidos no corresponden a los periodos solicitados');
}
return value as unknown as IndicadorDatos;
}));
}