Spaces:
Sleeping
Sleeping
JACINTO VELASCO commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ def render_code_snippet(code):
|
|
| 21 |
st.markdown(f"<div style='background-color:#272822;padding:10px;border-radius:8px;overflow-x:auto'>{highlighted_code}</div>", unsafe_allow_html=True)
|
| 22 |
|
| 23 |
def show_question(q, real_index):
|
| 24 |
-
st.subheader(f"Pregunta {real_index+1}:")
|
| 25 |
|
| 26 |
if "```python" in q["question"]:
|
| 27 |
parts = q["question"].split("```python")
|
|
@@ -50,22 +50,11 @@ def show_question(q, real_index):
|
|
| 50 |
st.markdown("✅ Correcto" if is_correct else "❌ Incorrecto")
|
| 51 |
st.markdown(f"_Explicación:_ {q['explanation']}")
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
df_temp["incorrecto"] = ~df_temp["correcto"]
|
| 57 |
-
resumen = df_temp.groupby("tipo")[["correcto", "incorrecto"]].sum()
|
| 58 |
-
resumen["total"] = resumen["correcto"] + resumen["incorrecto"]
|
| 59 |
-
resumen["% acierto"] = (resumen["correcto"] / resumen["total"] * 100).round(1)
|
| 60 |
-
resumen["% error"] = (resumen["incorrecto"] / resumen["total"] * 100).round(1)
|
| 61 |
-
|
| 62 |
-
with st.sidebar:
|
| 63 |
-
st.markdown("### Estadísticas parciales")
|
| 64 |
-
st.markdown("#### Resumen por tipo")
|
| 65 |
-
st.dataframe(resumen[["% acierto"]], height=200)
|
| 66 |
-
|
| 67 |
-
if st.button("Siguiente", key=f"next_{real_index}"):
|
| 68 |
st.session_state.current += 1
|
|
|
|
| 69 |
st.rerun()
|
| 70 |
|
| 71 |
def mostrar_estadisticas(history):
|
|
@@ -74,15 +63,14 @@ def mostrar_estadisticas(history):
|
|
| 74 |
resumen = df.groupby("tipo")[["correcto", "incorrecto"]].sum()
|
| 75 |
resumen["total"] = resumen["correcto"] + resumen["incorrecto"]
|
| 76 |
resumen["% acierto"] = (resumen["correcto"] / resumen["total"] * 100).round(1)
|
| 77 |
-
resumen["% error"] = (resumen["incorrecto"] / resumen["total"] * 100).round(1)
|
| 78 |
|
| 79 |
st.markdown("### 📊 Estadísticas por tipo de pregunta")
|
| 80 |
st.dataframe(resumen[["% acierto"]], height=200)
|
| 81 |
|
| 82 |
fig, ax = plt.subplots()
|
| 83 |
-
resumen[["% acierto"
|
| 84 |
plt.ylabel("Porcentaje")
|
| 85 |
-
plt.title("Porcentaje de aciertos
|
| 86 |
st.pyplot(fig)
|
| 87 |
|
| 88 |
return df
|
|
@@ -115,8 +103,9 @@ def main():
|
|
| 115 |
st.session_state.correct_count = 0
|
| 116 |
st.session_state.current = 0
|
| 117 |
st.session_state.history = []
|
| 118 |
-
st.session_state.
|
| 119 |
-
random.shuffle(st.session_state.
|
|
|
|
| 120 |
|
| 121 |
with st.sidebar:
|
| 122 |
st.markdown("## Progreso")
|
|
@@ -125,11 +114,10 @@ def main():
|
|
| 125 |
porcentaje = round((correctas / total) * 100, 1) if total > 0 else 0
|
| 126 |
st.metric("Respuestas correctas", f"{correctas} ({porcentaje}%)")
|
| 127 |
st.metric("Respondidas", total)
|
| 128 |
-
|
| 129 |
-
if 'history' in st.session_state and st.session_state.history:
|
| 130 |
df_temp = pd.DataFrame(st.session_state.history)
|
| 131 |
df_temp["incorrecto"] = ~df_temp["correcto"]
|
| 132 |
-
resumen = df_temp.groupby("tipo")[
|
| 133 |
resumen["total"] = resumen["correcto"] + resumen["incorrecto"]
|
| 134 |
resumen["% acierto"] = (resumen["correcto"] / resumen["total"] * 100).round(1)
|
| 135 |
st.markdown("#### Resumen por tipo")
|
|
@@ -144,7 +132,7 @@ def main():
|
|
| 144 |
df = mostrar_estadisticas(st.session_state.history)
|
| 145 |
exportar_pdf(df)
|
| 146 |
if st.button("Reiniciar"):
|
| 147 |
-
for key in ["answers", "correct_count", "current", "history", "shuffled_indices"]:
|
| 148 |
del st.session_state[key]
|
| 149 |
st.rerun()
|
| 150 |
|
|
|
|
| 21 |
st.markdown(f"<div style='background-color:#272822;padding:10px;border-radius:8px;overflow-x:auto'>{highlighted_code}</div>", unsafe_allow_html=True)
|
| 22 |
|
| 23 |
def show_question(q, real_index):
|
| 24 |
+
st.subheader(f"Pregunta {real_index+1} ({q['tipo']}):")
|
| 25 |
|
| 26 |
if "```python" in q["question"]:
|
| 27 |
parts = q["question"].split("```python")
|
|
|
|
| 50 |
st.markdown("✅ Correcto" if is_correct else "❌ Incorrecto")
|
| 51 |
st.markdown(f"_Explicación:_ {q['explanation']}")
|
| 52 |
|
| 53 |
+
st.session_state.answered = True
|
| 54 |
|
| 55 |
+
if st.session_state.get("answered") and st.button("Siguiente", key=f"next_{real_index}"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
st.session_state.current += 1
|
| 57 |
+
st.session_state.answered = False
|
| 58 |
st.rerun()
|
| 59 |
|
| 60 |
def mostrar_estadisticas(history):
|
|
|
|
| 63 |
resumen = df.groupby("tipo")[["correcto", "incorrecto"]].sum()
|
| 64 |
resumen["total"] = resumen["correcto"] + resumen["incorrecto"]
|
| 65 |
resumen["% acierto"] = (resumen["correcto"] / resumen["total"] * 100).round(1)
|
|
|
|
| 66 |
|
| 67 |
st.markdown("### 📊 Estadísticas por tipo de pregunta")
|
| 68 |
st.dataframe(resumen[["% acierto"]], height=200)
|
| 69 |
|
| 70 |
fig, ax = plt.subplots()
|
| 71 |
+
resumen[["% acierto"]].plot(kind="bar", legend=False, ax=ax)
|
| 72 |
plt.ylabel("Porcentaje")
|
| 73 |
+
plt.title("Porcentaje de aciertos por tipo")
|
| 74 |
st.pyplot(fig)
|
| 75 |
|
| 76 |
return df
|
|
|
|
| 103 |
st.session_state.correct_count = 0
|
| 104 |
st.session_state.current = 0
|
| 105 |
st.session_state.history = []
|
| 106 |
+
st.session_state.shuffled_indices = list(range(len(questions)))
|
| 107 |
+
random.shuffle(st.session_state.shuffled_indices)
|
| 108 |
+
st.session_state.answered = False
|
| 109 |
|
| 110 |
with st.sidebar:
|
| 111 |
st.markdown("## Progreso")
|
|
|
|
| 114 |
porcentaje = round((correctas / total) * 100, 1) if total > 0 else 0
|
| 115 |
st.metric("Respuestas correctas", f"{correctas} ({porcentaje}%)")
|
| 116 |
st.metric("Respondidas", total)
|
| 117 |
+
if st.session_state.history:
|
|
|
|
| 118 |
df_temp = pd.DataFrame(st.session_state.history)
|
| 119 |
df_temp["incorrecto"] = ~df_temp["correcto"]
|
| 120 |
+
resumen = df_temp.groupby("tipo")["correcto", "incorrecto"].sum()
|
| 121 |
resumen["total"] = resumen["correcto"] + resumen["incorrecto"]
|
| 122 |
resumen["% acierto"] = (resumen["correcto"] / resumen["total"] * 100).round(1)
|
| 123 |
st.markdown("#### Resumen por tipo")
|
|
|
|
| 132 |
df = mostrar_estadisticas(st.session_state.history)
|
| 133 |
exportar_pdf(df)
|
| 134 |
if st.button("Reiniciar"):
|
| 135 |
+
for key in ["answers", "correct_count", "current", "history", "shuffled_indices", "answered"]:
|
| 136 |
del st.session_state[key]
|
| 137 |
st.rerun()
|
| 138 |
|