Skip to content

Commit a179fb4

Browse files
committed
Parte 3
1 parent a85c14b commit a179fb4

1 file changed

Lines changed: 84 additions & 2 deletions

File tree

app.py

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,94 @@
122122
"requiere_reentrenamiento": True if score_empatia < 70 else False
123123
})
124124

125+
import plotly.express as px # Asegúrate de que esto esté arriba con los imports
126+
125127
# ==========================================
126-
# TAB 3: DASHBOARD (PARTE 3) - PROXIMAMENTE
128+
# TAB 3: DASHBOARD PREDICTIVO (PARTE 3)
127129
# ==========================================
128130
with tabs[2]:
129-
st.warning("🚧 Módulo de Dashboards Predictivos en construcción...")
131+
st.header("📊 Torre de Control de Formación")
132+
st.markdown("Visibilidad en tiempo real del estado de certificación y riesgo de fuga.")
133+
134+
# 1. GENERACIÓN DE DATOS (Simulamos conexión a Base de Datos)
135+
# Nota: En un caso real, esto vendría de SQL o BigQuery
136+
def obtener_data_analytics():
137+
data = []
138+
cohortes = ['Enero', 'Febrero', 'Marzo']
139+
for i in range(50):
140+
cohorte = random.choice(cohortes)
141+
nota = random.randint(50, 100)
142+
tiempo = random.randint(30, 180) # Minutos en plataforma
143+
144+
# Lógica de Riesgo (Business Intelligence)
145+
riesgo = "Bajo"
146+
if nota < 70: riesgo = "Medio"
147+
if nota < 60 and tiempo < 60: riesgo = "Crítico"
148+
149+
data.append({
150+
"Agente": f"AGT-{i:03d}",
151+
"Cohorte": cohorte,
152+
"Nota Final": nota,
153+
"Tiempo en Plataforma (min)": tiempo,
154+
"Nivel de Riesgo": riesgo,
155+
"Estado": "Certificado" if nota >= 80 else "En Proceso"
156+
})
157+
return pd.DataFrame(data)
158+
159+
df = obtener_data_analytics()
160+
161+
# 2. KPIs SUPERIORES (METRICAS CLAVE)
162+
kpi1, kpi2, kpi3, kpi4 = st.columns(4)
163+
164+
certificados = df[df["Estado"]=="Certificado"].shape[0]
165+
en_riesgo = df[df["Nivel de Riesgo"]=="Crítico"].shape[0]
166+
promedio_nota = df["Nota Final"].mean()
167+
168+
kpi1.metric("Total Agentes", len(df), "+5 nuevos")
169+
kpi2.metric("Tasa Certificación", f"{certificados/len(df)*100:.0f}%", "Objetivo: 85%")
170+
kpi3.metric("Riesgo de Fuga", en_riesgo, "-2 vs semana pasada", delta_color="inverse")
171+
kpi4.metric("Nota Promedio", f"{promedio_nota:.1f}", "+1.2 pts")
172+
173+
st.markdown("---")
174+
175+
# 3. GRÁFICOS INTERACTIVOS (PLOTLY)
176+
col_left, col_right = st.columns([2, 1])
177+
178+
with col_left:
179+
st.subheader("🔍 Matriz de Rendimiento vs. Dedicación")
180+
# Gráfico de Dispersión: Muestra correlación entre estudiar y aprobar
181+
fig_scatter = px.scatter(
182+
df,
183+
x="Tiempo en Plataforma (min)",
184+
y="Nota Final",
185+
color="Nivel de Riesgo",
186+
size="Nota Final",
187+
hover_data=["Agente", "Cohorte"],
188+
color_discrete_map={"Bajo": "#00CC96", "Medio": "#FFA15A", "Crítico": "#EF553B"},
189+
title="¿Quién está en riesgo de reprobar?"
190+
)
191+
st.plotly_chart(fig_scatter, use_container_width=True)
192+
193+
with col_right:
194+
st.subheader("👥 Estado por Cohorte")
195+
# Gráfico de Barras Apiladas
196+
fig_bar = px.bar(
197+
df,
198+
x="Cohorte",
199+
color="Estado",
200+
barmode="group",
201+
color_discrete_sequence=["#636EFA", "#AB63FA"],
202+
title="Avance de Grupos"
203+
)
204+
st.plotly_chart(fig_bar, use_container_width=True)
130205

206+
# 4. TABLA DE DETALLE CON ALERTAS
207+
st.subheader("🚨 Agentes que requieren atención inmediata (Top 5 Riesgo)")
208+
df_critical = df[df["Nivel de Riesgo"] == "Crítico"].head(5)
209+
st.dataframe(
210+
df_critical.style.applymap(lambda x: 'color: red' if x == 'Crítico' else '', subset=['Nivel de Riesgo']),
211+
use_container_width=True
212+
)
131213
# ==========================================
132214
# TAB 4: SIMULADOR GAMIFICADO (PARTE 4)
133215
# ==========================================

0 commit comments

Comments
 (0)