Spaces:
Sleeping
Sleeping
JACINTO VELASCO commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ st.set_page_config(
|
|
| 18 |
)
|
| 19 |
|
| 20 |
# =========================================================
|
| 21 |
-
# CSS: examen típico (blanco, limpio,
|
| 22 |
# =========================================================
|
| 23 |
st.markdown("""
|
| 24 |
<style>
|
|
@@ -30,26 +30,43 @@ html, body, [class*="css"] { font-family: ui-sans-serif, system-ui, -apple-syste
|
|
| 30 |
[data-testid="stSidebar"]{ background:#f8fafc; border-right:1px solid #e5e7eb; }
|
| 31 |
[data-testid="stSidebar"] > div { padding-top: 1rem; }
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
div.stButton > button, div.stFormSubmitButton > button {
|
| 35 |
background:#ffffff !important;
|
| 36 |
color:#111827 !important;
|
| 37 |
border:1px solid #d1d5db !important;
|
| 38 |
-
border-radius:
|
| 39 |
-
font-weight:
|
| 40 |
-
padding:0.
|
| 41 |
}
|
| 42 |
div.stButton > button:hover, div.stFormSubmitButton > button:hover {
|
| 43 |
background:#f9fafb !important;
|
| 44 |
}
|
| 45 |
|
| 46 |
-
/* Código
|
| 47 |
.stCodeBlock pre { background:#f3f4f6 !important; border:1px solid #e5e7eb !important; border-radius:12px !important; padding:14px !important; }
|
| 48 |
code { background:#f3f4f6 !important; border:1px solid #e5e7eb !important; border-radius:8px !important; padding:1px 6px !important; color:#111827 !important; }
|
| 49 |
|
| 50 |
-
/*
|
| 51 |
-
.
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
</style>
|
| 54 |
""", unsafe_allow_html=True)
|
| 55 |
|
|
@@ -110,7 +127,7 @@ def format_time(sec):
|
|
| 110 |
def analyze_questions(questions):
|
| 111 |
df = pd.DataFrame(questions)
|
| 112 |
total = len(df)
|
| 113 |
-
|
| 114 |
df["nivel"] = df.get("nivel", "básico").map(norm)
|
| 115 |
df["tipo"] = df.get("tipo", "General").fillna("General").astype(str).str.strip()
|
| 116 |
|
|
@@ -130,7 +147,7 @@ def perf_by_type(history):
|
|
| 130 |
df = pd.DataFrame(history)
|
| 131 |
g = df.groupby("tipo")["correct"].agg(Respondidas="count", Aciertos="sum").reset_index()
|
| 132 |
g["Tasa_%"] = (g["Aciertos"] / g["Respondidas"] * 100).round(1)
|
| 133 |
-
g = g.sort_values(["Tasa_%", "Respondidas"], ascending=[True, False]).rename(columns={"tipo":"Tipo"})
|
| 134 |
return g
|
| 135 |
|
| 136 |
# =========================================================
|
|
@@ -157,38 +174,41 @@ def main():
|
|
| 157 |
st.session_state.opts_cache = {}
|
| 158 |
|
| 159 |
# =====================================================
|
| 160 |
-
# TOP (
|
| 161 |
# =====================================================
|
| 162 |
-
st.title("Fundamentos de Programación y Computadores")
|
| 163 |
-
st.markdown("Simulacro de examen. Configura el examen en el panel izquierdo y responde las preguntas una a una.")
|
| 164 |
-
st.markdown(
|
|
|
|
|
|
|
|
|
|
| 165 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
| 166 |
|
| 167 |
# =====================================================
|
| 168 |
-
# SIDEBAR
|
| 169 |
# =====================================================
|
| 170 |
with st.sidebar:
|
|
|
|
| 171 |
st.header("Panel de control")
|
| 172 |
|
| 173 |
if not st.session_state.exam_active:
|
| 174 |
-
st.
|
| 175 |
|
| 176 |
niveles = sorted(set(norm(q.get("nivel", "básico")) for q in questions))
|
| 177 |
-
sel = st.multiselect("Dificultad:", niveles, default=niveles)
|
| 178 |
|
| 179 |
-
mode = st.radio("Longitud:", ["Rápido (10)", "Estándar (25)", "Completo (Todas)"])
|
| 180 |
|
| 181 |
filtered = [q for q in questions if norm(q.get("nivel", "básico")) in sel] if sel else []
|
| 182 |
limit = 10 if "10" in mode else 25 if "25" in mode else len(filtered)
|
| 183 |
-
st.caption(f"Preguntas que saldrán: {min(limit, len(filtered))}")
|
| 184 |
|
| 185 |
-
|
| 186 |
-
|
| 187 |
st.markdown("—")
|
| 188 |
-
st.caption("Distribución por tipo (banco completo)")
|
| 189 |
st.dataframe(by_type, use_container_width=True, hide_index=True, height=220)
|
| 190 |
|
| 191 |
-
if st.button("Comenzar", use_container_width=True):
|
| 192 |
if not sel:
|
| 193 |
st.error("Selecciona al menos una dificultad.")
|
| 194 |
elif not filtered:
|
|
@@ -207,46 +227,85 @@ def main():
|
|
| 207 |
st.rerun()
|
| 208 |
|
| 209 |
else:
|
| 210 |
-
# Durante examen
|
| 211 |
total_q = len(st.session_state.exam_pool)
|
| 212 |
current = st.session_state.current_idx
|
| 213 |
|
|
|
|
|
|
|
| 214 |
if st.session_state.start_time:
|
| 215 |
-
st.caption(f"Tiempo: {format_time(time.time() - st.session_state.start_time)}")
|
| 216 |
|
| 217 |
-
st.metric("Pregunta", f"{current + 1} / {total_q}")
|
| 218 |
|
| 219 |
answered = current
|
| 220 |
if answered > 0:
|
| 221 |
acc = st.session_state.score / answered * 100
|
| 222 |
-
st.metric("Tasa de acierto", f"{acc:.1f}%")
|
| 223 |
else:
|
| 224 |
-
st.metric("Tasa de acierto", "—")
|
| 225 |
|
| 226 |
-
# Mantener: rendimiento por tipo (sí)
|
| 227 |
if st.session_state.history:
|
| 228 |
st.markdown("—")
|
| 229 |
-
st.subheader("Rendimiento por tipo")
|
| 230 |
st.dataframe(perf_by_type(st.session_state.history), use_container_width=True, hide_index=True, height=220)
|
| 231 |
|
| 232 |
st.markdown("—")
|
| 233 |
-
if st.button("Terminar examen", use_container_width=True):
|
| 234 |
st.session_state.current_idx = total_q
|
| 235 |
st.rerun()
|
| 236 |
|
| 237 |
# =====================================================
|
| 238 |
-
# PANTALLA INICIAL
|
| 239 |
# =====================================================
|
| 240 |
if not st.session_state.exam_active:
|
|
|
|
| 241 |
st.markdown("""
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
| 248 |
-
st.
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
return
|
| 251 |
|
| 252 |
# =====================================================
|
|
@@ -255,10 +314,10 @@ def main():
|
|
| 255 |
if st.session_state.current_idx < len(st.session_state.exam_pool):
|
| 256 |
q = st.session_state.exam_pool[st.session_state.current_idx]
|
| 257 |
|
| 258 |
-
st.subheader(f"Pregunta {st.session_state.current_idx + 1}")
|
| 259 |
render_content(q["question"])
|
| 260 |
|
| 261 |
-
#
|
| 262 |
qkey = f"opts_{st.session_state.current_idx}"
|
| 263 |
if qkey not in st.session_state.opts_cache:
|
| 264 |
opts = list(enumerate(q["options"]))
|
|
@@ -268,8 +327,7 @@ def main():
|
|
| 268 |
opts = st.session_state.opts_cache[qkey]
|
| 269 |
labels = [o[1] for o in opts]
|
| 270 |
|
| 271 |
-
#
|
| 272 |
-
# 4 opciones alineadas a la izquierda (radio ya lo hace)
|
| 273 |
if f"sel_{st.session_state.current_idx}" not in st.session_state:
|
| 274 |
st.session_state[f"sel_{st.session_state.current_idx}"] = None
|
| 275 |
|
|
@@ -280,12 +338,11 @@ def main():
|
|
| 280 |
index=None if st.session_state[f"sel_{st.session_state.current_idx}"] is None else labels.index(st.session_state[f"sel_{st.session_state.current_idx}"]),
|
| 281 |
disabled=disabled
|
| 282 |
)
|
| 283 |
-
|
| 284 |
if sel_label is not None and not disabled:
|
| 285 |
st.session_state[f"sel_{st.session_state.current_idx}"] = sel_label
|
| 286 |
|
| 287 |
st.write("")
|
| 288 |
-
if st.button("Responder",
|
| 289 |
user_label = st.session_state.get(f"sel_{st.session_state.current_idx}", None)
|
| 290 |
if user_label is None:
|
| 291 |
st.warning("Selecciona una opción antes de responder.")
|
|
@@ -319,7 +376,7 @@ def main():
|
|
| 319 |
|
| 320 |
st.rerun()
|
| 321 |
|
| 322 |
-
#
|
| 323 |
if st.session_state.answered_current and st.session_state.last_result:
|
| 324 |
res = st.session_state.last_result
|
| 325 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
|
@@ -334,18 +391,18 @@ def main():
|
|
| 334 |
st.markdown(f"**Comentario:** {res['expl']}")
|
| 335 |
|
| 336 |
st.write("")
|
| 337 |
-
if st.button("Siguiente", use_container_width=False):
|
| 338 |
st.session_state.current_idx += 1
|
| 339 |
st.session_state.answered_current = False
|
| 340 |
st.session_state.last_result = None
|
| 341 |
st.rerun()
|
| 342 |
|
| 343 |
# =====================================================
|
| 344 |
-
# FINAL
|
| 345 |
# =====================================================
|
| 346 |
else:
|
| 347 |
st.balloons()
|
| 348 |
-
st.header("Resultados")
|
| 349 |
|
| 350 |
total_q = len(st.session_state.exam_pool)
|
| 351 |
score = st.session_state.score
|
|
@@ -353,26 +410,26 @@ def main():
|
|
| 353 |
elapsed = format_time(time.time() - st.session_state.start_time) if st.session_state.start_time else "—"
|
| 354 |
|
| 355 |
c1, c2, c3 = st.columns(3)
|
| 356 |
-
c1.metric("Nota", f"{score} / {total_q}")
|
| 357 |
-
c2.metric("Porcentaje", f"{perc:.1f}%")
|
| 358 |
-
c3.metric("Tiempo", elapsed)
|
| 359 |
|
| 360 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
| 361 |
|
| 362 |
-
st.subheader("Progreso del alumno (historial)")
|
| 363 |
if st.session_state.history:
|
| 364 |
dfh = pd.DataFrame(st.session_state.history)
|
| 365 |
dfh["Resultado"] = dfh["correct"].map(lambda x: "✅" if x else "❌")
|
| 366 |
show_cols = ["n", "Resultado", "nivel", "tipo", "respuesta_alumno", "respuesta_correcta"]
|
| 367 |
st.dataframe(dfh[show_cols], use_container_width=True, hide_index=True, height=380)
|
| 368 |
|
| 369 |
-
st.subheader("Rendimiento por tipo")
|
| 370 |
st.dataframe(perf_by_type(st.session_state.history), use_container_width=True, hide_index=True, height=260)
|
| 371 |
else:
|
| 372 |
st.caption("No hay historial.")
|
| 373 |
|
| 374 |
st.write("")
|
| 375 |
-
if st.button("Volver al inicio"
|
| 376 |
st.session_state.exam_active = False
|
| 377 |
st.rerun()
|
| 378 |
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
# =========================================================
|
| 21 |
+
# CSS: examen típico (blanco), sidebar limpio, detalles más vistosos (sin chillón)
|
| 22 |
# =========================================================
|
| 23 |
st.markdown("""
|
| 24 |
<style>
|
|
|
|
| 30 |
[data-testid="stSidebar"]{ background:#f8fafc; border-right:1px solid #e5e7eb; }
|
| 31 |
[data-testid="stSidebar"] > div { padding-top: 1rem; }
|
| 32 |
|
| 33 |
+
hr { border: none; border-top: 1px solid #e5e7eb; }
|
| 34 |
+
|
| 35 |
+
.small-muted { color:#6b7280; font-size:0.92rem; }
|
| 36 |
+
|
| 37 |
+
/* Botones sobrios pero con “vida” */
|
| 38 |
div.stButton > button, div.stFormSubmitButton > button {
|
| 39 |
background:#ffffff !important;
|
| 40 |
color:#111827 !important;
|
| 41 |
border:1px solid #d1d5db !important;
|
| 42 |
+
border-radius:12px !important;
|
| 43 |
+
font-weight:750 !important;
|
| 44 |
+
padding:0.60rem 0.95rem !important;
|
| 45 |
}
|
| 46 |
div.stButton > button:hover, div.stFormSubmitButton > button:hover {
|
| 47 |
background:#f9fafb !important;
|
| 48 |
}
|
| 49 |
|
| 50 |
+
/* Código VS Code light */
|
| 51 |
.stCodeBlock pre { background:#f3f4f6 !important; border:1px solid #e5e7eb !important; border-radius:12px !important; padding:14px !important; }
|
| 52 |
code { background:#f3f4f6 !important; border:1px solid #e5e7eb !important; border-radius:8px !important; padding:1px 6px !important; color:#111827 !important; }
|
| 53 |
|
| 54 |
+
/* “Tarjetitas” suaves en sidebar */
|
| 55 |
+
.sidebar-card{
|
| 56 |
+
background: #ffffff;
|
| 57 |
+
border: 1px solid #e5e7eb;
|
| 58 |
+
border-radius: 14px;
|
| 59 |
+
padding: 12px 12px;
|
| 60 |
+
margin: 8px 0 10px 0;
|
| 61 |
+
}
|
| 62 |
+
.py-badge{
|
| 63 |
+
display:inline-block;
|
| 64 |
+
padding: 6px 10px;
|
| 65 |
+
border-radius: 999px;
|
| 66 |
+
border: 1px solid #e5e7eb;
|
| 67 |
+
background: #ffffff;
|
| 68 |
+
font-weight: 800;
|
| 69 |
+
}
|
| 70 |
</style>
|
| 71 |
""", unsafe_allow_html=True)
|
| 72 |
|
|
|
|
| 127 |
def analyze_questions(questions):
|
| 128 |
df = pd.DataFrame(questions)
|
| 129 |
total = len(df)
|
| 130 |
+
|
| 131 |
df["nivel"] = df.get("nivel", "básico").map(norm)
|
| 132 |
df["tipo"] = df.get("tipo", "General").fillna("General").astype(str).str.strip()
|
| 133 |
|
|
|
|
| 147 |
df = pd.DataFrame(history)
|
| 148 |
g = df.groupby("tipo")["correct"].agg(Respondidas="count", Aciertos="sum").reset_index()
|
| 149 |
g["Tasa_%"] = (g["Aciertos"] / g["Respondidas"] * 100).round(1)
|
| 150 |
+
g = g.sort_values(["Tasa_%", "Respondidas"], ascending=[True, False]).rename(columns={"tipo": "Tipo"})
|
| 151 |
return g
|
| 152 |
|
| 153 |
# =========================================================
|
|
|
|
| 174 |
st.session_state.opts_cache = {}
|
| 175 |
|
| 176 |
# =====================================================
|
| 177 |
+
# TOP (simple y claro)
|
| 178 |
# =====================================================
|
| 179 |
+
st.title("🧠 Fundamentos de Programación y Computadores")
|
| 180 |
+
st.markdown("📝 **Simulacro de examen**. Configura el examen en el panel izquierdo y responde las preguntas una a una.")
|
| 181 |
+
st.markdown(
|
| 182 |
+
f"<p class='small-muted'>📌 Banco disponible: <b>{total}</b> preguntas · 🧩 <b>{len(by_type)}</b> tipos · 🎚️ <b>{len(by_level)}</b> niveles</p>",
|
| 183 |
+
unsafe_allow_html=True
|
| 184 |
+
)
|
| 185 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
| 186 |
|
| 187 |
# =====================================================
|
| 188 |
+
# SIDEBAR
|
| 189 |
# =====================================================
|
| 190 |
with st.sidebar:
|
| 191 |
+
st.markdown("<div class='py-badge'>🐍 Python</div>", unsafe_allow_html=True)
|
| 192 |
st.header("Panel de control")
|
| 193 |
|
| 194 |
if not st.session_state.exam_active:
|
| 195 |
+
st.markdown("<div class='sidebar-card'><b>⚙️ Configurar examen</b><br/><span class='small-muted'>Elige dificultad y longitud, y empieza.</span></div>", unsafe_allow_html=True)
|
| 196 |
|
| 197 |
niveles = sorted(set(norm(q.get("nivel", "básico")) for q in questions))
|
| 198 |
+
sel = st.multiselect("🎚️ Dificultad:", niveles, default=niveles)
|
| 199 |
|
| 200 |
+
mode = st.radio("⏳ Longitud:", ["Rápido (10)", "Estándar (25)", "Completo (Todas)"])
|
| 201 |
|
| 202 |
filtered = [q for q in questions if norm(q.get("nivel", "básico")) in sel] if sel else []
|
| 203 |
limit = 10 if "10" in mode else 25 if "25" in mode else len(filtered)
|
|
|
|
| 204 |
|
| 205 |
+
st.caption(f"📄 Preguntas que saldrán: **{min(limit, len(filtered))}**")
|
| 206 |
+
|
| 207 |
st.markdown("—")
|
| 208 |
+
st.caption("🧩 Distribución por tipo (banco completo)")
|
| 209 |
st.dataframe(by_type, use_container_width=True, hide_index=True, height=220)
|
| 210 |
|
| 211 |
+
if st.button("🚀 Comenzar", use_container_width=True):
|
| 212 |
if not sel:
|
| 213 |
st.error("Selecciona al menos una dificultad.")
|
| 214 |
elif not filtered:
|
|
|
|
| 227 |
st.rerun()
|
| 228 |
|
| 229 |
else:
|
|
|
|
| 230 |
total_q = len(st.session_state.exam_pool)
|
| 231 |
current = st.session_state.current_idx
|
| 232 |
|
| 233 |
+
st.markdown("<div class='sidebar-card'><b>📍 Estado del examen</b></div>", unsafe_allow_html=True)
|
| 234 |
+
|
| 235 |
if st.session_state.start_time:
|
| 236 |
+
st.caption(f"⏱️ Tiempo: {format_time(time.time() - st.session_state.start_time)}")
|
| 237 |
|
| 238 |
+
st.metric("📌 Pregunta", f"{current + 1} / {total_q}")
|
| 239 |
|
| 240 |
answered = current
|
| 241 |
if answered > 0:
|
| 242 |
acc = st.session_state.score / answered * 100
|
| 243 |
+
st.metric("🎯 Tasa de acierto", f"{acc:.1f}%")
|
| 244 |
else:
|
| 245 |
+
st.metric("🎯 Tasa de acierto", "—")
|
| 246 |
|
|
|
|
| 247 |
if st.session_state.history:
|
| 248 |
st.markdown("—")
|
| 249 |
+
st.subheader("📊 Rendimiento por tipo")
|
| 250 |
st.dataframe(perf_by_type(st.session_state.history), use_container_width=True, hide_index=True, height=220)
|
| 251 |
|
| 252 |
st.markdown("—")
|
| 253 |
+
if st.button("⛔ Terminar examen", use_container_width=True):
|
| 254 |
st.session_state.current_idx = total_q
|
| 255 |
st.rerun()
|
| 256 |
|
| 257 |
# =====================================================
|
| 258 |
+
# PANTALLA INICIAL: “Cómo funciona” más largo + niveles explicados
|
| 259 |
# =====================================================
|
| 260 |
if not st.session_state.exam_active:
|
| 261 |
+
st.subheader("✅ Cómo funciona")
|
| 262 |
st.markdown("""
|
| 263 |
+
1) **Configura el examen** en el panel izquierdo 🧭
|
| 264 |
+
- **Dificultad**: puedes elegir una o varias (por ejemplo: solo “básico” para repasar, o “medio + alto” para exigirte).
|
| 265 |
+
- **Longitud**:
|
| 266 |
+
- ⚡ **Rápido (10)** → ideal para calentar o repasar un tema.
|
| 267 |
+
- 🧪 **Estándar (25)** → simulacro razonable (como un mini-examen).
|
| 268 |
+
- 🧠 **Completo** → usa todas las preguntas disponibles en el filtro.
|
| 269 |
+
|
| 270 |
+
2) Pulsa **🚀 Comenzar**
|
| 271 |
+
Se generará un examen con preguntas aleatorias dentro del filtro elegido.
|
| 272 |
+
|
| 273 |
+
3) **Responde cada pregunta** ✍️
|
| 274 |
+
- Verás el enunciado (puede incluir **código** o **diagramas**).
|
| 275 |
+
- Selecciona **una opción** (4 respuestas alineadas a la izquierda) y pulsa **Responder**.
|
| 276 |
+
|
| 277 |
+
4) **Revisa el feedback** ✅❌
|
| 278 |
+
Después de responder, la app te mostrará:
|
| 279 |
+
- si es **Correcto** o **Incorrecto**
|
| 280 |
+
- tu respuesta
|
| 281 |
+
- la respuesta correcta
|
| 282 |
+
- el **comentario/explicación** (si existe en el JSON)
|
| 283 |
+
|
| 284 |
+
5) Pulsa **Siguiente** ➜
|
| 285 |
+
Avanzas a la siguiente pregunta. Tu **tasa de acierto** se actualiza en tiempo real en el panel.
|
| 286 |
+
|
| 287 |
+
""")
|
| 288 |
+
|
| 289 |
+
st.subheader("🎚️ Niveles de dificultad (orientativo)")
|
| 290 |
+
st.markdown("""
|
| 291 |
+
- 🟢 **básico**: conceptos directos, sintaxis, trazas simples, operaciones básicas.
|
| 292 |
+
- 🟡 **medio**: más lógica, condicionales/bucles con más pasos, casos límite.
|
| 293 |
+
- 🟠 **alto**: razonamiento más largo, código más denso, más probabilidad de trampas típicas.
|
| 294 |
+
- 🔴 **avanzado** (si aparece): ejercicios poco frecuentes o combinaciones exigentes.
|
| 295 |
+
|
| 296 |
+
> Nota: el nivel lo marca el JSON; la dificultad real puede variar según la pregunta.
|
| 297 |
+
""")
|
| 298 |
+
|
| 299 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
| 300 |
+
st.subheader("📊 Estadísticas del banco (exactas)")
|
| 301 |
+
c1, c2 = st.columns(2)
|
| 302 |
+
with c1:
|
| 303 |
+
st.caption("🎚️ Por dificultad")
|
| 304 |
+
st.dataframe(by_level, use_container_width=True, hide_index=True, height=240)
|
| 305 |
+
with c2:
|
| 306 |
+
st.caption("🧩 Por tipo")
|
| 307 |
+
st.dataframe(by_type, use_container_width=True, hide_index=True, height=240)
|
| 308 |
+
|
| 309 |
return
|
| 310 |
|
| 311 |
# =====================================================
|
|
|
|
| 314 |
if st.session_state.current_idx < len(st.session_state.exam_pool):
|
| 315 |
q = st.session_state.exam_pool[st.session_state.current_idx]
|
| 316 |
|
| 317 |
+
st.subheader(f"📝 Pregunta {st.session_state.current_idx + 1}")
|
| 318 |
render_content(q["question"])
|
| 319 |
|
| 320 |
+
# opciones barajadas persistentes
|
| 321 |
qkey = f"opts_{st.session_state.current_idx}"
|
| 322 |
if qkey not in st.session_state.opts_cache:
|
| 323 |
opts = list(enumerate(q["options"]))
|
|
|
|
| 327 |
opts = st.session_state.opts_cache[qkey]
|
| 328 |
labels = [o[1] for o in opts]
|
| 329 |
|
| 330 |
+
# selección por radio (limpio, típico)
|
|
|
|
| 331 |
if f"sel_{st.session_state.current_idx}" not in st.session_state:
|
| 332 |
st.session_state[f"sel_{st.session_state.current_idx}"] = None
|
| 333 |
|
|
|
|
| 338 |
index=None if st.session_state[f"sel_{st.session_state.current_idx}"] is None else labels.index(st.session_state[f"sel_{st.session_state.current_idx}"]),
|
| 339 |
disabled=disabled
|
| 340 |
)
|
|
|
|
| 341 |
if sel_label is not None and not disabled:
|
| 342 |
st.session_state[f"sel_{st.session_state.current_idx}"] = sel_label
|
| 343 |
|
| 344 |
st.write("")
|
| 345 |
+
if st.button("Responder", disabled=disabled):
|
| 346 |
user_label = st.session_state.get(f"sel_{st.session_state.current_idx}", None)
|
| 347 |
if user_label is None:
|
| 348 |
st.warning("Selecciona una opción antes de responder.")
|
|
|
|
| 376 |
|
| 377 |
st.rerun()
|
| 378 |
|
| 379 |
+
# feedback
|
| 380 |
if st.session_state.answered_current and st.session_state.last_result:
|
| 381 |
res = st.session_state.last_result
|
| 382 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
|
|
|
| 391 |
st.markdown(f"**Comentario:** {res['expl']}")
|
| 392 |
|
| 393 |
st.write("")
|
| 394 |
+
if st.button("Siguiente ➜", use_container_width=False):
|
| 395 |
st.session_state.current_idx += 1
|
| 396 |
st.session_state.answered_current = False
|
| 397 |
st.session_state.last_result = None
|
| 398 |
st.rerun()
|
| 399 |
|
| 400 |
# =====================================================
|
| 401 |
+
# FINAL
|
| 402 |
# =====================================================
|
| 403 |
else:
|
| 404 |
st.balloons()
|
| 405 |
+
st.header("🏁 Resultados")
|
| 406 |
|
| 407 |
total_q = len(st.session_state.exam_pool)
|
| 408 |
score = st.session_state.score
|
|
|
|
| 410 |
elapsed = format_time(time.time() - st.session_state.start_time) if st.session_state.start_time else "—"
|
| 411 |
|
| 412 |
c1, c2, c3 = st.columns(3)
|
| 413 |
+
c1.metric("✅ Nota", f"{score} / {total_q}")
|
| 414 |
+
c2.metric("📈 Porcentaje", f"{perc:.1f}%")
|
| 415 |
+
c3.metric("⏱️ Tiempo", elapsed)
|
| 416 |
|
| 417 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
| 418 |
|
| 419 |
+
st.subheader("📌 Progreso del alumno (historial)")
|
| 420 |
if st.session_state.history:
|
| 421 |
dfh = pd.DataFrame(st.session_state.history)
|
| 422 |
dfh["Resultado"] = dfh["correct"].map(lambda x: "✅" if x else "❌")
|
| 423 |
show_cols = ["n", "Resultado", "nivel", "tipo", "respuesta_alumno", "respuesta_correcta"]
|
| 424 |
st.dataframe(dfh[show_cols], use_container_width=True, hide_index=True, height=380)
|
| 425 |
|
| 426 |
+
st.subheader("📊 Rendimiento por tipo")
|
| 427 |
st.dataframe(perf_by_type(st.session_state.history), use_container_width=True, hide_index=True, height=260)
|
| 428 |
else:
|
| 429 |
st.caption("No hay historial.")
|
| 430 |
|
| 431 |
st.write("")
|
| 432 |
+
if st.button("🏠 Volver al inicio"):
|
| 433 |
st.session_state.exam_active = False
|
| 434 |
st.rerun()
|
| 435 |
|