Initial commit - dashboard leads
This commit is contained in:
62
backend/diag_caso_469.py
Normal file
62
backend/diag_caso_469.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# diag_caso_469.py - Investiga un telefono puntual: asignacion, respuesta, y
|
||||
# actividad de la asesora ese dia (para saber si estuvo o no de descanso).
|
||||
from datetime import datetime
|
||||
from data_manager_v2 import DataManager
|
||||
|
||||
TEL = "923306769" # telefono a investigar
|
||||
NOMBRE = "DIANA"
|
||||
DIA_OBJ = (2026, 8, 10)
|
||||
|
||||
dm = DataManager()
|
||||
|
||||
# 1) Todos los mensajes de ese contacto (asignaciones y respuestas), en hora Peru
|
||||
conn = dm.pg_conn(); cur = conn.cursor()
|
||||
cur.execute("""
|
||||
SELECT (m.created_at - INTERVAL '5 hours') AS fecha, m.id, m.sender_id, m.sender_type,
|
||||
LEFT(m.content, 70)
|
||||
FROM messages m
|
||||
JOIN conversations cv ON m.conversation_id = cv.id
|
||||
JOIN contacts c ON cv.contact_id = c.id
|
||||
WHERE REPLACE(REPLACE(c.phone_number,'+51',''),'+','') LIKE %s
|
||||
ORDER BY m.id ASC
|
||||
""", ('%'+TEL,))
|
||||
rows = cur.fetchall()
|
||||
print(f"\n=== Mensajes del contacto {TEL} (hora Peru) ===\n")
|
||||
print(f"{'fecha':20} {'msg_id':>9} {'sender_id':>9} {'tipo':8} contenido")
|
||||
print("-"*90)
|
||||
for fecha, mid, sid, stype, cont in rows:
|
||||
marca = " <- ASESOR" if (sid is not None and 15 <= sid <= 25) else ""
|
||||
stype = str(stype or "-"); sid_s = str(sid if sid is not None else "-")
|
||||
print(f"{str(fecha):26} {str(mid):>9} {sid_s:>9} {stype:8} {str(cont or '')[:40]}{marca}")
|
||||
|
||||
# 2) Que trajo el query de asignacion+respuesta para este telefono
|
||||
print(f"\n=== Lo que el dashboard tomo como T1 (asignacion) y T2 (respuesta) ===")
|
||||
for r in dm.traer_asignacion_respuesta():
|
||||
if str(r.get('telefono','')).endswith(TEL[-9:]):
|
||||
print(f" T1 asignacion = {r.get('created_at')}")
|
||||
print(f" T2 respuesta = {r.get('respuesta_fecha')}")
|
||||
print(f" asesor = {r.get('user_name')}")
|
||||
|
||||
# 3) Actividad de Diana ese dia (para saber si trabajo o descanso)
|
||||
print(f"\n=== Actividad de {NOMBRE} el {DIA_OBJ[2]:02d}/{DIA_OBJ[1]:02d}/{DIA_OBJ[0]} (mensajes enviados) ===")
|
||||
asig = dm.traer_asignacion_respuesta()
|
||||
uid_diana = None
|
||||
for r in asig:
|
||||
if NOMBRE in (r.get('user_name') or '').upper() and r.get('user_id') is not None:
|
||||
uid_diana = r['user_id']; break
|
||||
if uid_diana is None:
|
||||
print(" (no se hallo user_id de Diana)")
|
||||
else:
|
||||
hrs = []
|
||||
for a in dm.traer_actividad_asesores():
|
||||
ts = a.get('created_at')
|
||||
if a.get('user_id')==uid_diana and isinstance(ts,datetime) and \
|
||||
(ts.year,ts.month,ts.day)==DIA_OBJ:
|
||||
hrs.append(ts.strftime('%H:%M'))
|
||||
if not hrs:
|
||||
print(f" SIN actividad ese dia -> probablemente DESCANSO / no trabajo.")
|
||||
else:
|
||||
hrs.sort()
|
||||
print(f" {len(hrs)} mensajes. Primera: {hrs[0]} Ultima: {hrs[-1]}")
|
||||
print(f" (si hay actividad en la tarde 13-18 = turno 1; si en la noche = turno 2)")
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user