"""RES-1 · 00 · descripción del satélite .cambios (sin variables explicativas): tipos, fuentes, fechas, causas, casado. Antes del pre-registro.""" import duckdb, json c = duckdb.connect(); x = c.execute x("SET threads=3; SET memory_limit='1500MB'; SET temp_directory='/w/tmp/duck'") C = "/d/unified_20261103.cambios/cambios.parquet" print(x(f"DESCRIBE SELECT * FROM '{C}'").fetchall()) R = {} R['por_fuente_tipo'] = x(f"""SELECT fuente, tipo, count(*), count(id_canonical), count(fecha), min(fecha), max(fecha) FROM '{C}' WHERE tipo IN ('resolucion','penalidad','extincion','otro') GROUP BY 1,2 ORDER BY 1,2""").fetchall() for r in R['por_fuente_tipo']: print(r) R['casado'] = x(f"""SELECT fuente, tipo, casado_via, count(*) FROM '{C}' WHERE tipo IN ('resolucion','penalidad') GROUP BY ALL ORDER BY ALL""").fetchall() for r in R['casado']: print(r) R['anio'] = x(f"""SELECT fuente, tipo, year(fecha) a, count(*) FROM '{C}' WHERE tipo IN ('resolucion','penalidad') GROUP BY ALL ORDER BY ALL""").fetchall() for r in R['anio']: print(r) R['tipo_fuente'] = x(f"""SELECT fuente, tipo, tipo_fuente, count(*) FROM '{C}' WHERE tipo IN ('resolucion','penalidad') GROUP BY ALL ORDER BY ALL""").fetchall() for r in R['tipo_fuente']: print(r) R['desc_regcon'] = x(f"""SELECT descripcion, count(*) FROM '{C}' WHERE fuente='VALENCIA' AND tipo='resolucion' GROUP BY 1 ORDER BY 2 DESC LIMIT 40""").fetchall() for r in R['desc_regcon']: print(r) R['desc_rpc'] = x(f"""SELECT left(descripcion,80), count(*) FROM '{C}' WHERE fuente='CATALUNYA' AND tipo='resolucion' GROUP BY 1 ORDER BY 2 DESC LIMIT 40""").fetchall() for r in R['desc_rpc']: print(r) R['fecha_es'] = x(f"""SELECT fuente, tipo, fecha_es, count(*) FROM '{C}' WHERE tipo IN ('resolucion','penalidad') GROUP BY ALL ORDER BY ALL""").fetchall() for r in R['fecha_es']: print(r) json.dump(R, open('/w/salidas/00_explora.json','w'), ensure_ascii=False, indent=1, default=str)