Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fff2765810 | |||
| 9852e397da | |||
| 615f63cb7c | |||
| dcdcc34c46 | |||
| 0ee2916e1c | |||
| 72c4b38593 | |||
| 37a7a102f2 | |||
| 2d0bb8eed3 | |||
| b8253dda56 | |||
| 0f10a36f0d | |||
| 0d74f3a513 | |||
| 5b1dd30356 | |||
| 50d53c86fd | |||
| 73fcccea80 | |||
| ba583b6391 | |||
| 705b356f3f | |||
| aabdfa4013 | |||
| 0079f38446 | |||
| 9e92e25813 | |||
| 46c66406df | |||
| a2727f06ad | |||
| b660c77191 | |||
| a15ca94564 | |||
| 6eec071f3a | |||
| 9c0bff0cfe | |||
| 8bc0b06e7b | |||
| 830d978a1b | |||
| b89b630c2e | |||
| fecb0247d1 |
@@ -11,7 +11,7 @@ WebApi/
|
|||||||
├── main.py crea la app y la levanta en 0.0.0.0:5000
|
├── main.py crea la app y la levanta en 0.0.0.0:5000
|
||||||
├── webapi/
|
├── webapi/
|
||||||
│ ├── __init__.py create_app(): /health y los tres blueprints
|
│ ├── __init__.py create_app(): /health y los tres blueprints
|
||||||
│ ├── indicadores.py rutas de indicadores y figuras, comunes a los tres proyectos
|
│ ├── indicadores.py rutas de indicadores, datos y figuras, comunes a los tres proyectos
|
||||||
│ └── blueprints/
|
│ └── blueprints/
|
||||||
│ ├── cacu.py cacu_bp, prefijo /cacu
|
│ ├── cacu.py cacu_bp, prefijo /cacu
|
||||||
│ ├── cama.py cama_bp, prefijo /cama
|
│ ├── cama.py cama_bp, prefijo /cama
|
||||||
@@ -21,7 +21,7 @@ WebApi/
|
|||||||
│ ├── test_app.py /health y rutas de CaCu, con SQLite temporal
|
│ ├── test_app.py /health y rutas de CaCu, con SQLite temporal
|
||||||
│ ├── test_cacu.py indicadores de CaCu, con SQLite temporal
|
│ ├── test_cacu.py indicadores de CaCu, con SQLite temporal
|
||||||
│ ├── test_cama.py indicadores de CaMa, con SQLite temporal
|
│ ├── test_cama.py indicadores de CaMa, con SQLite temporal
|
||||||
│ └── test_tea.py rutas de TEA, con SQLite temporal y 18 indicadores
|
│ └── test_tea.py rutas de TEA, con SQLite temporal y sus 5 indicadores
|
||||||
├── Dockerfile imagen; el contexto es la raíz del repo padre
|
├── Dockerfile imagen; el contexto es la raíz del repo padre
|
||||||
└── docker-entrypoint.sh migra las tres bases y arranca main.py
|
└── docker-entrypoint.sh migra las tres bases y arranca main.py
|
||||||
```
|
```
|
||||||
@@ -29,7 +29,8 @@ WebApi/
|
|||||||
Un blueprint por dominio, con rutas de ejemplo (paciente y `predict`).
|
Un blueprint por dominio, con rutas de ejemplo (paciente y `predict`).
|
||||||
Los tres sirven además los indicadores del kit: cada blueprint llama a
|
Los tres sirven además los indicadores del kit: cada blueprint llama a
|
||||||
`registrar_indicadores(blueprint, proyecto, get_<proyecto>_session)` de
|
`registrar_indicadores(blueprint, proyecto, get_<proyecto>_session)` de
|
||||||
`webapi/indicadores.py`, que agrega `/indicadores` y las figuras.
|
`webapi/indicadores.py`, que agrega el catálogo, los periodos, los datos,
|
||||||
|
los metadatos y las figuras.
|
||||||
|
|
||||||
## Flujo de datos
|
## Flujo de datos
|
||||||
|
|
||||||
@@ -49,15 +50,31 @@ GET /<proyecto>/indicadores/<id>/figuras/<figura>?periodos=&tema=
|
|||||||
├─ valida indicador y figura (404 si no existen; figuras_de(medida))
|
├─ valida indicador y figura (404 si no existen; figuras_de(medida))
|
||||||
├─ valida tema y periodos (400 si están mal)
|
├─ valida tema y periodos (400 si están mal)
|
||||||
├─ sesion = get_<proyecto>_session()
|
├─ sesion = get_<proyecto>_session()
|
||||||
├─ sin periodos: periodos_con_reporte(..., tipo=<primer tipo que publica>)
|
├─ sin periodos: periodos_por_defecto(...): los del primer tipo que publica;
|
||||||
├─ figura_json(sesion, medida, periodos, figura, tablas=tablas, tema=tema)
|
│ en una figura de un solo periodo (donas, barras), solo el más reciente
|
||||||
│ (indicadores_kit lee measure_report y arma el JSON de Plotly)
|
│ con algo que dibujar
|
||||||
|
├─ figura_json(sesion, medida, periodos, figura, tablas=tablas, tema=tema, filtros=filtros)
|
||||||
|
│ indicadores_kit (serving/contratos.py):
|
||||||
|
│ 1. el reporte vigente de cada periodo, de la vista v_measure_report_vigente
|
||||||
|
│ 2. las celdas del total, de la vista de su contrato: v_c1, v_c2 o v_c3r
|
||||||
|
│ (con ?filtro=, la misma consulta con solo esas unidades, no la vista)
|
||||||
|
│ 3. etiquetas, colores y pie, de def_parametro; y arma el JSON de Plotly
|
||||||
└─ finally: sesion.close()
|
└─ finally: sesion.close()
|
||||||
│
|
│
|
||||||
v
|
v
|
||||||
Response(texto, mimetype="application/json")
|
Response(texto, mimetype="application/json")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Las rutas de datos, periodos y metadatos siguen los mismos pasos, con
|
||||||
|
`datos_de`, `periodos_de` y `metadatos_de` de
|
||||||
|
`indicadores_kit.serving.datos` en lugar de `figura_json`.
|
||||||
|
|
||||||
|
Ninguna ruta lee `measure_report_unidad` directamente ni calcula: los números
|
||||||
|
ya salen agregados y suprimidos de las vistas. Las vistas las crea la arista
|
||||||
|
`vistas` de `Orquestacion` (`indicadores_kit/esquema.py: ddl_de_vistas`), no la
|
||||||
|
migración: una base solo migrada no las tiene, y una base calculada antes de
|
||||||
|
MD-19 no tiene unidades. En los dos casos hay que correr el ciclo (camino B).
|
||||||
|
|
||||||
La sesión se cierra siempre, en `finally`. Un `KeyError` interno no se
|
La sesión se cierra siempre, en `finally`. Un `KeyError` interno no se
|
||||||
convierte en 404: sube como error 500. Un `LookupError` (periodo sin
|
convierte en 404: sube como error 500. Un `LookupError` (periodo sin
|
||||||
reporte) sí da 404.
|
reporte) sí da 404.
|
||||||
@@ -105,8 +122,8 @@ La API solo lee. Antes de pedir una figura, la base de TEA necesita las
|
|||||||
tablas, los datos y los reportes calculados. Hay dos caminos.
|
tablas, los datos y los reportes calculados. Hay dos caminos.
|
||||||
|
|
||||||
**A. Base de demostración (datos sintéticos del kit).** Una sola orden
|
**A. Base de demostración (datos sintéticos del kit).** Una sola orden
|
||||||
crea las tablas, carga el staging sintético y calcula los 18 indicadores
|
crea las tablas, llena las tablas fuente con datos sintéticos y calcula los 5
|
||||||
en `2025-S1` y `2025-S2`. Necesita un archivo nuevo o vacío; no corra
|
indicadores en `2025-S1` y `2025-S2`. Necesita un archivo nuevo o vacío; no corra
|
||||||
`alembic` antes en ese archivo.
|
`alembic` antes en ese archivo.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -116,41 +133,21 @@ uv run python -c "import os; from sqlalchemy import create_engine; from indicado
|
|||||||
uv run python main.py # http://localhost:5000
|
uv run python main.py # http://localhost:5000
|
||||||
```
|
```
|
||||||
|
|
||||||
**B. Datos reales.** Con la misma `TEA_DATABASE_URL` en todos los pasos:
|
**B. Datos reales.** La base del dominio (tablas fuente, plata, reportes y
|
||||||
|
vistas) la monta `Orquestacion`, con la misma `<PROYECTO>_DATABASE_URL`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd Persistance
|
cd Orquestacion
|
||||||
uv run alembic -c persistance/tea/alembic.ini upgrade head # tablas
|
# ... con las tablas fuente de TEA ya llenas (pacientes, evaluacion_psicologica, eeg_estudio, ...)
|
||||||
# ... llene las tablas de staging de TEA (pacientes, evaluacion_psicologica, eeg_estudio, ...)
|
TEA_DATABASE_URL=sqlite:////ruta/tea.db uv run --frozen python -m orquestacion ciclo tea --desde 2024 --hasta 2026
|
||||||
cd ../WebApi
|
cd ../WebApi
|
||||||
uv run python -m indicadores_kit.tea.etl # staging -> hechos del kit
|
TEA_DATABASE_URL=sqlite:////ruta/tea.db uv run python main.py # http://localhost:5000
|
||||||
uv run python -m indicadores_kit.correr tea K01_evaluacion_3_meses 2025-S1 2025-S2
|
|
||||||
# repita `correr` por cada indicador (ids en /tea/indicadores)
|
|
||||||
uv run python main.py # http://localhost:5000
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Cada `correr` agrega un reporte; no borra los anteriores.
|
Volver a correr el ciclo no duplica cargas ni reportes. CaCu y CaMa, igual
|
||||||
|
(`ciclo cacu`, `ciclo cama`): el ciclo registra los semestres y los meses
|
||||||
**CaCu y CaMa** siguen los mismos pasos con su `alembic.ini`, su variable
|
que publica cada indicador. La secuencia y sus pruebas están en
|
||||||
de entorno y el ETL de su proyecto (`python -m indicadores_kit.cacu.etl`).
|
`Orquestacion/` (`tests/test_ciclo.py`).
|
||||||
`correr` solo agrega semestres a `dim_periodo`; para tener también meses,
|
|
||||||
prepare los dos tipos y calcule con los pasos del kit:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uv run python -c "
|
|
||||||
from datetime import date
|
|
||||||
from indicadores_kit.pasos import calcular_periodos, preparar_registro
|
|
||||||
from indicadores_kit.registry.measures import leer_measure, ruta_de_measure
|
|
||||||
preparar_registro('cacu', 2025, 2025, tipos=('semestre', 'mes'))
|
|
||||||
medida = leer_measure(ruta_de_measure('cacu', 'cacu_eu8'))
|
|
||||||
for tipo in ('semestre', 'mes'):
|
|
||||||
calcular_periodos('cacu', medida, tipo, date(2025, 1, 1), date(2026, 1, 1), permitir_sin_definir=True)
|
|
||||||
"
|
|
||||||
uv run python main.py
|
|
||||||
```
|
|
||||||
|
|
||||||
Los ids son `cacu_eu8` y `cama_eu8`. En `tests/conftest.py` está la
|
|
||||||
secuencia completa con los fixtures del kit.
|
|
||||||
|
|
||||||
### Correr con Docker
|
### Correr con Docker
|
||||||
|
|
||||||
@@ -167,6 +164,16 @@ contexto, publica el puerto 5000 y guarda las bases en el volumen `webapi_data`
|
|||||||
tablas quedan vacías: cargue y calcule como en el camino B. También
|
tablas quedan vacías: cargue y calcule como en el camino B. También
|
||||||
levanta `webapp` en el puerto 4200.
|
levanta `webapp` en el puerto 4200.
|
||||||
|
|
||||||
|
El despliegue de desarrollo del servidor no usa este archivo sino
|
||||||
|
`deploy/dev/` (proyecto `isssteleon-dev`): `webapi` en el puerto 9603 y
|
||||||
|
`webapp` en el 9604, con las bases en el volumen `isssteleon-dev_datos`
|
||||||
|
montado de solo lectura en `/data`. Ahí no corre ningún cálculo: sirve un
|
||||||
|
dataset ya generado, fijado a la revisión `DATASET_REVISION` de
|
||||||
|
`deploy/dev/control.py`, y antes de arrancar comprueba que los gitlinks de
|
||||||
|
WebApp, WebApi, indicadores_kit y models sean los de esa revisión. Si alguno
|
||||||
|
cambia, el despliegue se bloquea hasta regenerar el dataset (ver
|
||||||
|
`deploy/dev/README.md`).
|
||||||
|
|
||||||
### Rutas
|
### Rutas
|
||||||
|
|
||||||
| Método | Ruta | Respuesta |
|
| Método | Ruta | Respuesta |
|
||||||
@@ -179,6 +186,9 @@ levanta `webapp` en el puerto 4200.
|
|||||||
| GET | `/tea/pacientes/<int:pac_id>` | 200 paciente; 404 `{"error": "not found"}` |
|
| GET | `/tea/pacientes/<int:pac_id>` | 200 paciente; 404 `{"error": "not found"}` |
|
||||||
| POST | `/tea/predict` | igual que CaCu |
|
| POST | `/tea/predict` | igual que CaCu |
|
||||||
| GET | `/<proyecto>/indicadores` | 200 lista de indicadores (`proyecto` = `cacu`, `cama` o `tea`) |
|
| GET | `/<proyecto>/indicadores` | 200 lista de indicadores (`proyecto` = `cacu`, `cama` o `tea`) |
|
||||||
|
| GET | `/<proyecto>/indicadores/<indicador>/periodos` | 200 periodos con reporte; 404 |
|
||||||
|
| GET | `/<proyecto>/indicadores/<indicador>/datos` | 200 los números, sin figura; 400 o 404 |
|
||||||
|
| GET | `/<proyecto>/indicadores/<indicador>/metadatos` | 200 ficha metodológica; 404 |
|
||||||
| GET | `/<proyecto>/indicadores/<indicador>/figuras/<figura>` | 200 JSON de la figura; 400 o 404 |
|
| GET | `/<proyecto>/indicadores/<indicador>/figuras/<figura>` | 200 JSON de la figura; 400 o 404 |
|
||||||
|
|
||||||
Las rutas de `pac_id` solo aceptan enteros. Con otro valor (`/tea/pacientes/abc`)
|
Las rutas de `pac_id` solo aceptan enteros. Con otro valor (`/tea/pacientes/abc`)
|
||||||
@@ -190,18 +200,34 @@ Ejemplos:
|
|||||||
curl localhost:5000/health
|
curl localhost:5000/health
|
||||||
curl localhost:5000/tea/pacientes/1
|
curl localhost:5000/tea/pacientes/1
|
||||||
curl localhost:5000/tea/indicadores
|
curl localhost:5000/tea/indicadores
|
||||||
curl "localhost:5000/tea/indicadores/K01_evaluacion_3_meses/figuras/fig_c1_grupos"
|
curl "localhost:5000/tea/indicadores/M21_diagnosticados_con_eeg/figuras/fig_c1_grupos"
|
||||||
curl "localhost:5000/tea/indicadores/K01_evaluacion_3_meses/figuras/fig_c1_grupos?periodos=2025-S1,2025-S2&tema=oscuro"
|
curl "localhost:5000/tea/indicadores/M21_diagnosticados_con_eeg/figuras/fig_c1_grupos?periodos=2025-S1,2025-S2&tema=oscuro"
|
||||||
|
curl localhost:5000/tea/indicadores/M21_diagnosticados_con_eeg/periodos
|
||||||
|
curl "localhost:5000/tea/indicadores/M21_diagnosticados_con_eeg/datos?periodos=2025-S1,2025-S2"
|
||||||
|
curl localhost:5000/tea/indicadores/M21_diagnosticados_con_eeg/metadatos
|
||||||
curl localhost:5000/cacu/indicadores
|
curl localhost:5000/cacu/indicadores
|
||||||
curl "localhost:5000/cacu/indicadores/cacu_eu8/figuras/fig_c1_puntos?periodos=2025-01,2025-02,2025-03"
|
curl localhost:5000/cacu/indicadores/ind1/datos
|
||||||
|
curl "localhost:5000/cacu/indicadores/ind1/figuras/fig_c1_puntos?periodos=2025-01,2025-02,2025-03"
|
||||||
|
curl "localhost:5000/cacu/indicadores/cacu_eu7/figuras/fig_c2_donas?periodos=2025-S1"
|
||||||
```
|
```
|
||||||
|
|
||||||
`/<proyecto>/indicadores` devuelve, por indicador: `id`, `titulo`,
|
`/<proyecto>/indicadores` devuelve, por indicador: `id`, `titulo`,
|
||||||
`contrato`, `figuras` y `tipos_periodo` (los que publica la definición en
|
`version`, `contrato`, `unidad`, `sentido`, `figuras`, `estratos` y
|
||||||
`extension.publicacion`). Las figuras dependen de la definición: con
|
`tipos_periodo` (los que publica la definición en `extension.publicacion`). El
|
||||||
ficha (TEA) hay una por contrato (`fig_c1_grupos`, `fig_c2_apiladas`,
|
`id` es el nombre del archivo TOML (`cacu_eu7`), no el `measure_id` de las
|
||||||
`fig_c3r_caja`); sin ficha (CaCu, CaMa) es `fig_c1_puntos`, un punto por
|
tablas (`CACU_EU7`). Los indicadores marcados `oculto` en su TOML no salen en
|
||||||
periodo.
|
la lista, pero su `id` sigue respondiendo. La lista no dice qué filtros admite
|
||||||
|
cada indicador.
|
||||||
|
|
||||||
|
Las figuras dependen del contrato y de si la definición tiene ficha
|
||||||
|
(`extension.ficha`, `serving/figuras.py: figuras_de`):
|
||||||
|
|
||||||
|
| Contrato | Definición | Figuras | Eje |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| C1 | sin ficha (CaCu `ind1`, `cacu_eu13`; CaMa) | `fig_c1_puntos` | un punto por periodo |
|
||||||
|
| C1 | con ficha (TEA) | `fig_c1_grupos` | una barra por grupo, una serie por periodo |
|
||||||
|
| C2 | con ficha de un solo grupo (los tres proyectos) | `fig_c2_donas`, `fig_c2_barras` | una distribución; sin `periodos`, la del más reciente con datos |
|
||||||
|
| C3r | con ficha (los tres proyectos) | `fig_c3r_caja` | una caja por grupo y periodo |
|
||||||
|
|
||||||
Parámetros de la figura:
|
Parámetros de la figura:
|
||||||
|
|
||||||
@@ -221,6 +247,54 @@ Códigos de la figura:
|
|||||||
| 404 | indicador desconocido; figura que no es del contrato del indicador; el indicador no tiene reportes; algún periodo pedido no tiene reporte |
|
| 404 | indicador desconocido; figura que no es del contrato del indicador; el indicador no tiene reportes; algún periodo pedido no tiene reporte |
|
||||||
| 500 | error interno (por ejemplo un `KeyError`) |
|
| 500 | error interno (por ejemplo un `KeyError`) |
|
||||||
|
|
||||||
|
### Datos, periodos y metadatos
|
||||||
|
|
||||||
|
Para mostrar el número o graficar desde el frontend, sin Plotly. Salen de
|
||||||
|
las mismas filas que las figuras y ya traen la supresión aplicada.
|
||||||
|
|
||||||
|
| Ruta | Qué devuelve |
|
||||||
|
| --- | --- |
|
||||||
|
| `/periodos` | `id`, `version` y `periodos`: por cada periodo con reporte, su `tipo`, sus fechas, su `report_id`, `generado_en` y `fecha_corte` |
|
||||||
|
| `/datos?periodos=&estrato=&filtro=` | `id`, `titulo`, `version`, `contrato`, `unidad`, `tipo_periodo`, `periodos`, `estrato`, `valores_estrato`, `grupos`, `categorias` y `grupos_de_categoria` (vacías salvo en C2), `notas` (el pie), `reportes` con la procedencia de cada periodo y `filas` (una por periodo y grupo, o por categoría en C2); `filtros`, solo si se pidió uno |
|
||||||
|
| `/metadatos` | la ficha, la unidad, los estándares y las reglas que usa el indicador, con su estado |
|
||||||
|
|
||||||
|
`periodos` se pide igual que en la figura. `estrato` es uno de los
|
||||||
|
`estratos` del indicador y solo desglosa un C1 sin ficha; hoy ningún
|
||||||
|
indicador declara estratos, así que todo `?estrato=` da 400. Toda fila de `/datos` trae `periodo`, `grupo`,
|
||||||
|
`estrato` y `suprimido`, y después las columnas de su `contrato`:
|
||||||
|
|
||||||
|
| Contrato | Columnas |
|
||||||
|
| --- | --- |
|
||||||
|
| C1 (proporción) | `numerador`, `denominador`, `valor` (0 a 100), `ic_bajo`, `ic_alto` (Wilson al 95 %), `n_sin_evento`, `n_excluido` |
|
||||||
|
| C2 (distribución) | `categoria`, `n`, `orden` |
|
||||||
|
| C3r (tiempos) | `n`, `mediana`, `q1`, `q3`, `n_sin_evento`, `n_excluido`, `unidad` |
|
||||||
|
|
||||||
|
Una celda suprimida va con `suprimido` en 1 y sus números en `null`. En
|
||||||
|
`reportes`, `periodo_fin` es el primer día que ya no entra en el periodo.
|
||||||
|
|
||||||
|
La forma de estas respuestas es un contrato con el frontend: no se quita
|
||||||
|
ni se renombra un campo; solo se agregan.
|
||||||
|
|
||||||
|
**Filtros** (`?filtro=estrato:valor`, varios separados por coma; MD-19): `/datos`
|
||||||
|
y `/figuras/<f>` dan el mismo contrato, contado solo con las unidades que tienen
|
||||||
|
esos valores de estrato. Se combina con `periodos` y con `estrato` (el desglose).
|
||||||
|
`/datos` agrega la llave `"filtros": {"grupo_edad": "25-34"}`, solo cuando se pidió
|
||||||
|
filtro. La supresión se recalcula sobre las unidades filtradas, con el mismo
|
||||||
|
umbral: un filtro nunca deja ver una celda chica. Un indicador solo se puede
|
||||||
|
filtrar por los estratos que declara en `extension.filtros` de su TOML; hoy
|
||||||
|
ninguno lo hace (`cat_measure_estrato` queda vacía), así que todo `?filtro=` da 400.
|
||||||
|
El único estrato con valores en el catálogo es `grupo_edad`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl "localhost:5000/cacu/indicadores/ind1/datos?periodos=2025-S1&filtro=grupo_edad:25-34"
|
||||||
|
```
|
||||||
|
|
||||||
|
Códigos: 400 si `periodos` está mal formado, `estrato` no es del
|
||||||
|
indicador, o un `filtro` está mal escrito (`grupo_edad`, `:x`, el mismo
|
||||||
|
estrato dos veces), su estrato no es filtro del indicador o su valor no
|
||||||
|
está en el catálogo (`cat_estrato_valor`); 404 si el indicador no existe, no tiene reportes o algún
|
||||||
|
periodo pedido no lo tiene.
|
||||||
|
|
||||||
## Cómo extender
|
## Cómo extender
|
||||||
|
|
||||||
### Agregar una ruta a un blueprint existente
|
### Agregar una ruta a un blueprint existente
|
||||||
@@ -283,7 +357,7 @@ with pytest.MonkeyPatch.context() as mp:
|
|||||||
```
|
```
|
||||||
|
|
||||||
`fixtures.base_de_prueba` es de `indicadores_kit.tea.fixtures`: crea las
|
`fixtures.base_de_prueba` es de `indicadores_kit.tea.fixtures`: crea las
|
||||||
tablas y deja los 18 indicadores calculados.
|
tablas y deja sus 5 indicadores calculados.
|
||||||
|
|
||||||
Si cambias la URL después de crear el engine, llama a
|
Si cambias la URL después de crear el engine, llama a
|
||||||
`get_<dominio>_engine.cache_clear()`.
|
`get_<dominio>_engine.cache_clear()`.
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
"""Apoyo de los notebooks: montar la base de un dominio en una carpeta temporal.
|
|
||||||
|
|
||||||
Hace lo mismo que el fixture `base_del_dominio` de `tests/test_produccion.py`:
|
|
||||||
apunta Persistance a un archivo SQLite, migra con Alembic y llena el
|
|
||||||
staging con los fixtures del kit. Desde ahí, los pasos de
|
|
||||||
`indicadores_kit.pasos` corren por el camino de producción (repositorios
|
|
||||||
de Persistance). No es parte del paquete.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import persistance
|
|
||||||
import persistance.db
|
|
||||||
from alembic import command
|
|
||||||
from alembic.config import Config
|
|
||||||
from persistance.settings import settings
|
|
||||||
|
|
||||||
from indicadores_kit.cacu import fixtures as fixtures_cacu
|
|
||||||
from indicadores_kit.cama import fixtures as fixtures_cama
|
|
||||||
from indicadores_kit.pasos import fabrica_por_defecto
|
|
||||||
from indicadores_kit.registry.parametros import RUTA_PARAMETROS
|
|
||||||
|
|
||||||
FIXTURES = {"cacu": fixtures_cacu, "cama": fixtures_cama}
|
|
||||||
MOTORES = (
|
|
||||||
persistance.db.get_cacu_engine,
|
|
||||||
persistance.db.get_cama_engine,
|
|
||||||
persistance.db.get_tea_engine,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def montar(proyecto: str, carpeta: Path) -> str:
|
|
||||||
"""La base del proyecto en `carpeta`, migrada y con staging sintético. Devuelve su URL.
|
|
||||||
|
|
||||||
Es lo que hacen `<PROYECTO>_DATABASE_URL` y `alembic upgrade head`.
|
|
||||||
El ajuste se cambia en memoria porque Persistance lo lee al importarse.
|
|
||||||
"""
|
|
||||||
url = f"sqlite:///{carpeta / f'{proyecto}.db'}"
|
|
||||||
setattr(settings, f"{proyecto}_database_url", url)
|
|
||||||
for motor in MOTORES:
|
|
||||||
motor.cache_clear()
|
|
||||||
alembic_ini = Path(persistance.__file__).parent / proyecto / "alembic.ini"
|
|
||||||
command.upgrade(Config(str(alembic_ini)), "head")
|
|
||||||
with fabrica_por_defecto(proyecto)() as sesion:
|
|
||||||
FIXTURES[proyecto].insertar(sesion)
|
|
||||||
return url
|
|
||||||
|
|
||||||
|
|
||||||
def parametros_sin_supresion(carpeta: Path) -> Path:
|
|
||||||
"""Una copia de `parametros.toml` con el umbral de supresión en 1.
|
|
||||||
|
|
||||||
Con 4 o 5 pacientes por periodo, el umbral de 5 ocultaría casi todo.
|
|
||||||
Es lo que hacen las pruebas de producción.
|
|
||||||
"""
|
|
||||||
ruta = carpeta / "parametros.toml"
|
|
||||||
ruta.write_text(
|
|
||||||
RUTA_PARAMETROS.read_text(encoding="utf-8").replace("valor = 5", "valor = 1"),
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
return ruta
|
|
||||||
@@ -1,544 +0,0 @@
|
|||||||
{
|
|
||||||
"cells": [
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "f0fbce7e",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"**Qué revisa este notebook.** Las rutas de indicadores de CaCu (tarea WA-2), el análogo de las de TEA: `webapi/indicadores.py` registra en el blueprint `/cacu`\n",
|
|
||||||
"\n",
|
|
||||||
"| Ruta | Qué devuelve |\n",
|
|
||||||
"|---|---|\n",
|
|
||||||
"| `GET /cacu/indicadores` | id, título, contrato, figuras y tipos de periodo que publica cada indicador |\n",
|
|
||||||
"| `GET /cacu/indicadores/<id>/figuras/<figura>?periodos=&tema=` | JSON de Plotly; 404 si el indicador, la figura o el reporte no existen; 400 si el tema o los periodos están mal |\n",
|
|
||||||
"\n",
|
|
||||||
"Por qué: antes solo TEA servía indicadores y su lógica vivía en su blueprint; ahora es un solo código para todos los proyectos. Los periodos se validan contra los `tipos_periodo` que publica la definición (semestre `AAAA-S1`, mes `AAAA-MM`).\n",
|
|
||||||
"\n",
|
|
||||||
"Todo corre en una carpeta temporal, con la app de Flask dentro del proceso (cliente de pruebas, sin servidor); no deja archivos en el repositorio. Cada sección termina en `assert`."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 1,
|
|
||||||
"id": "2335c99f",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:28:58.077856Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:28:58.076999Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:28:58.933116Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:28:58.932355Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"import tempfile\n",
|
|
||||||
"from datetime import date\n",
|
|
||||||
"from pathlib import Path\n",
|
|
||||||
"\n",
|
|
||||||
"import pandas as pd\n",
|
|
||||||
"\n",
|
|
||||||
"import apoyo\n",
|
|
||||||
"from indicadores_kit.pasos import calcular_periodos, cargar, fabrica_por_defecto, preparar_registro, vistas\n",
|
|
||||||
"from indicadores_kit.registry.measures import leer_measure, ruta_de_measure\n",
|
|
||||||
"\n",
|
|
||||||
"carpeta = Path(tempfile.mkdtemp(prefix=\"cacu_ind_\"))\n",
|
|
||||||
"parametros = apoyo.parametros_sin_supresion(carpeta)\n",
|
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"def sembrar(proyecto):\n",
|
|
||||||
" \"\"\"Base migrada con staging sintético, cargada, con `<proyecto>_eu8` calculado en semestres y meses.\"\"\"\n",
|
|
||||||
" apoyo.montar(proyecto, carpeta)\n",
|
|
||||||
" cargar(proyecto)\n",
|
|
||||||
" vistas(fabrica_por_defecto(proyecto), proyecto)\n",
|
|
||||||
" preparar_registro(proyecto, 2025, 2025, ruta=parametros, tipos=(\"semestre\", \"mes\"))\n",
|
|
||||||
" medida = leer_measure(ruta_de_measure(proyecto, f\"{proyecto}_eu8\"))\n",
|
|
||||||
" return {\n",
|
|
||||||
" tipo: len(calcular_periodos(proyecto, medida, tipo, date(2025, 1, 1), date(2026, 1, 1), permitir_sin_definir=True))\n",
|
|
||||||
" for tipo in (\"semestre\", \"mes\")\n",
|
|
||||||
" }"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "e0e2fd4c",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 1. Sembrar y calcular\n",
|
|
||||||
"\n",
|
|
||||||
"`apoyo.montar` apunta Persistance a un SQLite temporal, migra con Alembic y llena el staging con los fixtures del kit. Luego los pasos del kit: carga, vistas, `dim_periodo` con semestres y meses, y el cálculo en los dos tipos de periodo."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 2,
|
|
||||||
"id": "31755e66",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:28:58.934834Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:28:58.934605Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:28:59.262772Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:28:59.262146Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Context impl SQLiteImpl.\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Will assume non-transactional DDL.\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade -> 79fe432d52a2, create cacu tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 79fe432d52a2 -> cbb31acf322d, add biometria hematica\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade cbb31acf322d -> 9952833a0048, add indicadores_kit tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 9952833a0048 -> b4a35a200913, add dim_fecha and dim_grupo_edad\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade b4a35a200913 -> 04fa57d42fec, add indicador_definicion\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 04fa57d42fec -> 1b350354d5ed, add measure_report.parametros_sha\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 1b350354d5ed -> cbd8fed23729, measure_report kit_version replaces sql_sha\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade cbd8fed23729 -> 8e7534131c73, add result tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<div>\n",
|
|
||||||
"<style scoped>\n",
|
|
||||||
" .dataframe tbody tr th:only-of-type {\n",
|
|
||||||
" vertical-align: middle;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe tbody tr th {\n",
|
|
||||||
" vertical-align: top;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe thead th {\n",
|
|
||||||
" text-align: right;\n",
|
|
||||||
" }\n",
|
|
||||||
"</style>\n",
|
|
||||||
"<table border=\"1\" class=\"dataframe\">\n",
|
|
||||||
" <thead>\n",
|
|
||||||
" <tr style=\"text-align: right;\">\n",
|
|
||||||
" <th></th>\n",
|
|
||||||
" <th>reportes calculados</th>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </thead>\n",
|
|
||||||
" <tbody>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>semestre</th>\n",
|
|
||||||
" <td>2</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>mes</th>\n",
|
|
||||||
" <td>12</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </tbody>\n",
|
|
||||||
"</table>\n",
|
|
||||||
"</div>"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
" reportes calculados\n",
|
|
||||||
"semestre 2\n",
|
|
||||||
"mes 12"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 2,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"calculados = sembrar(\"cacu\")\n",
|
|
||||||
"assert calculados == {\"semestre\": 2, \"mes\": 12}\n",
|
|
||||||
"pd.Series(calculados, name=\"reportes calculados\").to_frame()"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "3742a259",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 2. Levantar la app"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 3,
|
|
||||||
"id": "dd463639",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:28:59.264658Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:28:59.264546Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:28:59.539493Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:28:59.539048Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"from webapi import create_app\n",
|
|
||||||
"\n",
|
|
||||||
"app = create_app()\n",
|
|
||||||
"app.config.update(TESTING=True)\n",
|
|
||||||
"cliente = app.test_client()\n",
|
|
||||||
"assert cliente.get(\"/health\").status_code == 200"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "dece2719",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 3. `GET /cacu/indicadores`\n",
|
|
||||||
"\n",
|
|
||||||
"La lista sale de las definiciones del kit. CaCu no tiene ficha: su figura es un punto por periodo."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 4,
|
|
||||||
"id": "bc5fe03c",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:28:59.541734Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:28:59.541594Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:28:59.549005Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:28:59.548360Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<div>\n",
|
|
||||||
"<style scoped>\n",
|
|
||||||
" .dataframe tbody tr th:only-of-type {\n",
|
|
||||||
" vertical-align: middle;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe tbody tr th {\n",
|
|
||||||
" vertical-align: top;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe thead th {\n",
|
|
||||||
" text-align: right;\n",
|
|
||||||
" }\n",
|
|
||||||
"</style>\n",
|
|
||||||
"<table border=\"1\" class=\"dataframe\">\n",
|
|
||||||
" <thead>\n",
|
|
||||||
" <tr style=\"text-align: right;\">\n",
|
|
||||||
" <th></th>\n",
|
|
||||||
" <th>contrato</th>\n",
|
|
||||||
" <th>figuras</th>\n",
|
|
||||||
" <th>id</th>\n",
|
|
||||||
" <th>tipos_periodo</th>\n",
|
|
||||||
" <th>titulo</th>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </thead>\n",
|
|
||||||
" <tbody>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>0</th>\n",
|
|
||||||
" <td>C1</td>\n",
|
|
||||||
" <td>[fig_c1_puntos]</td>\n",
|
|
||||||
" <td>cacu_eu8</td>\n",
|
|
||||||
" <td>[semestre, mes]</td>\n",
|
|
||||||
" <td>Tasa de referencia a repetir citología</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </tbody>\n",
|
|
||||||
"</table>\n",
|
|
||||||
"</div>"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
" contrato figuras id tipos_periodo \\\n",
|
|
||||||
"0 C1 [fig_c1_puntos] cacu_eu8 [semestre, mes] \n",
|
|
||||||
"\n",
|
|
||||||
" titulo \n",
|
|
||||||
"0 Tasa de referencia a repetir citología "
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 4,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"respuesta = cliente.get(\"/cacu/indicadores\")\n",
|
|
||||||
"assert respuesta.status_code == 200\n",
|
|
||||||
"(fila,) = respuesta.get_json()\n",
|
|
||||||
"assert fila[\"id\"] == \"cacu_eu8\"\n",
|
|
||||||
"assert fila[\"contrato\"] == \"C1\" and fila[\"figuras\"] == [\"fig_c1_puntos\"]\n",
|
|
||||||
"assert fila[\"tipos_periodo\"] == [\"semestre\", \"mes\"]\n",
|
|
||||||
"pd.DataFrame([fila])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "b04a81c8",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 4. Una figura por semestre y una por mes\n",
|
|
||||||
"\n",
|
|
||||||
"Sin `?periodos=` se usan los periodos con reporte del primer tipo que publica la definición (semestre). Con meses, se piden explícitos."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 5,
|
|
||||||
"id": "91e6686f",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:28:59.550578Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:28:59.550464Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:28:59.791898Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:28:59.791286Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"(['2025-S1', '2025-S2'], ['2025-01', '2025-02', '2025-03'])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 5,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"def eje_x(respuesta):\n",
|
|
||||||
" return sorted({x for trazo in respuesta.get_json()[\"data\"] for x in trazo[\"x\"]})\n",
|
|
||||||
"\n",
|
|
||||||
"base = \"/cacu/indicadores/cacu_eu8/figuras/fig_c1_puntos\"\n",
|
|
||||||
"semestres = cliente.get(base)\n",
|
|
||||||
"assert semestres.status_code == 200 and semestres.mimetype == \"application/json\"\n",
|
|
||||||
"assert eje_x(semestres) == [\"2025-S1\", \"2025-S2\"]\n",
|
|
||||||
"meses = cliente.get(base + \"?periodos=2025-01,2025-02,2025-03&tema=oscuro\")\n",
|
|
||||||
"assert meses.status_code == 200\n",
|
|
||||||
"assert eje_x(meses) == [\"2025-01\", \"2025-02\", \"2025-03\"]\n",
|
|
||||||
"eje_x(semestres), eje_x(meses)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "a0cc37ed",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 5. Los errores\n",
|
|
||||||
"\n",
|
|
||||||
"400: tema o periodos mal formados, un tipo que el indicador no publica o tipos mezclados. 404: indicador o figura desconocidos, o un periodo sin reporte."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 6,
|
|
||||||
"id": "3293057d",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:28:59.793886Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:28:59.793756Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:28:59.804684Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:28:59.804012Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<div>\n",
|
|
||||||
"<style scoped>\n",
|
|
||||||
" .dataframe tbody tr th:only-of-type {\n",
|
|
||||||
" vertical-align: middle;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe tbody tr th {\n",
|
|
||||||
" vertical-align: top;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe thead th {\n",
|
|
||||||
" text-align: right;\n",
|
|
||||||
" }\n",
|
|
||||||
"</style>\n",
|
|
||||||
"<table border=\"1\" class=\"dataframe\">\n",
|
|
||||||
" <thead>\n",
|
|
||||||
" <tr style=\"text-align: right;\">\n",
|
|
||||||
" <th></th>\n",
|
|
||||||
" <th>caso</th>\n",
|
|
||||||
" <th>código</th>\n",
|
|
||||||
" <th>error</th>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </thead>\n",
|
|
||||||
" <tbody>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>0</th>\n",
|
|
||||||
" <td>tema desconocido</td>\n",
|
|
||||||
" <td>400</td>\n",
|
|
||||||
" <td>tema desconocido 'rojo'; use claro u oscuro</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>1</th>\n",
|
|
||||||
" <td>periodo mal formado</td>\n",
|
|
||||||
" <td>400</td>\n",
|
|
||||||
" <td>Periodos mal formados: '2025-1'; este indicado...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>2</th>\n",
|
|
||||||
" <td>tipo que no publica</td>\n",
|
|
||||||
" <td>400</td>\n",
|
|
||||||
" <td>Periodos mal formados: '2025-T1'; este indicad...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>3</th>\n",
|
|
||||||
" <td>tipos mezclados</td>\n",
|
|
||||||
" <td>400</td>\n",
|
|
||||||
" <td>Periodos de tipos distintos: '2025-S1,2025-03'...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>4</th>\n",
|
|
||||||
" <td>indicador desconocido</td>\n",
|
|
||||||
" <td>404</td>\n",
|
|
||||||
" <td>indicador desconocido</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>5</th>\n",
|
|
||||||
" <td>figura de otro contrato</td>\n",
|
|
||||||
" <td>404</td>\n",
|
|
||||||
" <td>figura 'fig_c2_apiladas' no es del contrato C1</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>6</th>\n",
|
|
||||||
" <td>semestre sin reporte</td>\n",
|
|
||||||
" <td>404</td>\n",
|
|
||||||
" <td>No hay reporte de cacu/CACU_EU8 0.1.0 para 203...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>7</th>\n",
|
|
||||||
" <td>mes sin reporte</td>\n",
|
|
||||||
" <td>404</td>\n",
|
|
||||||
" <td>No hay reporte de cacu/CACU_EU8 0.1.0 para 203...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </tbody>\n",
|
|
||||||
"</table>\n",
|
|
||||||
"</div>"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
" caso código \\\n",
|
|
||||||
"0 tema desconocido 400 \n",
|
|
||||||
"1 periodo mal formado 400 \n",
|
|
||||||
"2 tipo que no publica 400 \n",
|
|
||||||
"3 tipos mezclados 400 \n",
|
|
||||||
"4 indicador desconocido 404 \n",
|
|
||||||
"5 figura de otro contrato 404 \n",
|
|
||||||
"6 semestre sin reporte 404 \n",
|
|
||||||
"7 mes sin reporte 404 \n",
|
|
||||||
"\n",
|
|
||||||
" error \n",
|
|
||||||
"0 tema desconocido 'rojo'; use claro u oscuro \n",
|
|
||||||
"1 Periodos mal formados: '2025-1'; este indicado... \n",
|
|
||||||
"2 Periodos mal formados: '2025-T1'; este indicad... \n",
|
|
||||||
"3 Periodos de tipos distintos: '2025-S1,2025-03'... \n",
|
|
||||||
"4 indicador desconocido \n",
|
|
||||||
"5 figura 'fig_c2_apiladas' no es del contrato C1 \n",
|
|
||||||
"6 No hay reporte de cacu/CACU_EU8 0.1.0 para 203... \n",
|
|
||||||
"7 No hay reporte de cacu/CACU_EU8 0.1.0 para 203... "
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 6,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"casos = {\n",
|
|
||||||
" \"tema desconocido\": (base + \"?tema=rojo\", 400),\n",
|
|
||||||
" \"periodo mal formado\": (base + \"?periodos=2025-1\", 400),\n",
|
|
||||||
" \"tipo que no publica\": (base + \"?periodos=2025-T1\", 400),\n",
|
|
||||||
" \"tipos mezclados\": (base + \"?periodos=2025-S1,2025-03\", 400),\n",
|
|
||||||
" \"indicador desconocido\": (\"/cacu/indicadores/NO_EXISTE/figuras/fig_c1_puntos\", 404),\n",
|
|
||||||
" \"figura de otro contrato\": (\"/cacu/indicadores/cacu_eu8/figuras/fig_c2_apiladas\", 404),\n",
|
|
||||||
" \"semestre sin reporte\": (base + \"?periodos=2030-S1\", 404),\n",
|
|
||||||
" \"mes sin reporte\": (base + \"?periodos=2030-11\", 404),\n",
|
|
||||||
"}\n",
|
|
||||||
"filas = []\n",
|
|
||||||
"for nombre, (ruta, esperado) in casos.items():\n",
|
|
||||||
" respuesta = cliente.get(ruta)\n",
|
|
||||||
" assert respuesta.status_code == esperado, (nombre, respuesta.status_code)\n",
|
|
||||||
" assert \"error\" in respuesta.get_json()\n",
|
|
||||||
" filas.append({\"caso\": nombre, \"código\": respuesta.status_code, \"error\": respuesta.get_json()[\"error\"]})\n",
|
|
||||||
"pd.DataFrame(filas)"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"kernelspec": {
|
|
||||||
"display_name": "Python 3",
|
|
||||||
"language": "python",
|
|
||||||
"name": "python3"
|
|
||||||
},
|
|
||||||
"language_info": {
|
|
||||||
"codemirror_mode": {
|
|
||||||
"name": "ipython",
|
|
||||||
"version": 3
|
|
||||||
},
|
|
||||||
"file_extension": ".py",
|
|
||||||
"mimetype": "text/x-python",
|
|
||||||
"name": "python",
|
|
||||||
"nbconvert_exporter": "python",
|
|
||||||
"pygments_lexer": "ipython3",
|
|
||||||
"version": "3.14.5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nbformat": 4,
|
|
||||||
"nbformat_minor": 5
|
|
||||||
}
|
|
||||||
@@ -1,692 +0,0 @@
|
|||||||
{
|
|
||||||
"cells": [
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "08979bf1",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"**Qué revisa este notebook.** Las rutas de indicadores de CaMa (tarea WA-2), el análogo de las de TEA: `webapi/indicadores.py` registra en el blueprint `/cama`\n",
|
|
||||||
"\n",
|
|
||||||
"| Ruta | Qué devuelve |\n",
|
|
||||||
"|---|---|\n",
|
|
||||||
"| `GET /cama/indicadores` | id, título, contrato, figuras y tipos de periodo que publica cada indicador |\n",
|
|
||||||
"| `GET /cama/indicadores/<id>/figuras/<figura>?periodos=&tema=` | JSON de Plotly; 404 si el indicador, la figura o el reporte no existen; 400 si el tema o los periodos están mal |\n",
|
|
||||||
"\n",
|
|
||||||
"Por qué: antes solo TEA servía indicadores y su lógica vivía en su blueprint; ahora es un solo código para todos los proyectos. Los periodos se validan contra los `tipos_periodo` que publica la definición (semestre `AAAA-S1`, mes `AAAA-MM`).\n",
|
|
||||||
"\n",
|
|
||||||
"Todo corre en una carpeta temporal, con la app de Flask dentro del proceso (cliente de pruebas, sin servidor); no deja archivos en el repositorio. Cada sección termina en `assert`."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 1,
|
|
||||||
"id": "d5ad084c",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:29:12.636812Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:29:12.636595Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:29:13.532062Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:29:13.531521Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"import tempfile\n",
|
|
||||||
"from datetime import date\n",
|
|
||||||
"from pathlib import Path\n",
|
|
||||||
"\n",
|
|
||||||
"import pandas as pd\n",
|
|
||||||
"\n",
|
|
||||||
"import apoyo\n",
|
|
||||||
"from indicadores_kit.pasos import calcular_periodos, cargar, fabrica_por_defecto, preparar_registro, vistas\n",
|
|
||||||
"from indicadores_kit.registry.measures import leer_measure, ruta_de_measure\n",
|
|
||||||
"\n",
|
|
||||||
"carpeta = Path(tempfile.mkdtemp(prefix=\"cama_ind_\"))\n",
|
|
||||||
"parametros = apoyo.parametros_sin_supresion(carpeta)\n",
|
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"def sembrar(proyecto):\n",
|
|
||||||
" \"\"\"Base migrada con staging sintético, cargada, con `<proyecto>_eu8` calculado en semestres y meses.\"\"\"\n",
|
|
||||||
" apoyo.montar(proyecto, carpeta)\n",
|
|
||||||
" cargar(proyecto)\n",
|
|
||||||
" vistas(fabrica_por_defecto(proyecto), proyecto)\n",
|
|
||||||
" preparar_registro(proyecto, 2025, 2025, ruta=parametros, tipos=(\"semestre\", \"mes\"))\n",
|
|
||||||
" medida = leer_measure(ruta_de_measure(proyecto, f\"{proyecto}_eu8\"))\n",
|
|
||||||
" return {\n",
|
|
||||||
" tipo: len(calcular_periodos(proyecto, medida, tipo, date(2025, 1, 1), date(2026, 1, 1), permitir_sin_definir=True))\n",
|
|
||||||
" for tipo in (\"semestre\", \"mes\")\n",
|
|
||||||
" }"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "8a047caf",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 1. Sembrar CaCu, CaMa y TEA\n",
|
|
||||||
"\n",
|
|
||||||
"CaMa es lo que se revisa; CaCu y TEA se siembran para comprobar al final que siguen respondiendo."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 2,
|
|
||||||
"id": "2d1f6b64",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:29:13.534349Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:29:13.534069Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:29:14.164492Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:29:14.163897Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Context impl SQLiteImpl.\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Will assume non-transactional DDL.\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade -> 79fe432d52a2, create cacu tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 79fe432d52a2 -> cbb31acf322d, add biometria hematica\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade cbb31acf322d -> 9952833a0048, add indicadores_kit tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 9952833a0048 -> b4a35a200913, add dim_fecha and dim_grupo_edad\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade b4a35a200913 -> 04fa57d42fec, add indicador_definicion\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 04fa57d42fec -> 1b350354d5ed, add measure_report.parametros_sha\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 1b350354d5ed -> cbd8fed23729, measure_report kit_version replaces sql_sha\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade cbd8fed23729 -> 8e7534131c73, add result tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Context impl SQLiteImpl.\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Will assume non-transactional DDL.\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade -> 61636717f659, create cama tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 61636717f659 -> c6939a6f23da, add biometria hematica\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade c6939a6f23da -> 0616858b7434, add indicadores_kit tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 0616858b7434 -> 1006aa43f896, add dim_fecha and dim_grupo_edad\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 1006aa43f896 -> b47d340c39f9, add indicador_definicion\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade b47d340c39f9 -> 2568e85ae55a, add measure_report.parametros_sha\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade 2568e85ae55a -> b3ef4834fd39, measure_report kit_version replaces sql_sha\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"INFO [alembic.runtime.migration] Running upgrade b3ef4834fd39 -> 4a8f75c95c04, add result tables\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<div>\n",
|
|
||||||
"<style scoped>\n",
|
|
||||||
" .dataframe tbody tr th:only-of-type {\n",
|
|
||||||
" vertical-align: middle;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe tbody tr th {\n",
|
|
||||||
" vertical-align: top;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe thead th {\n",
|
|
||||||
" text-align: right;\n",
|
|
||||||
" }\n",
|
|
||||||
"</style>\n",
|
|
||||||
"<table border=\"1\" class=\"dataframe\">\n",
|
|
||||||
" <thead>\n",
|
|
||||||
" <tr style=\"text-align: right;\">\n",
|
|
||||||
" <th></th>\n",
|
|
||||||
" <th>cacu</th>\n",
|
|
||||||
" <th>cama</th>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>reportes por tipo</th>\n",
|
|
||||||
" <th></th>\n",
|
|
||||||
" <th></th>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </thead>\n",
|
|
||||||
" <tbody>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>semestre</th>\n",
|
|
||||||
" <td>2</td>\n",
|
|
||||||
" <td>2</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>mes</th>\n",
|
|
||||||
" <td>12</td>\n",
|
|
||||||
" <td>12</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </tbody>\n",
|
|
||||||
"</table>\n",
|
|
||||||
"</div>"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
" cacu cama\n",
|
|
||||||
"reportes por tipo \n",
|
|
||||||
"semestre 2 2\n",
|
|
||||||
"mes 12 12"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 2,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"calculados = {p: sembrar(p) for p in (\"cacu\", \"cama\")}\n",
|
|
||||||
"pd.DataFrame(calculados).rename_axis(\"reportes por tipo\")"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 3,
|
|
||||||
"id": "4b139a71",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:29:14.166372Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:29:14.166264Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:29:16.964747Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:29:16.963671Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"assert calculados[\"cacu\"] == calculados[\"cama\"] == {\"semestre\": 2, \"mes\": 12}\n",
|
|
||||||
"\n",
|
|
||||||
"from indicadores_kit.tea import fixtures as fixtures_tea\n",
|
|
||||||
"from persistance.db import get_tea_engine\n",
|
|
||||||
"from persistance.settings import settings\n",
|
|
||||||
"\n",
|
|
||||||
"settings.tea_database_url = f\"sqlite:///{carpeta / 'tea.db'}\"\n",
|
|
||||||
"get_tea_engine.cache_clear()\n",
|
|
||||||
"assert len(fixtures_tea.base_de_prueba(get_tea_engine())) == 18"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "26625d23",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 2. Levantar la app"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 4,
|
|
||||||
"id": "43b83c90",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:29:16.967133Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:29:16.966937Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:29:17.182927Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:29:17.182429Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"from webapi import create_app\n",
|
|
||||||
"\n",
|
|
||||||
"app = create_app()\n",
|
|
||||||
"app.config.update(TESTING=True)\n",
|
|
||||||
"cliente = app.test_client()\n",
|
|
||||||
"assert cliente.get(\"/health\").status_code == 200"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "a4b9236d",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 3. `GET /cama/indicadores`\n",
|
|
||||||
"\n",
|
|
||||||
"La lista sale de las definiciones del kit. CaMa no tiene ficha: su figura es un punto por periodo."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 5,
|
|
||||||
"id": "a7b6352a",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:29:17.185036Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:29:17.184883Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:29:17.193594Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:29:17.192992Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<div>\n",
|
|
||||||
"<style scoped>\n",
|
|
||||||
" .dataframe tbody tr th:only-of-type {\n",
|
|
||||||
" vertical-align: middle;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe tbody tr th {\n",
|
|
||||||
" vertical-align: top;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe thead th {\n",
|
|
||||||
" text-align: right;\n",
|
|
||||||
" }\n",
|
|
||||||
"</style>\n",
|
|
||||||
"<table border=\"1\" class=\"dataframe\">\n",
|
|
||||||
" <thead>\n",
|
|
||||||
" <tr style=\"text-align: right;\">\n",
|
|
||||||
" <th></th>\n",
|
|
||||||
" <th>contrato</th>\n",
|
|
||||||
" <th>figuras</th>\n",
|
|
||||||
" <th>id</th>\n",
|
|
||||||
" <th>tipos_periodo</th>\n",
|
|
||||||
" <th>titulo</th>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </thead>\n",
|
|
||||||
" <tbody>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>0</th>\n",
|
|
||||||
" <td>C1</td>\n",
|
|
||||||
" <td>[fig_c1_puntos]</td>\n",
|
|
||||||
" <td>cama_eu8</td>\n",
|
|
||||||
" <td>[semestre, mes]</td>\n",
|
|
||||||
" <td>Proporción de exámenes técnicamente aceptables</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </tbody>\n",
|
|
||||||
"</table>\n",
|
|
||||||
"</div>"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
" contrato figuras id tipos_periodo \\\n",
|
|
||||||
"0 C1 [fig_c1_puntos] cama_eu8 [semestre, mes] \n",
|
|
||||||
"\n",
|
|
||||||
" titulo \n",
|
|
||||||
"0 Proporción de exámenes técnicamente aceptables "
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 5,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"respuesta = cliente.get(\"/cama/indicadores\")\n",
|
|
||||||
"assert respuesta.status_code == 200\n",
|
|
||||||
"(fila,) = respuesta.get_json()\n",
|
|
||||||
"assert fila[\"id\"] == \"cama_eu8\"\n",
|
|
||||||
"assert fila[\"contrato\"] == \"C1\" and fila[\"figuras\"] == [\"fig_c1_puntos\"]\n",
|
|
||||||
"assert fila[\"tipos_periodo\"] == [\"semestre\", \"mes\"]\n",
|
|
||||||
"pd.DataFrame([fila])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "8c8c5a96",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 4. Una figura por semestre y una por mes\n",
|
|
||||||
"\n",
|
|
||||||
"Sin `?periodos=` se usan los periodos con reporte del primer tipo que publica la definición (semestre). Con meses, se piden explícitos."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 6,
|
|
||||||
"id": "bdacb5d2",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:29:17.195892Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:29:17.195747Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:29:17.473353Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:29:17.472652Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"(['2025-S1', '2025-S2'], ['2025-01', '2025-02', '2025-03'])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 6,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"def eje_x(respuesta):\n",
|
|
||||||
" return sorted({x for trazo in respuesta.get_json()[\"data\"] for x in trazo[\"x\"]})\n",
|
|
||||||
"\n",
|
|
||||||
"base = \"/cama/indicadores/cama_eu8/figuras/fig_c1_puntos\"\n",
|
|
||||||
"semestres = cliente.get(base)\n",
|
|
||||||
"assert semestres.status_code == 200 and semestres.mimetype == \"application/json\"\n",
|
|
||||||
"assert eje_x(semestres) == [\"2025-S1\", \"2025-S2\"]\n",
|
|
||||||
"meses = cliente.get(base + \"?periodos=2025-01,2025-02,2025-03&tema=oscuro\")\n",
|
|
||||||
"assert meses.status_code == 200\n",
|
|
||||||
"assert eje_x(meses) == [\"2025-01\", \"2025-02\", \"2025-03\"]\n",
|
|
||||||
"eje_x(semestres), eje_x(meses)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "209f6915",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 5. Los errores\n",
|
|
||||||
"\n",
|
|
||||||
"400: tema o periodos mal formados, un tipo que el indicador no publica o tipos mezclados. 404: indicador o figura desconocidos, o un periodo sin reporte."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 7,
|
|
||||||
"id": "3aaa513e",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:29:17.474906Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:29:17.474786Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:29:17.485833Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:29:17.485313Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<div>\n",
|
|
||||||
"<style scoped>\n",
|
|
||||||
" .dataframe tbody tr th:only-of-type {\n",
|
|
||||||
" vertical-align: middle;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe tbody tr th {\n",
|
|
||||||
" vertical-align: top;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" .dataframe thead th {\n",
|
|
||||||
" text-align: right;\n",
|
|
||||||
" }\n",
|
|
||||||
"</style>\n",
|
|
||||||
"<table border=\"1\" class=\"dataframe\">\n",
|
|
||||||
" <thead>\n",
|
|
||||||
" <tr style=\"text-align: right;\">\n",
|
|
||||||
" <th></th>\n",
|
|
||||||
" <th>caso</th>\n",
|
|
||||||
" <th>código</th>\n",
|
|
||||||
" <th>error</th>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </thead>\n",
|
|
||||||
" <tbody>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>0</th>\n",
|
|
||||||
" <td>tema desconocido</td>\n",
|
|
||||||
" <td>400</td>\n",
|
|
||||||
" <td>tema desconocido 'rojo'; use claro u oscuro</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>1</th>\n",
|
|
||||||
" <td>periodo mal formado</td>\n",
|
|
||||||
" <td>400</td>\n",
|
|
||||||
" <td>Periodos mal formados: '2025-1'; este indicado...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>2</th>\n",
|
|
||||||
" <td>tipo que no publica</td>\n",
|
|
||||||
" <td>400</td>\n",
|
|
||||||
" <td>Periodos mal formados: '2025-T1'; este indicad...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>3</th>\n",
|
|
||||||
" <td>tipos mezclados</td>\n",
|
|
||||||
" <td>400</td>\n",
|
|
||||||
" <td>Periodos de tipos distintos: '2025-S1,2025-03'...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>4</th>\n",
|
|
||||||
" <td>indicador desconocido</td>\n",
|
|
||||||
" <td>404</td>\n",
|
|
||||||
" <td>indicador desconocido</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>5</th>\n",
|
|
||||||
" <td>figura de otro contrato</td>\n",
|
|
||||||
" <td>404</td>\n",
|
|
||||||
" <td>figura 'fig_c2_apiladas' no es del contrato C1</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>6</th>\n",
|
|
||||||
" <td>semestre sin reporte</td>\n",
|
|
||||||
" <td>404</td>\n",
|
|
||||||
" <td>No hay reporte de cama/CAMA_EU8 0.1.0 para 203...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" <tr>\n",
|
|
||||||
" <th>7</th>\n",
|
|
||||||
" <td>mes sin reporte</td>\n",
|
|
||||||
" <td>404</td>\n",
|
|
||||||
" <td>No hay reporte de cama/CAMA_EU8 0.1.0 para 203...</td>\n",
|
|
||||||
" </tr>\n",
|
|
||||||
" </tbody>\n",
|
|
||||||
"</table>\n",
|
|
||||||
"</div>"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
" caso código \\\n",
|
|
||||||
"0 tema desconocido 400 \n",
|
|
||||||
"1 periodo mal formado 400 \n",
|
|
||||||
"2 tipo que no publica 400 \n",
|
|
||||||
"3 tipos mezclados 400 \n",
|
|
||||||
"4 indicador desconocido 404 \n",
|
|
||||||
"5 figura de otro contrato 404 \n",
|
|
||||||
"6 semestre sin reporte 404 \n",
|
|
||||||
"7 mes sin reporte 404 \n",
|
|
||||||
"\n",
|
|
||||||
" error \n",
|
|
||||||
"0 tema desconocido 'rojo'; use claro u oscuro \n",
|
|
||||||
"1 Periodos mal formados: '2025-1'; este indicado... \n",
|
|
||||||
"2 Periodos mal formados: '2025-T1'; este indicad... \n",
|
|
||||||
"3 Periodos de tipos distintos: '2025-S1,2025-03'... \n",
|
|
||||||
"4 indicador desconocido \n",
|
|
||||||
"5 figura 'fig_c2_apiladas' no es del contrato C1 \n",
|
|
||||||
"6 No hay reporte de cama/CAMA_EU8 0.1.0 para 203... \n",
|
|
||||||
"7 No hay reporte de cama/CAMA_EU8 0.1.0 para 203... "
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 7,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"casos = {\n",
|
|
||||||
" \"tema desconocido\": (base + \"?tema=rojo\", 400),\n",
|
|
||||||
" \"periodo mal formado\": (base + \"?periodos=2025-1\", 400),\n",
|
|
||||||
" \"tipo que no publica\": (base + \"?periodos=2025-T1\", 400),\n",
|
|
||||||
" \"tipos mezclados\": (base + \"?periodos=2025-S1,2025-03\", 400),\n",
|
|
||||||
" \"indicador desconocido\": (\"/cama/indicadores/NO_EXISTE/figuras/fig_c1_puntos\", 404),\n",
|
|
||||||
" \"figura de otro contrato\": (\"/cama/indicadores/cama_eu8/figuras/fig_c2_apiladas\", 404),\n",
|
|
||||||
" \"semestre sin reporte\": (base + \"?periodos=2030-S1\", 404),\n",
|
|
||||||
" \"mes sin reporte\": (base + \"?periodos=2030-11\", 404),\n",
|
|
||||||
"}\n",
|
|
||||||
"filas = []\n",
|
|
||||||
"for nombre, (ruta, esperado) in casos.items():\n",
|
|
||||||
" respuesta = cliente.get(ruta)\n",
|
|
||||||
" assert respuesta.status_code == esperado, (nombre, respuesta.status_code)\n",
|
|
||||||
" assert \"error\" in respuesta.get_json()\n",
|
|
||||||
" filas.append({\"caso\": nombre, \"código\": respuesta.status_code, \"error\": respuesta.get_json()[\"error\"]})\n",
|
|
||||||
"pd.DataFrame(filas)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "83cc8e7d",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## 6. CaCu y TEA siguen respondiendo\n",
|
|
||||||
"\n",
|
|
||||||
"El código es el mismo para los tres proyectos; el blueprint de CaMa no cambió a los otros."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 8,
|
|
||||||
"id": "277c2d8a",
|
|
||||||
"metadata": {
|
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2026-10-11T06:29:17.487716Z",
|
|
||||||
"iopub.status.busy": "2026-10-11T06:29:17.487598Z",
|
|
||||||
"iopub.status.idle": "2026-10-11T06:29:17.603918Z",
|
|
||||||
"shell.execute_reply": "2026-10-11T06:29:17.603263Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"404"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 8,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"cacu = cliente.get(\"/cacu/indicadores/cacu_eu8/figuras/fig_c1_puntos?periodos=2025-03\")\n",
|
|
||||||
"assert cacu.status_code == 200\n",
|
|
||||||
"lista = cliente.get(\"/tea/indicadores\").get_json()\n",
|
|
||||||
"assert len(lista) == 18\n",
|
|
||||||
"tea = next(f for f in lista if f[\"id\"] == \"K01_evaluacion_3_meses\")\n",
|
|
||||||
"figura = cliente.get(f\"/tea/indicadores/{tea['id']}/figuras/{tea['figuras'][0]}?periodos=2025-S1,2025-S2\")\n",
|
|
||||||
"assert figura.status_code == 200 and \"data\" in figura.get_json()\n",
|
|
||||||
"cliente.get(\"/cacu/indicadores/NO_EXISTE/figuras/fig_c1_puntos\").status_code"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"kernelspec": {
|
|
||||||
"display_name": "Python 3",
|
|
||||||
"language": "python",
|
|
||||||
"name": "python3"
|
|
||||||
},
|
|
||||||
"language_info": {
|
|
||||||
"codemirror_mode": {
|
|
||||||
"name": "ipython",
|
|
||||||
"version": 3
|
|
||||||
},
|
|
||||||
"file_extension": ".py",
|
|
||||||
"mimetype": "text/x-python",
|
|
||||||
"name": "python",
|
|
||||||
"nbconvert_exporter": "python",
|
|
||||||
"pygments_lexer": "ipython3",
|
|
||||||
"version": "3.14.5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nbformat": 4,
|
|
||||||
"nbformat_minor": 5
|
|
||||||
}
|
|
||||||
+7
-38
@@ -1,53 +1,22 @@
|
|||||||
"""Lo común de las pruebas de indicadores de CaCu y CaMa."""
|
"""Lo común de las pruebas de indicadores de CaCu y CaMa."""
|
||||||
|
|
||||||
from importlib import import_module
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from sqlmodel import Session, select
|
|
||||||
|
|
||||||
SEMESTRES = ["2025-S1", "2025-S2"]
|
SEMESTRES = ["2025-S1", "2025-S2"]
|
||||||
MESES = ["2025-01", "2025-02", "2025-03"]
|
MESES = ["2025-01", "2025-02", "2025-03"]
|
||||||
|
|
||||||
|
|
||||||
def sembrar_base(proyecto: str, motor) -> None:
|
def sembrar_base(proyecto: str, motor) -> None:
|
||||||
"""Staging sintético del kit, tablas del kit, carga y el indicador de ejemplo calculado.
|
"""La base de demostración del kit: staging sintético, carga y todos los indicadores calculados.
|
||||||
|
|
||||||
Lo mismo que hace `indicadores_kit.tea.fixtures.base_de_prueba` para TEA,
|
Lo mismo que hace `indicadores_kit.tea.fixtures.base_de_prueba` para
|
||||||
con los pasos del kit: parámetros, `dim_periodo` (semestres y meses de
|
TEA: cada definición de `measures_de(proyecto)` queda calculada en los
|
||||||
2025) y `<proyecto>_eu8` en `SEMESTRES` y `MESES`.
|
periodos de 2025 que publica (`SEMESTRES`, y los doce meses si publica
|
||||||
|
meses).
|
||||||
"""
|
"""
|
||||||
from indicadores_kit.esquema import crear_esquema
|
from indicadores_kit.demostracion import base_de_prueba
|
||||||
from indicadores_kit.mart.calculo import calcular_measure
|
|
||||||
from indicadores_kit.registry.measures import leer_measure, ruta_de_measure
|
|
||||||
from indicadores_kit.registry.parametros import RUTA_PARAMETROS, cargar_parametros
|
|
||||||
from indicadores_kit.registry.periodos import generar_dim_periodo
|
|
||||||
from indicadores_kit.tablas import tablas_de
|
|
||||||
|
|
||||||
fixtures = import_module(f"indicadores_kit.{proyecto}.fixtures")
|
base_de_prueba(motor, proyecto)
|
||||||
etl = import_module(f"indicadores_kit.{proyecto}.etl")
|
|
||||||
base = import_module(f"core.{proyecto}.base")
|
|
||||||
modelos = import_module(f"core.{proyecto}.models")
|
|
||||||
tablas = tablas_de(proyecto)
|
|
||||||
|
|
||||||
getattr(base, "CaCuModel" if proyecto == "cacu" else "CaMaModel").metadata.create_all(motor)
|
|
||||||
crear_esquema(motor, proyecto)
|
|
||||||
cargar, tabla = (
|
|
||||||
(etl.cargar_citologias, modelos.CitologiaCervical)
|
|
||||||
if proyecto == "cacu"
|
|
||||||
else (etl.cargar_mastografias, modelos.Mastografia)
|
|
||||||
)
|
|
||||||
with Session(motor) as sesion:
|
|
||||||
fixtures.insertar(sesion)
|
|
||||||
cargar(
|
|
||||||
sesion,
|
|
||||||
sesion.exec(select(modelos.Paciente)).all(),
|
|
||||||
sesion.exec(select(tabla)).all(),
|
|
||||||
)
|
|
||||||
cargar_parametros(sesion, RUTA_PARAMETROS, tablas=tablas)
|
|
||||||
generar_dim_periodo(sesion, 2025, 2025, tablas=tablas, tipos=("semestre", "mes"))
|
|
||||||
medida = leer_measure(ruta_de_measure(proyecto, f"{proyecto}_eu8"))
|
|
||||||
for periodo in SEMESTRES + MESES:
|
|
||||||
calcular_measure(sesion, medida, periodo, tablas=tablas, permitir_sin_definir=True)
|
|
||||||
|
|
||||||
|
|
||||||
def cliente_de(proyecto: str, tmp_path_factory):
|
def cliente_de(proyecto: str, tmp_path_factory):
|
||||||
|
|||||||
+161
-11
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from conftest import MESES, SEMESTRES, cliente_de
|
from conftest import MESES, SEMESTRES, cliente_de
|
||||||
from indicadores_kit.registry.measures import measures_de
|
from indicadores_kit.registry.measures import RAIZ, measures_de
|
||||||
from indicadores_kit.serving.figuras import figuras_de
|
from indicadores_kit.serving.figuras import figuras_de
|
||||||
|
|
||||||
PROYECTO = "cacu"
|
PROYECTO = "cacu"
|
||||||
INDICADOR = "cacu_eu8"
|
INDICADOR = "ind1"
|
||||||
DEFINICIONES = measures_de(PROYECTO)
|
DEFINICIONES = measures_de(PROYECTO)
|
||||||
(FIGURA,) = figuras_de(DEFINICIONES[INDICADOR])
|
(FIGURA,) = figuras_de(DEFINICIONES[INDICADOR])
|
||||||
|
|
||||||
@@ -29,13 +29,33 @@ def test_listar_indicadores(client):
|
|||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
lista = response.get_json()
|
lista = response.get_json()
|
||||||
assert [fila["id"] for fila in lista] == sorted(DEFINICIONES)
|
visibles = [id_ for id_, medida in DEFINICIONES.items() if not medida.extension.publicacion.oculto]
|
||||||
fila = next(fila for fila in lista if fila["id"] == INDICADOR)
|
assert [fila["id"] for fila in lista] == sorted(visibles)
|
||||||
medida = DEFINICIONES[INDICADOR]
|
for fila in lista:
|
||||||
assert fila["titulo"] == medida.title
|
medida = DEFINICIONES[fila["id"]]
|
||||||
assert fila["contrato"] == medida.extension.contrato
|
assert fila["titulo"] == medida.title
|
||||||
assert fila["figuras"] == figuras_de(medida) == [FIGURA]
|
assert fila["contrato"] == medida.extension.contrato
|
||||||
assert fila["tipos_periodo"] == ["semestre", "mes"]
|
assert fila["figuras"] == figuras_de(medida)
|
||||||
|
assert fila["tipos_periodo"] == ["semestre", "mes"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_los_ocultos_no_salen_en_el_catalogo_pero_responden(client):
|
||||||
|
"""Provisional (oct 2026): cacu_eu7_anormal no se muestra; cacu_riesgo_banda, hasta MD-Q5."""
|
||||||
|
ocultos = {"cacu_eu7_anormal", "cacu_riesgo_banda"}
|
||||||
|
ids = {fila["id"] for fila in client.get(f"/{PROYECTO}/indicadores").get_json()}
|
||||||
|
|
||||||
|
assert ids == set(DEFINICIONES) - ocultos
|
||||||
|
for indicador in ocultos:
|
||||||
|
assert client.get(f"/{PROYECTO}/indicadores/{indicador}/metadatos").status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_un_indicador_retirado_da_404(client):
|
||||||
|
"""T-22a (ADR-MD-009): los retirados (`<proyecto>/retirados/` del kit) ni se calculan ni se sirven."""
|
||||||
|
retirados = [ruta.stem for ruta in (RAIZ / PROYECTO / "retirados").glob("*.toml")]
|
||||||
|
|
||||||
|
assert retirados
|
||||||
|
for indicador in retirados:
|
||||||
|
assert client.get(f"/{PROYECTO}/indicadores/{indicador}/metadatos").status_code == 404
|
||||||
|
|
||||||
|
|
||||||
def test_figura_con_semestres(client):
|
def test_figura_con_semestres(client):
|
||||||
@@ -85,11 +105,11 @@ def test_figura_con_parametros_mal_formados_da_400(client, query):
|
|||||||
("indicador", "figura", "query"),
|
("indicador", "figura", "query"),
|
||||||
[
|
[
|
||||||
("CACU_NO_EXISTE", FIGURA, ""),
|
("CACU_NO_EXISTE", FIGURA, ""),
|
||||||
(INDICADOR, "fig_c2_apiladas", ""), # figura de otro contrato
|
(INDICADOR, "fig_c3r_caja", ""), # figura de otro contrato
|
||||||
(INDICADOR, "fig_no_existe", ""),
|
(INDICADOR, "fig_no_existe", ""),
|
||||||
(INDICADOR, FIGURA, "?periodos=2030-S1"), # sin reporte
|
(INDICADOR, FIGURA, "?periodos=2030-S1"), # sin reporte
|
||||||
(INDICADOR, FIGURA, "?periodos=2025-S1,2030-S2"),
|
(INDICADOR, FIGURA, "?periodos=2025-S1,2030-S2"),
|
||||||
(INDICADOR, FIGURA, "?periodos=2025-11"), # un mes sin reporte
|
(INDICADOR, FIGURA, "?periodos=2024-11"), # un mes sin reporte
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
||||||
@@ -108,3 +128,133 @@ def test_un_keyerror_interno_no_se_vuelve_404(client, monkeypatch):
|
|||||||
monkeypatch.setattr(indicadores, "figura_json", falla)
|
monkeypatch.setattr(indicadores, "figura_json", falla)
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
_figura(client, query="?periodos=2025-S1")
|
_figura(client, query="?periodos=2025-S1")
|
||||||
|
|
||||||
|
|
||||||
|
# --- Todos los indicadores del proyecto ---
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
||||||
|
def test_figura_de_cada_indicador(client, indicador):
|
||||||
|
for figura in figuras_de(DEFINICIONES[indicador]):
|
||||||
|
response = _figura(client, indicador, figura)
|
||||||
|
|
||||||
|
assert response.status_code == 200, (indicador, figura)
|
||||||
|
assert set(response.get_json()) >= {"data", "layout"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_una_distribucion_sin_periodos_es_la_del_semestre_mas_reciente(client):
|
||||||
|
assert figuras_de(DEFINICIONES["cacu_eu7"]) == ["fig_c2_barras", "fig_c2_donas"]
|
||||||
|
|
||||||
|
por_defecto = _figura(client, "cacu_eu7", "fig_c2_donas")
|
||||||
|
del_ultimo = _figura(client, "cacu_eu7", "fig_c2_donas", f"?periodos={SEMESTRES[-1]}")
|
||||||
|
de_todos = _figura(client, "cacu_eu7", "fig_c2_donas", f"?periodos={','.join(SEMESTRES)}")
|
||||||
|
|
||||||
|
assert por_defecto.get_json() == del_ultimo.get_json()
|
||||||
|
assert len(de_todos.get_json()["data"]) == len(SEMESTRES) * len(por_defecto.get_json()["data"])
|
||||||
|
|
||||||
|
|
||||||
|
# --- El catálogo, los periodos, los datos y los metadatos ---
|
||||||
|
|
||||||
|
CATALOGO = {"id", "titulo", "version", "contrato", "unidad", "sentido", "tipos_periodo", "figuras", "estratos"}
|
||||||
|
|
||||||
|
|
||||||
|
def _ruta(client, indicador: str, ruta: str, query: str = ""):
|
||||||
|
return client.get(f"/{PROYECTO}/indicadores/{indicador}/{ruta}{query}")
|
||||||
|
|
||||||
|
|
||||||
|
def test_el_catalogo_trae_lo_necesario_para_pedir_lo_demas(client):
|
||||||
|
lista = client.get(f"/{PROYECTO}/indicadores").get_json()
|
||||||
|
|
||||||
|
assert all(set(fila) == CATALOGO for fila in lista)
|
||||||
|
for fila in lista:
|
||||||
|
medida = DEFINICIONES[fila["id"]]
|
||||||
|
assert (fila["version"], fila["unidad"], fila["sentido"]) == (medida.version, medida.basis, medida.improvementNotation)
|
||||||
|
assert fila["estratos"] == medida.extension.estratos
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
||||||
|
def test_periodos_datos_y_metadatos_de_cada_indicador(client, indicador):
|
||||||
|
medida = DEFINICIONES[indicador]
|
||||||
|
|
||||||
|
periodos = _ruta(client, indicador, "periodos")
|
||||||
|
datos = _ruta(client, indicador, "datos")
|
||||||
|
metadatos = _ruta(client, indicador, "metadatos")
|
||||||
|
|
||||||
|
assert (periodos.status_code, datos.status_code, metadatos.status_code) == (200, 200, 200)
|
||||||
|
assert all(r.mimetype == "application/json" for r in (periodos, datos, metadatos))
|
||||||
|
assert all(r.get_json()["id"] == indicador for r in (periodos, datos, metadatos))
|
||||||
|
de_semestre = [p["periodo"] for p in periodos.get_json()["periodos"] if p["tipo"] == "semestre"]
|
||||||
|
assert de_semestre == SEMESTRES
|
||||||
|
cuerpo = datos.get_json()
|
||||||
|
assert (cuerpo["contrato"], cuerpo["tipo_periodo"], cuerpo["periodos"]) == (medida.extension.contrato, "semestre", SEMESTRES)
|
||||||
|
assert cuerpo["filas"] and all(fila["estrato"] is None for fila in cuerpo["filas"])
|
||||||
|
assert {fila["grupo"] for fila in cuerpo["filas"]} <= set(cuerpo["grupos"])
|
||||||
|
assert "data" not in cuerpo and "layout" not in cuerpo # no es una figura
|
||||||
|
assert metadatos.get_json()["tipo_calculo"] == medida.scoring
|
||||||
|
|
||||||
|
|
||||||
|
def test_datos_con_meses(client):
|
||||||
|
response = _ruta(client, INDICADOR, "datos", f"?periodos={','.join(MESES)}")
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.get_json()["tipo_periodo"] == "mes"
|
||||||
|
assert [fila["periodo"] for fila in response.get_json()["filas"]] == MESES
|
||||||
|
|
||||||
|
|
||||||
|
def test_los_datos_dicen_de_que_reporte_salen(client):
|
||||||
|
cuerpo = _ruta(client, INDICADOR, "datos", "?periodos=2025-S1").get_json()
|
||||||
|
periodos = _ruta(client, INDICADOR, "periodos").get_json()["periodos"]
|
||||||
|
|
||||||
|
(reporte,) = cuerpo["reportes"]
|
||||||
|
assert reporte["report_id"] == next(p["report_id"] for p in periodos if p["periodo"] == "2025-S1")
|
||||||
|
assert (reporte["periodo_inicio"], reporte["periodo_fin"]) == ("2025-01-01", "2025-07-01")
|
||||||
|
assert cuerpo["version"] == DEFINICIONES[INDICADOR].version
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("query", ["?periodos=2025-S3", "?periodos=2025-S1,2025-03", "?estrato=no_existe"])
|
||||||
|
def test_datos_con_parametros_mal_formados_da_400(client, query):
|
||||||
|
response = _ruta(client, INDICADOR, "datos", query)
|
||||||
|
|
||||||
|
assert response.status_code == 400
|
||||||
|
assert "error" in response.get_json()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("indicador", "ruta", "query"),
|
||||||
|
[
|
||||||
|
("NO_EXISTE", "datos", ""),
|
||||||
|
("NO_EXISTE", "periodos", ""),
|
||||||
|
("NO_EXISTE", "metadatos", ""),
|
||||||
|
(INDICADOR, "datos", "?periodos=2030-S1"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_un_indicador_desconocido_o_un_periodo_sin_reporte_da_404(client, indicador, ruta, query):
|
||||||
|
response = _ruta(client, indicador, ruta, query)
|
||||||
|
|
||||||
|
assert response.status_code == 404
|
||||||
|
assert "error" in response.get_json()
|
||||||
|
|
||||||
|
|
||||||
|
# --- Los filtros (T-19f) ---
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("query", ["?filtro=grupo_edad", "?filtro=:25-34", "?filtro=grupo_edad:25-34,grupo_edad:35-44",
|
||||||
|
"?filtro=grupo_edad:25-34", "?filtro=ronda:1"])
|
||||||
|
def test_un_filtro_mal_escrito_o_no_declarado_da_400(client, query):
|
||||||
|
"""Ningún indicador vivo declara filtros todavía: todo `?filtro=` da 400, en datos y en figuras."""
|
||||||
|
for response in (_ruta(client, INDICADOR, "datos", query), _figura(client, query=query)):
|
||||||
|
assert response.status_code == 400
|
||||||
|
assert "error" in response.get_json()
|
||||||
|
|
||||||
|
|
||||||
|
def test_sin_filtro_los_datos_no_traen_la_llave_filtros(client):
|
||||||
|
assert "filtros" not in _ruta(client, INDICADOR, "datos").get_json()
|
||||||
|
|
||||||
|
|
||||||
|
def test_los_filtros_se_leen_como_estrato_y_valor():
|
||||||
|
from webapi.indicadores import filtros_pedidos
|
||||||
|
|
||||||
|
assert filtros_pedidos(None) == {} and filtros_pedidos("") == {}
|
||||||
|
assert filtros_pedidos("grupo_edad:25-34,ronda:1") == {"grupo_edad": "25-34", "ronda": "1"}
|
||||||
|
with pytest.raises(ValueError, match="mal escrito"):
|
||||||
|
filtros_pedidos("grupo_edad")
|
||||||
|
|||||||
+130
-11
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from conftest import MESES, SEMESTRES, cliente_de
|
from conftest import MESES, SEMESTRES, cliente_de
|
||||||
from indicadores_kit.registry.measures import measures_de
|
from indicadores_kit.registry.measures import RAIZ, measures_de
|
||||||
from indicadores_kit.serving.figuras import figuras_de
|
from indicadores_kit.serving.figuras import figuras_de
|
||||||
|
|
||||||
PROYECTO = "cama"
|
PROYECTO = "cama"
|
||||||
INDICADOR = "cama_eu8"
|
INDICADOR = "cama_confirmacion_birads45"
|
||||||
DEFINICIONES = measures_de(PROYECTO)
|
DEFINICIONES = measures_de(PROYECTO)
|
||||||
(FIGURA,) = figuras_de(DEFINICIONES[INDICADOR])
|
(FIGURA,) = figuras_de(DEFINICIONES[INDICADOR])
|
||||||
|
|
||||||
@@ -29,13 +29,38 @@ def test_listar_indicadores(client):
|
|||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
lista = response.get_json()
|
lista = response.get_json()
|
||||||
assert [fila["id"] for fila in lista] == sorted(DEFINICIONES)
|
visibles = [id_ for id_, medida in DEFINICIONES.items() if not medida.extension.publicacion.oculto]
|
||||||
fila = next(fila for fila in lista if fila["id"] == INDICADOR)
|
assert [fila["id"] for fila in lista] == sorted(visibles)
|
||||||
medida = DEFINICIONES[INDICADOR]
|
for fila in lista:
|
||||||
assert fila["titulo"] == medida.title
|
medida = DEFINICIONES[fila["id"]]
|
||||||
assert fila["contrato"] == medida.extension.contrato
|
assert fila["titulo"] == medida.title
|
||||||
assert fila["figuras"] == figuras_de(medida) == [FIGURA]
|
assert fila["contrato"] == medida.extension.contrato
|
||||||
assert fila["tipos_periodo"] == ["semestre", "mes"]
|
assert fila["figuras"] == figuras_de(medida)
|
||||||
|
assert fila["tipos_periodo"] == ["semestre", "mes"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_los_ocultos_no_salen_en_el_catalogo_pero_responden(client):
|
||||||
|
"""Provisional (oct 2026): cama_birads no se muestra.
|
||||||
|
|
||||||
|
cama_birads lo sustituyen cama_birads_456_paciente y cama_birads_456_mastografia.
|
||||||
|
cama_confirmacion_birads45 vuelve a mostrarse: su tarjeta destacada y su
|
||||||
|
gráfica de tendencia (usuario, 2026-10-16).
|
||||||
|
"""
|
||||||
|
ocultos = {"cama_birads"} # cama_riesgo_banda es propuesta desde T-21h: no se calcula ni se sirve
|
||||||
|
ids = {fila["id"] for fila in client.get(f"/{PROYECTO}/indicadores").get_json()}
|
||||||
|
|
||||||
|
assert ids == set(DEFINICIONES) - ocultos
|
||||||
|
for indicador in ocultos:
|
||||||
|
assert client.get(f"/{PROYECTO}/indicadores/{indicador}/metadatos").status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_un_indicador_retirado_da_404(client):
|
||||||
|
"""T-22a (ADR-MD-009): los retirados (`<proyecto>/retirados/` del kit) ni se calculan ni se sirven."""
|
||||||
|
retirados = [ruta.stem for ruta in (RAIZ / PROYECTO / "retirados").glob("*.toml")]
|
||||||
|
|
||||||
|
assert retirados
|
||||||
|
for indicador in retirados:
|
||||||
|
assert client.get(f"/{PROYECTO}/indicadores/{indicador}/metadatos").status_code == 404
|
||||||
|
|
||||||
|
|
||||||
def test_figura_con_semestres(client):
|
def test_figura_con_semestres(client):
|
||||||
@@ -85,11 +110,11 @@ def test_figura_con_parametros_mal_formados_da_400(client, query):
|
|||||||
("indicador", "figura", "query"),
|
("indicador", "figura", "query"),
|
||||||
[
|
[
|
||||||
("CAMA_NO_EXISTE", FIGURA, ""),
|
("CAMA_NO_EXISTE", FIGURA, ""),
|
||||||
(INDICADOR, "fig_c2_apiladas", ""), # figura de otro contrato
|
(INDICADOR, "fig_c3r_caja", ""), # figura de otro contrato
|
||||||
(INDICADOR, "fig_no_existe", ""),
|
(INDICADOR, "fig_no_existe", ""),
|
||||||
(INDICADOR, FIGURA, "?periodos=2030-S1"), # sin reporte
|
(INDICADOR, FIGURA, "?periodos=2030-S1"), # sin reporte
|
||||||
(INDICADOR, FIGURA, "?periodos=2025-S1,2030-S2"),
|
(INDICADOR, FIGURA, "?periodos=2025-S1,2030-S2"),
|
||||||
(INDICADOR, FIGURA, "?periodos=2025-11"), # un mes sin reporte
|
(INDICADOR, FIGURA, "?periodos=2024-11"), # un mes sin reporte
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
||||||
@@ -108,3 +133,97 @@ def test_un_keyerror_interno_no_se_vuelve_404(client, monkeypatch):
|
|||||||
monkeypatch.setattr(indicadores, "figura_json", falla)
|
monkeypatch.setattr(indicadores, "figura_json", falla)
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
_figura(client, query="?periodos=2025-S1")
|
_figura(client, query="?periodos=2025-S1")
|
||||||
|
|
||||||
|
|
||||||
|
# --- Todos los indicadores del proyecto ---
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
||||||
|
def test_figura_de_cada_indicador(client, indicador):
|
||||||
|
for figura in figuras_de(DEFINICIONES[indicador]):
|
||||||
|
response = _figura(client, indicador, figura)
|
||||||
|
|
||||||
|
assert response.status_code == 200, (indicador, figura)
|
||||||
|
assert set(response.get_json()) >= {"data", "layout"}
|
||||||
|
|
||||||
|
|
||||||
|
# --- El catálogo, los periodos, los datos y los metadatos ---
|
||||||
|
|
||||||
|
CATALOGO = {"id", "titulo", "version", "contrato", "unidad", "sentido", "tipos_periodo", "figuras", "estratos"}
|
||||||
|
|
||||||
|
|
||||||
|
def _ruta(client, indicador: str, ruta: str, query: str = ""):
|
||||||
|
return client.get(f"/{PROYECTO}/indicadores/{indicador}/{ruta}{query}")
|
||||||
|
|
||||||
|
|
||||||
|
def test_el_catalogo_trae_lo_necesario_para_pedir_lo_demas(client):
|
||||||
|
lista = client.get(f"/{PROYECTO}/indicadores").get_json()
|
||||||
|
|
||||||
|
assert all(set(fila) == CATALOGO for fila in lista)
|
||||||
|
for fila in lista:
|
||||||
|
medida = DEFINICIONES[fila["id"]]
|
||||||
|
assert (fila["version"], fila["unidad"], fila["sentido"]) == (medida.version, medida.basis, medida.improvementNotation)
|
||||||
|
assert fila["estratos"] == medida.extension.estratos
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
||||||
|
def test_periodos_datos_y_metadatos_de_cada_indicador(client, indicador):
|
||||||
|
medida = DEFINICIONES[indicador]
|
||||||
|
|
||||||
|
periodos = _ruta(client, indicador, "periodos")
|
||||||
|
datos = _ruta(client, indicador, "datos")
|
||||||
|
metadatos = _ruta(client, indicador, "metadatos")
|
||||||
|
|
||||||
|
assert (periodos.status_code, datos.status_code, metadatos.status_code) == (200, 200, 200)
|
||||||
|
assert all(r.mimetype == "application/json" for r in (periodos, datos, metadatos))
|
||||||
|
assert all(r.get_json()["id"] == indicador for r in (periodos, datos, metadatos))
|
||||||
|
de_semestre = [p["periodo"] for p in periodos.get_json()["periodos"] if p["tipo"] == "semestre"]
|
||||||
|
assert de_semestre == SEMESTRES
|
||||||
|
cuerpo = datos.get_json()
|
||||||
|
assert (cuerpo["contrato"], cuerpo["tipo_periodo"], cuerpo["periodos"]) == (medida.extension.contrato, "semestre", SEMESTRES)
|
||||||
|
assert cuerpo["filas"] and all(fila["estrato"] is None for fila in cuerpo["filas"])
|
||||||
|
assert {fila["grupo"] for fila in cuerpo["filas"]} <= set(cuerpo["grupos"])
|
||||||
|
assert "data" not in cuerpo and "layout" not in cuerpo # no es una figura
|
||||||
|
assert metadatos.get_json()["tipo_calculo"] == medida.scoring
|
||||||
|
|
||||||
|
|
||||||
|
def test_datos_con_meses(client):
|
||||||
|
response = _ruta(client, INDICADOR, "datos", f"?periodos={','.join(MESES)}")
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.get_json()["tipo_periodo"] == "mes"
|
||||||
|
assert [fila["periodo"] for fila in response.get_json()["filas"]] == MESES
|
||||||
|
|
||||||
|
|
||||||
|
def test_los_datos_dicen_de_que_reporte_salen(client):
|
||||||
|
cuerpo = _ruta(client, INDICADOR, "datos", "?periodos=2025-S1").get_json()
|
||||||
|
periodos = _ruta(client, INDICADOR, "periodos").get_json()["periodos"]
|
||||||
|
|
||||||
|
(reporte,) = cuerpo["reportes"]
|
||||||
|
assert reporte["report_id"] == next(p["report_id"] for p in periodos if p["periodo"] == "2025-S1")
|
||||||
|
assert (reporte["periodo_inicio"], reporte["periodo_fin"]) == ("2025-01-01", "2025-07-01")
|
||||||
|
assert cuerpo["version"] == DEFINICIONES[INDICADOR].version
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("query", ["?periodos=2025-S3", "?periodos=2025-S1,2025-03", "?estrato=no_existe"])
|
||||||
|
def test_datos_con_parametros_mal_formados_da_400(client, query):
|
||||||
|
response = _ruta(client, INDICADOR, "datos", query)
|
||||||
|
|
||||||
|
assert response.status_code == 400
|
||||||
|
assert "error" in response.get_json()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("indicador", "ruta", "query"),
|
||||||
|
[
|
||||||
|
("NO_EXISTE", "datos", ""),
|
||||||
|
("NO_EXISTE", "periodos", ""),
|
||||||
|
("NO_EXISTE", "metadatos", ""),
|
||||||
|
(INDICADOR, "datos", "?periodos=2030-S1"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_un_indicador_desconocido_o_un_periodo_sin_reporte_da_404(client, indicador, ruta, query):
|
||||||
|
response = _ruta(client, indicador, ruta, query)
|
||||||
|
|
||||||
|
assert response.status_code == 404
|
||||||
|
assert "error" in response.get_json()
|
||||||
|
|||||||
+72
-18
@@ -1,5 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from indicadores_kit.registry.measures import measures_de
|
from indicadores_kit.registry.measures import RAIZ, measures_de
|
||||||
from indicadores_kit.serving.figuras import figuras_de
|
from indicadores_kit.serving.figuras import figuras_de
|
||||||
from indicadores_kit.tea import fixtures
|
from indicadores_kit.tea import fixtures
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ PERIODOS = ",".join(fixtures.PERIODOS)
|
|||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def client(tmp_path_factory):
|
def client(tmp_path_factory):
|
||||||
"""Una base de TEA temporal, con los 18 indicadores calculados, por `TEA_DATABASE_URL`."""
|
"""Una base de TEA temporal, con los 20 indicadores calculados (16 en el catálogo), por `TEA_DATABASE_URL`."""
|
||||||
# Dentro de la fixture: la configuración de Persistance se lee al importarla,
|
# Dentro de la fixture: la configuración de Persistance se lee al importarla,
|
||||||
# y test_app.py debe alcanzar a fijar CACU_DATABASE_URL antes.
|
# y test_app.py debe alcanzar a fijar CACU_DATABASE_URL antes.
|
||||||
from persistance.db import get_tea_engine
|
from persistance.db import get_tea_engine
|
||||||
@@ -42,7 +42,8 @@ def test_listar_indicadores(client):
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
lista = response.get_json()
|
lista = response.get_json()
|
||||||
assert [fila["id"] for fila in lista] == sorted(DEFINICIONES)
|
visibles = [id_ for id_, medida in DEFINICIONES.items() if not medida.extension.publicacion.oculto]
|
||||||
|
assert [fila["id"] for fila in lista] == sorted(visibles)
|
||||||
for fila in lista:
|
for fila in lista:
|
||||||
medida = DEFINICIONES[fila["id"]]
|
medida = DEFINICIONES[fila["id"]]
|
||||||
assert fila["titulo"] == medida.title
|
assert fila["titulo"] == medida.title
|
||||||
@@ -50,24 +51,39 @@ def test_listar_indicadores(client):
|
|||||||
assert fila["figuras"] == figuras_de(medida)
|
assert fila["figuras"] == figuras_de(medida)
|
||||||
|
|
||||||
|
|
||||||
|
def test_los_ocultos_no_salen_en_el_catalogo_pero_responden(client):
|
||||||
|
"""Provisional (oct 2026): solo se muestran M21, M22 y los tres destacados (M23 a M25)."""
|
||||||
|
visibles = {
|
||||||
|
"M21_diagnosticados_con_eeg",
|
||||||
|
"M22_diagnosticados_sin_eeg",
|
||||||
|
"M23_pacientes_evaluados",
|
||||||
|
"M24_confirmacion_diagnostico",
|
||||||
|
"M25_dias_mchat_diagnostico",
|
||||||
|
}
|
||||||
|
ids = {fila["id"] for fila in client.get("/tea/indicadores").get_json()}
|
||||||
|
|
||||||
|
assert ids == visibles
|
||||||
|
for oculto in sorted(set(DEFINICIONES) - visibles):
|
||||||
|
assert client.get(f"/tea/indicadores/{oculto}/metadatos").status_code == 200
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
||||||
def test_figura_de_cada_indicador(client, indicador):
|
def test_figura_de_cada_indicador(client, indicador):
|
||||||
(figura,) = figuras_de(DEFINICIONES[indicador])
|
for figura in figuras_de(DEFINICIONES[indicador]):
|
||||||
|
response = _figura(client, indicador, figura, f"?periodos={PERIODOS}&tema=oscuro")
|
||||||
|
|
||||||
response = _figura(client, indicador, figura, f"?periodos={PERIODOS}&tema=oscuro")
|
assert response.status_code == 200, figura
|
||||||
|
assert response.mimetype == "application/json"
|
||||||
assert response.status_code == 200
|
assert "data" in response.get_json()
|
||||||
assert response.mimetype == "application/json"
|
|
||||||
assert "data" in response.get_json()
|
|
||||||
|
|
||||||
|
|
||||||
def test_figura_sin_periodos_usa_todos_los_reportes(client):
|
def test_figura_sin_periodos_usa_todos_los_reportes(client):
|
||||||
(figura,) = figuras_de(DEFINICIONES["K01_evaluacion_3_meses"])
|
(figura,) = figuras_de(DEFINICIONES["M21_diagnosticados_con_eeg"])
|
||||||
|
|
||||||
response = _figura(client, "K01_evaluacion_3_meses", figura)
|
response = _figura(client, "M21_diagnosticados_con_eeg", figura)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.get_json()["layout"]["title"]["text"] == DEFINICIONES["K01_evaluacion_3_meses"].title
|
assert response.get_json()["layout"]["title"]["text"] == DEFINICIONES["M21_diagnosticados_con_eeg"].title
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -81,7 +97,7 @@ def test_figura_sin_periodos_usa_todos_los_reportes(client):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_figura_con_parametros_mal_formados_da_400(client, query):
|
def test_figura_con_parametros_mal_formados_da_400(client, query):
|
||||||
response = _figura(client, "K01_evaluacion_3_meses", "fig_c1_grupos", query)
|
response = _figura(client, "M21_diagnosticados_con_eeg", "fig_c1_grupos", query)
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert "error" in response.get_json()
|
assert "error" in response.get_json()
|
||||||
@@ -91,10 +107,10 @@ def test_figura_con_parametros_mal_formados_da_400(client, query):
|
|||||||
("indicador", "figura", "query"),
|
("indicador", "figura", "query"),
|
||||||
[
|
[
|
||||||
("K99_no_existe", "fig_c1_grupos", ""),
|
("K99_no_existe", "fig_c1_grupos", ""),
|
||||||
("K01_evaluacion_3_meses", "fig_c2_apiladas", ""), # figura de otro contrato
|
("M21_diagnosticados_con_eeg", "fig_c3r_caja", ""), # figura de otro contrato
|
||||||
("K01_evaluacion_3_meses", "fig_no_existe", ""),
|
("M21_diagnosticados_con_eeg", "fig_no_existe", ""),
|
||||||
("K01_evaluacion_3_meses", "fig_c1_grupos", "?periodos=2030-S1"), # sin reporte
|
("M21_diagnosticados_con_eeg", "fig_c1_grupos", "?periodos=2030-S1"), # sin reporte
|
||||||
("K01_evaluacion_3_meses", "fig_c1_grupos", f"?periodos={PERIODOS},2030-S2"),
|
("M21_diagnosticados_con_eeg", "fig_c1_grupos", f"?periodos={PERIODOS},2030-S2"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
def test_figura_desconocida_o_sin_reporte_da_404(client, indicador, figura, query):
|
||||||
@@ -120,4 +136,42 @@ def test_un_keyerror_interno_no_se_vuelve_404(client, monkeypatch):
|
|||||||
|
|
||||||
monkeypatch.setattr(indicadores, "figura_json", falla)
|
monkeypatch.setattr(indicadores, "figura_json", falla)
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
_figura(client, "K01_evaluacion_3_meses", "fig_c1_grupos", "?periodos=2025-S1")
|
_figura(client, "M21_diagnosticados_con_eeg", "fig_c1_grupos", "?periodos=2025-S1")
|
||||||
|
|
||||||
|
|
||||||
|
# --- Los periodos, los datos y los metadatos ---
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("indicador", sorted(DEFINICIONES))
|
||||||
|
def test_periodos_datos_y_metadatos_de_cada_indicador(client, indicador):
|
||||||
|
medida = DEFINICIONES[indicador]
|
||||||
|
|
||||||
|
periodos = client.get(f"/tea/indicadores/{indicador}/periodos")
|
||||||
|
datos = client.get(f"/tea/indicadores/{indicador}/datos?periodos={PERIODOS}")
|
||||||
|
metadatos = client.get(f"/tea/indicadores/{indicador}/metadatos")
|
||||||
|
|
||||||
|
assert (periodos.status_code, datos.status_code, metadatos.status_code) == (200, 200, 200)
|
||||||
|
assert [p["periodo"] for p in periodos.get_json()["periodos"]] == sorted(fixtures.PERIODOS)
|
||||||
|
cuerpo = datos.get_json()
|
||||||
|
assert (cuerpo["id"], cuerpo["contrato"]) == (indicador, medida.extension.contrato)
|
||||||
|
assert cuerpo["filas"] and {fila["periodo"] for fila in cuerpo["filas"]} == set(fixtures.PERIODOS)
|
||||||
|
assert {fila["grupo"] for fila in cuerpo["filas"]} <= set(cuerpo["grupos"])
|
||||||
|
assert "data" not in cuerpo and "layout" not in cuerpo # no es una figura
|
||||||
|
assert metadatos.get_json()["ficha"]["codigo"] == medida.extension.ficha.codigo
|
||||||
|
|
||||||
|
|
||||||
|
def test_los_grupos_de_los_datos_van_en_el_orden_de_la_ficha(client):
|
||||||
|
response = client.get(f"/tea/indicadores/M21_diagnosticados_con_eeg/datos?periodos={PERIODOS}")
|
||||||
|
|
||||||
|
grupos = list(response.get_json()["grupos"])
|
||||||
|
assert grupos != sorted(grupos) # el orden de la ficha, no el alfabético
|
||||||
|
assert grupos[-1] == "TOTAL"
|
||||||
|
|
||||||
|
|
||||||
|
def test_un_indicador_retirado_da_404(client):
|
||||||
|
"""T-22a (ADR-MD-009): los retirados (`tea/retirados/` del kit) ni se calculan ni se sirven."""
|
||||||
|
retirados = [ruta.stem for ruta in (RAIZ / "tea" / "retirados").glob("*.toml")]
|
||||||
|
|
||||||
|
assert len(retirados) == 18
|
||||||
|
for indicador in retirados:
|
||||||
|
assert client.get(f"/tea/indicadores/{indicador}/metadatos").status_code == 404
|
||||||
|
|||||||
+123
-24
@@ -2,20 +2,39 @@
|
|||||||
|
|
||||||
`registrar_indicadores` agrega a un blueprint:
|
`registrar_indicadores` agrega a un blueprint:
|
||||||
|
|
||||||
GET /indicadores lista de indicadores
|
GET /indicadores catálogo de indicadores
|
||||||
GET /indicadores/<id>/figuras/<figura>?periodos=&tema=
|
GET /indicadores/<id>/periodos periodos con reporte
|
||||||
|
GET /indicadores/<id>/datos?periodos=&estrato=&filtro= los números, sin figura
|
||||||
|
GET /indicadores/<id>/metadatos ficha metodológica
|
||||||
|
GET /indicadores/<id>/figuras/<figura>?periodos=&tema=&filtro=
|
||||||
|
|
||||||
Las definiciones salen del kit (`measures_de`) y las figuras de
|
Las definiciones salen del kit (`measures_de`), los datos de
|
||||||
|
`indicadores_kit.serving.datos` y las figuras de
|
||||||
`indicadores_kit.serving.figuras`; aquí solo se valida, se abre la sesión y
|
`indicadores_kit.serving.figuras`; aquí solo se valida, se abre la sesión y
|
||||||
se traducen los errores a códigos HTTP.
|
se traducen los errores a códigos HTTP. La forma de cada respuesta es un
|
||||||
|
contrato con el frontend: no se quita ni se renombra un campo.
|
||||||
|
|
||||||
|
`?filtro=estrato:valor[,estrato:valor]` (T-19f) cuenta lo mismo solo con las
|
||||||
|
unidades que tienen esos valores: el mismo contrato, y en `/datos` la llave
|
||||||
|
`filtros`. Solo se aceptan los filtros que el indicador declara
|
||||||
|
(`extension.filtros`) y los valores de su catálogo; si no, 400.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
|
||||||
from flask import Blueprint, Response, jsonify, request
|
from flask import Blueprint, Response, jsonify, request
|
||||||
from indicadores_kit.registry.measures import Measure, measures_de
|
from indicadores_kit.registry.measures import Measure, measures_de
|
||||||
from indicadores_kit.serving.figuras import TEMAS, figura_json, figuras_de, periodos_con_reporte
|
from indicadores_kit.serving.contratos import FiltroNoDeclarado
|
||||||
|
from indicadores_kit.serving.datos import datos_de, metadatos_de, periodos_de, resumen_de
|
||||||
|
from indicadores_kit.serving.figuras import (
|
||||||
|
TEMAS,
|
||||||
|
figura_json,
|
||||||
|
figuras_de,
|
||||||
|
periodos_con_reporte,
|
||||||
|
periodos_por_defecto,
|
||||||
|
)
|
||||||
from indicadores_kit.tablas import tablas_de
|
from indicadores_kit.tablas import tablas_de
|
||||||
from sqlmodel import Session
|
from sqlmodel import Session
|
||||||
|
|
||||||
@@ -36,11 +55,31 @@ def _error(mensaje: str, codigo: int):
|
|||||||
return jsonify({"error": mensaje}), codigo
|
return jsonify({"error": mensaje}), codigo
|
||||||
|
|
||||||
|
|
||||||
|
def _json(contenido) -> Response:
|
||||||
|
"""Sin `jsonify`, que ordena las llaves: grupos y categorías van en su orden de presentación."""
|
||||||
|
return Response(json.dumps(contenido, ensure_ascii=False), mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
def _tipo_de(periodo: str, tipos: list[str]) -> str | None:
|
def _tipo_de(periodo: str, tipos: list[str]) -> str | None:
|
||||||
"""El tipo, entre los que publica el indicador, al que pertenece el periodo (o `None`)."""
|
"""El tipo, entre los que publica el indicador, al que pertenece el periodo (o `None`)."""
|
||||||
return next((tipo for tipo in tipos if FORMATOS[tipo][0].fullmatch(periodo)), None)
|
return next((tipo for tipo in tipos if FORMATOS[tipo][0].fullmatch(periodo)), None)
|
||||||
|
|
||||||
|
|
||||||
|
def filtros_pedidos(texto: str | None) -> dict[str, str]:
|
||||||
|
"""`estrato:valor[,estrato:valor]` -> `{estrato: valor}`. Vacío si no se pidió; `ValueError` si viene mal escrito."""
|
||||||
|
if not texto:
|
||||||
|
return {}
|
||||||
|
filtros = {}
|
||||||
|
for parte in texto.split(","):
|
||||||
|
estrato, separador, valor = parte.partition(":")
|
||||||
|
if not separador or not estrato or not valor:
|
||||||
|
raise ValueError(f"filtro mal escrito {parte!r}; use estrato:valor")
|
||||||
|
if estrato in filtros:
|
||||||
|
raise ValueError(f"el filtro {estrato!r} va dos veces")
|
||||||
|
filtros[estrato] = valor
|
||||||
|
return filtros
|
||||||
|
|
||||||
|
|
||||||
def periodos_pedidos(texto: str | None, medida: Measure) -> tuple[list[str], str | None]:
|
def periodos_pedidos(texto: str | None, medida: Measure) -> tuple[list[str], str | None]:
|
||||||
"""Los periodos de `?periodos=` y su tipo. Sin parámetro (o vacío): `([], None)`.
|
"""Los periodos de `?periodos=` y su tipo. Sin parámetro (o vacío): `([], None)`.
|
||||||
|
|
||||||
@@ -64,7 +103,7 @@ def periodos_pedidos(texto: str | None, medida: Measure) -> tuple[list[str], str
|
|||||||
def registrar_indicadores(
|
def registrar_indicadores(
|
||||||
blueprint: Blueprint, proyecto: str, get_session: Callable[[], Session]
|
blueprint: Blueprint, proyecto: str, get_session: Callable[[], Session]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Agrega las dos rutas de indicadores de `proyecto` al blueprint.
|
"""Agrega las rutas de indicadores de `proyecto` al blueprint.
|
||||||
|
|
||||||
`get_session` es la fábrica de `Persistance` (`get_<proyecto>_session`):
|
`get_session` es la fábrica de `Persistance` (`get_<proyecto>_session`):
|
||||||
se llama en cada petición, no al registrar.
|
se llama en cada petición, no al registrar.
|
||||||
@@ -73,18 +112,74 @@ def registrar_indicadores(
|
|||||||
tablas = tablas_de(proyecto)
|
tablas = tablas_de(proyecto)
|
||||||
|
|
||||||
def listar_indicadores():
|
def listar_indicadores():
|
||||||
return jsonify(
|
# Los marcados `oculto` en su TOML no salen en el catálogo; su id sigue respondiendo.
|
||||||
[
|
return _json([
|
||||||
{
|
resumen_de(id_, medida)
|
||||||
"id": id_,
|
for id_, medida in definiciones.items()
|
||||||
"titulo": medida.title,
|
if not medida.extension.publicacion.oculto
|
||||||
"contrato": medida.extension.contrato,
|
])
|
||||||
"figuras": figuras_de(medida),
|
|
||||||
"tipos_periodo": medida.extension.publicacion.tipos_periodo,
|
def _periodos_o_los_que_haya(sesion: Session, medida: Measure, periodos: list[str]) -> list[str]:
|
||||||
}
|
"""Los pedidos; sin pedir ninguno, los que tienen reporte del primer tipo que publica."""
|
||||||
for id_, medida in definiciones.items()
|
if periodos:
|
||||||
]
|
return periodos
|
||||||
)
|
tipo = medida.extension.publicacion.tipos_periodo[0]
|
||||||
|
return periodos_con_reporte(sesion, medida, tablas=tablas, tipo=tipo)
|
||||||
|
|
||||||
|
def get_periodos(indicador: str):
|
||||||
|
medida = definiciones.get(indicador)
|
||||||
|
if medida is None:
|
||||||
|
return _error("indicador desconocido", 404)
|
||||||
|
sesion = get_session()
|
||||||
|
try:
|
||||||
|
periodos = periodos_de(sesion, medida, tablas=tablas)
|
||||||
|
finally:
|
||||||
|
sesion.close()
|
||||||
|
return _json({"id": indicador, "version": medida.version, "periodos": periodos})
|
||||||
|
|
||||||
|
def get_metadatos(indicador: str):
|
||||||
|
medida = definiciones.get(indicador)
|
||||||
|
if medida is None:
|
||||||
|
return _error("indicador desconocido", 404)
|
||||||
|
sesion = get_session()
|
||||||
|
try:
|
||||||
|
metadatos = metadatos_de(sesion, medida, tablas=tablas)
|
||||||
|
finally:
|
||||||
|
sesion.close()
|
||||||
|
return _json({"id": indicador, **metadatos})
|
||||||
|
|
||||||
|
def get_datos(indicador: str):
|
||||||
|
medida = definiciones.get(indicador)
|
||||||
|
if medida is None:
|
||||||
|
return _error("indicador desconocido", 404)
|
||||||
|
estrato = request.args.get("estrato") or None
|
||||||
|
if estrato is not None and estrato not in medida.extension.estratos:
|
||||||
|
return _error(
|
||||||
|
f"estrato desconocido {estrato!r}; este indicador tiene {medida.extension.estratos}",
|
||||||
|
400,
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
periodos, _ = periodos_pedidos(request.args.get("periodos"), medida)
|
||||||
|
filtros = filtros_pedidos(request.args.get("filtro"))
|
||||||
|
except ValueError as error:
|
||||||
|
return _error(str(error), 400)
|
||||||
|
|
||||||
|
sesion = get_session()
|
||||||
|
try:
|
||||||
|
periodos = _periodos_o_los_que_haya(sesion, medida, periodos)
|
||||||
|
if not periodos:
|
||||||
|
return _error("el indicador no tiene reportes calculados", 404)
|
||||||
|
datos = datos_de(sesion, medida, periodos, tablas=tablas, estrato=estrato, filtros=filtros or None)
|
||||||
|
except FiltroNoDeclarado as error:
|
||||||
|
return _error(str(error), 400)
|
||||||
|
except KeyError:
|
||||||
|
# KeyError también es LookupError: aquí es un error interno (500), no un periodo sin reporte.
|
||||||
|
raise
|
||||||
|
except LookupError as error:
|
||||||
|
return _error(str(error), 404)
|
||||||
|
finally:
|
||||||
|
sesion.close()
|
||||||
|
return _json({"id": indicador, **datos})
|
||||||
|
|
||||||
def get_figura(indicador: str, figura: str):
|
def get_figura(indicador: str, figura: str):
|
||||||
medida = definiciones.get(indicador)
|
medida = definiciones.get(indicador)
|
||||||
@@ -100,18 +195,19 @@ def registrar_indicadores(
|
|||||||
return _error(f"tema desconocido {tema!r}; use claro u oscuro", 400)
|
return _error(f"tema desconocido {tema!r}; use claro u oscuro", 400)
|
||||||
try:
|
try:
|
||||||
periodos, tipo = periodos_pedidos(request.args.get("periodos"), medida)
|
periodos, tipo = periodos_pedidos(request.args.get("periodos"), medida)
|
||||||
|
filtros = filtros_pedidos(request.args.get("filtro"))
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
return _error(str(error), 400)
|
return _error(str(error), 400)
|
||||||
|
|
||||||
sesion = get_session()
|
sesion = get_session()
|
||||||
try:
|
try:
|
||||||
|
# Sin pedir ninguno: todos, o solo el más reciente si la figura se lee en un periodo.
|
||||||
|
periodos = periodos or periodos_por_defecto(sesion, medida, figura, tablas=tablas)
|
||||||
if not periodos:
|
if not periodos:
|
||||||
# El primer tipo que publica el indicador.
|
return _error("el indicador no tiene reportes calculados", 404)
|
||||||
tipo = medida.extension.publicacion.tipos_periodo[0]
|
texto = figura_json(sesion, medida, periodos, figura, tablas=tablas, tema=tema, filtros=filtros or None)
|
||||||
periodos = periodos_con_reporte(sesion, medida, tablas=tablas, tipo=tipo)
|
except FiltroNoDeclarado as error:
|
||||||
if not periodos:
|
return _error(str(error), 400)
|
||||||
return _error("el indicador no tiene reportes calculados", 404)
|
|
||||||
texto = figura_json(sesion, medida, periodos, figura, tablas=tablas, tema=tema)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# KeyError también es LookupError: aquí es un error interno (500), no un periodo sin reporte.
|
# KeyError también es LookupError: aquí es un error interno (500), no un periodo sin reporte.
|
||||||
raise
|
raise
|
||||||
@@ -122,6 +218,9 @@ def registrar_indicadores(
|
|||||||
return Response(texto, mimetype="application/json")
|
return Response(texto, mimetype="application/json")
|
||||||
|
|
||||||
blueprint.add_url_rule("/indicadores", "listar_indicadores", listar_indicadores)
|
blueprint.add_url_rule("/indicadores", "listar_indicadores", listar_indicadores)
|
||||||
|
blueprint.add_url_rule("/indicadores/<indicador>/periodos", "get_periodos", get_periodos)
|
||||||
|
blueprint.add_url_rule("/indicadores/<indicador>/datos", "get_datos", get_datos)
|
||||||
|
blueprint.add_url_rule("/indicadores/<indicador>/metadatos", "get_metadatos", get_metadatos)
|
||||||
blueprint.add_url_rule(
|
blueprint.add_url_rule(
|
||||||
"/indicadores/<indicador>/figuras/<figura>", "get_figura", get_figura
|
"/indicadores/<indicador>/figuras/<figura>", "get_figura", get_figura
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user