Initial commit - dashboard leads
This commit is contained in:
73
backend/diag_roas_faltantes_2026.py
Normal file
73
backend/diag_roas_faltantes_2026.py
Normal file
@@ -0,0 +1,73 @@
|
||||
"""
|
||||
Diagnostico ROAS por MES (2026): para cada mes, los conjuntos del Meta CSV que
|
||||
NO se suman en la matriz por sede (sin pauta / sin sede valida), con su importe.
|
||||
"""
|
||||
import services as S
|
||||
import leads_logic as L
|
||||
|
||||
ANO = "2026"
|
||||
SEDES = {"LIMA", "PIURA", "AREQUIPA", "TRUJILLO"}
|
||||
MESES = ["ENERO","FEBRERO","MARZO","ABRIL","MAYO","JUNIO","JULIO","AGOSTO",
|
||||
"SEPTIEMBRE","OCTUBRE","NOVIEMBRE","DICIEMBRE"]
|
||||
|
||||
conj_pauta = S._conjunto_pauta() # {pauta: [conjunto,...]}
|
||||
camp = S._campanias_sede_cargo() # {pauta: {sede, cargo}}
|
||||
|
||||
conj_sede = {}
|
||||
conj_pauta_map = {}
|
||||
for pauta, conjuntos in conj_pauta.items():
|
||||
sp = camp.get(str(pauta).strip())
|
||||
sede = " ".join(str((sp or {}).get("sede") or "").upper().split())
|
||||
for co in conjuntos:
|
||||
k = " ".join(str(co).split()).upper()
|
||||
conj_pauta_map[k] = str(pauta).strip()
|
||||
if sp and sede in SEDES:
|
||||
conj_sede[k] = sede
|
||||
|
||||
filas = S._meta_filas()
|
||||
|
||||
for mi in range(1, 13):
|
||||
mes = str(mi)
|
||||
sin_sumar = {}
|
||||
suma_ok = 0.0
|
||||
suma_falta = 0.0
|
||||
for f in filas:
|
||||
fx = L._to_date(f.get("inicio"))
|
||||
if not L._en_periodo(fx, ANO, mes, "TODOS"):
|
||||
continue
|
||||
k = " ".join(str(f.get("conjunto")).split()).upper()
|
||||
imp = float(f.get("importe") or 0.0)
|
||||
res = int(float(f.get("resultados") or 0.0))
|
||||
if k in conj_sede:
|
||||
suma_ok += imp
|
||||
continue
|
||||
if k not in conj_pauta_map:
|
||||
motivo = "SIN PAUTA"
|
||||
else:
|
||||
p = conj_pauta_map[k]
|
||||
sp = camp.get(p)
|
||||
motivo = (f"pauta '{p}' SIN campania" if not sp
|
||||
else f"pauta '{p}' sede='{sp.get('sede')}' (fuera de las 4)")
|
||||
d = sin_sumar.setdefault(k, {"importe": 0.0, "resultados": 0, "motivo": motivo})
|
||||
d["importe"] += imp
|
||||
d["resultados"] += res
|
||||
suma_falta += imp
|
||||
|
||||
# solo imprimir meses con algo de data
|
||||
if suma_ok == 0 and not sin_sumar:
|
||||
continue
|
||||
|
||||
print("=" * 100)
|
||||
print(f" {MESES[mi-1]} {ANO}")
|
||||
print("=" * 100)
|
||||
if sin_sumar:
|
||||
print(f"{'CONJUNTO':45} {'IMPORTE':>12} {'RESULTADOS':>12} MOTIVO")
|
||||
print("-" * 100)
|
||||
for k, d in sorted(sin_sumar.items(), key=lambda x: -x[1]["importe"]):
|
||||
print(f"{k[:45]:45} {('$'+format(d['importe'],',.2f')):>12} {d['resultados']:>12,} {d['motivo']}")
|
||||
else:
|
||||
print(" (sin conjuntos faltantes)")
|
||||
print("-" * 100)
|
||||
print(f"{'IMPORTE QUE SÍ SUMA (4 sedes)':45} {('$'+format(suma_ok,',.2f')):>12}")
|
||||
print(f"{'IMPORTE QUE NO SUMA (faltante)':45} {('$'+format(suma_falta,',.2f')):>12}")
|
||||
print(f" Conjuntos distintos sin sumar: {len(sin_sumar)}\n")
|
||||
Reference in New Issue
Block a user