"""FTS-REPARTO (web) · la fixture de la prueba tests/web/test_fondos_ue_empresa.Datos.test_reparto_y_sin_divulgar: las líneas ORIGINALES del FTS (csv.gz de la Comisión, leídos con el lector de segunda_ue.py, sin DuckDB ni fts_pj.parquet) de las celdas que cambian (NIF × ejercicio de priv/celdas_cambian.json), una fila por línea: nif, anio, importe (tal cual en el csv; vacío si está vacío) y aviso, el código del valor EXACTO de «Source of (estimated) detailed amount». Sin nombres, sin direcciones: solo el NIF de la sociedad. Un valor que no esté en la tabla, error. python3 fixture_reparto.py """ import csv import glob import gzip import io import json import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import segunda_ue as S # noqa: E402 # El valor exacto (sin espacios a los lados ni punto final) → código. Los diez de la copia del 13-nov. AVISOS = { "": "sin_aviso", "An estimated repartition for each beneficiary was available in our central accounting system. The actual share may evolve over the lifespan of a project": "estimado", "A repartition for each beneficiary was sourced from the grant management system at contract signature. The actual share may evolve over the lifespan of a project": "firma", "Actual payments made until the time of publication (provisional commitment). Subsequent payments consuming this commitment will not be included in the estimated repartition for each beneficiary": "pagos", "The total commitment amount was attributed to a single beneficiary or in cases involving a consortium, it is possible that only the invoicing party is displayed, even if there are multiple beneficiaries who are all jointly and severally liable towards the EU for the performance of the underlying contract": "un_beneficiario", "The repartition for each beneficiary was not available in our central accounting system at the time of publication. 100 % of the amount is displayed with the coordinator, which is usually the invoicing party. In case of consortium, all the contractors are all jointly and severally liable towards the EU for the performance of the underlying contract": "coordinador_100", "The repartition for each beneficiary was not available in our central accounting system at the time of publication. The total amount was divided by the number of beneficiaries in order to display a proportional repartition": "partes_iguales", "The repartition for each beneficiary was not available in our central accounting system at the time of publication": "no_disponible", "In compliance with Article 38(3)(d) of the Financial Regulation, the contract amount will remain undisclosed for at least the duration of the framework contract under which it was awarded": "sin_divulgar", } def main(): lote, celdas, sal = sys.argv[1:4] quiero = {(x["nif"], int(x["anio"])) for x in json.load(open(celdas, encoding="utf-8")) if int(x["f"]) == 0} filas, raros = [], {} for f in sorted(glob.glob(f"{lote}/raw/*_FTS_dataset_en.csv.gz")): raw = gzip.open(f).read() try: t = raw.decode("utf-8-sig") except UnicodeDecodeError: t = raw.decode("cp1252") r = csv.reader(io.StringIO(t)) cab = next(r) i_y, i_s = cab.index("Year"), cab.index("Source of (estimated) detailed amount") i_v = next(i for i, c in enumerate(cab) if c.startswith("VAT number")) i_a = next(i for i, c in enumerate(cab) if c.startswith("Beneficiary") and c.endswith("s contracted amount (EUR)")) for x in r: if len(x) != len(cab): continue n = S.nif_de_vat(x[i_v]) if not n or (n, int(x[i_y])) not in quiero: continue v = (x[i_s] or "").strip().rstrip(".").strip() if v not in AVISOS: raros[v[:120]] = raros.get(v[:120], 0) + 1 continue filas.append((n, int(x[i_y]), (x[i_a] or "").strip(), AVISOS[v])) if raros: raise SystemExit(f"valores de «Source of (estimated) detailed amount» sin código: {raros}") filas.sort() with open(sal, "w", newline="", encoding="utf-8") as fh: w = csv.writer(fh, lineterminator="\n") w.writerow(["nif", "anio", "importe", "aviso"]) w.writerows(filas) print(json.dumps({"celdas_pedidas": len(quiero), "celdas_con_lineas": len({(a, b) for a, b, _, _ in filas}), "lineas": len(filas), "por_aviso": {k: sum(1 for f in filas if f[3] == k) for k in sorted(set(AVISOS.values()))}}, ensure_ascii=False)) if __name__ == "__main__": main()