feat: Add poblacion_apta service to docker-compose, enhance API gateway for new service integration, and update README with service details. Introduce new database tables for poblacion_apta_jobs and poblacion_apta_rows, and implement functionality for handling cop/mod calculations in the cleaning service.
This commit is contained in:
@@ -160,3 +160,59 @@ def _apply_cop_mod_split(
|
||||
f"[OK] '{amount_col}' -> '{ccol}', '{mcol}' <- Separa COP/MOD "
|
||||
f"(fecha: '{fecha_column}')"
|
||||
)
|
||||
|
||||
|
||||
def _alloc_cop_mod_diff_column_name(existing: set[str]) -> str:
|
||||
"""Nombre único para la columna resultado (preferido: cop/mod)."""
|
||||
preferred = "cop/mod"
|
||||
if preferred not in existing:
|
||||
return preferred
|
||||
for i in range(2, 200):
|
||||
name = f"cop/mod_{i}"
|
||||
if name not in existing:
|
||||
return name
|
||||
raise ValueError("No se pudo asignar nombre de columna único para cop/mod.")
|
||||
|
||||
|
||||
def _apply_cop_mod_bruto_neto(
|
||||
result: pd.DataFrame,
|
||||
bruto_col: str,
|
||||
neto_col: str,
|
||||
log: list[str],
|
||||
) -> None:
|
||||
"""Crea columna ``cop/mod`` = valor bruto − valor neto."""
|
||||
if bruto_col not in result.columns:
|
||||
log.append(
|
||||
f"[WARN] COP/MOD (bruto−neto): columna bruto '{bruto_col}' no existe; se omite."
|
||||
)
|
||||
return
|
||||
if neto_col not in result.columns:
|
||||
log.append(
|
||||
f"[WARN] COP/MOD (bruto−neto): columna neto '{neto_col}' no existe; se omite."
|
||||
)
|
||||
return
|
||||
if bruto_col == neto_col:
|
||||
log.append(
|
||||
f"[WARN] COP/MOD (bruto−neto): bruto y neto son la misma columna '{bruto_col}'; se omite."
|
||||
)
|
||||
return
|
||||
|
||||
bruto_ser = result[bruto_col]
|
||||
neto_ser = result[neto_col]
|
||||
bruto_hint = _infer_decimal_hint_from_column(bruto_ser.astype(str))
|
||||
neto_hint = _infer_decimal_hint_from_column(neto_ser.astype(str))
|
||||
|
||||
out_col = _alloc_cop_mod_diff_column_name(set(result.columns))
|
||||
values: list[Any] = []
|
||||
for i in range(len(result)):
|
||||
bruto_i = _amount_cell_to_optional_int(bruto_ser.iloc[i], bruto_hint)
|
||||
neto_i = _amount_cell_to_optional_int(neto_ser.iloc[i], neto_hint)
|
||||
if bruto_i is None or neto_i is None:
|
||||
values.append("")
|
||||
continue
|
||||
values.append(bruto_i - neto_i)
|
||||
|
||||
result[out_col] = values
|
||||
log.append(
|
||||
f"[OK] '{out_col}' = '{bruto_col}' − '{neto_col}' <- COP/MOD (bruto − neto)"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user