Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fecb0247d1 |
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user