Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +48 -25
src/streamlit_app.py
CHANGED
|
@@ -4,7 +4,6 @@ from pathlib import Path
|
|
| 4 |
|
| 5 |
DATA_FILE = Path(__file__).parent / "master_fundamentos_evaluado.json"
|
| 6 |
|
| 7 |
-
|
| 8 |
@st.cache_data
|
| 9 |
def load_data(path):
|
| 10 |
with open(path, encoding="utf-8") as f:
|
|
@@ -23,23 +22,26 @@ def build_exam():
|
|
| 23 |
preguntas = random.sample(data["preguntas"], 25)
|
| 24 |
casos = random.sample(data["casos_clinicos"], 2)
|
| 25 |
items = [{"grupo": "normal", "data": q} for q in preguntas]
|
| 26 |
-
for c in casos:
|
| 27 |
for q in c["preguntas"]:
|
| 28 |
-
items.append({
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
return items
|
| 31 |
|
| 32 |
# ───────── Estado inicial ─────────
|
| 33 |
if "mode" not in st.session_state:
|
| 34 |
-
st.session_state.mode = "preguntas"
|
| 35 |
-
st.session_state.question
|
| 36 |
-
st.session_state.case_list
|
| 37 |
-
st.session_state.case_idx
|
| 38 |
st.session_state.exam_items = []
|
| 39 |
-
st.session_state.exam_idx
|
| 40 |
-
st.session_state.hits_norm
|
| 41 |
-
st.session_state.hits_case
|
| 42 |
st.session_state.total_case = {}
|
|
|
|
| 43 |
|
| 44 |
# ───────── Barra lateral ─────────
|
| 45 |
st.sidebar.title("Fundamentos")
|
|
@@ -74,14 +76,21 @@ if st.sidebar.button("Examen (25 + 2 casos)"):
|
|
| 74 |
st.session_state.question = st.session_state.exam_items[0]["data"]
|
| 75 |
st.rerun()
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
st.sidebar.markdown("---")
|
| 78 |
st.sidebar.markdown("Creado con ❤️ por Requetito")
|
| 79 |
|
| 80 |
# ───────── Encabezado: modo + progreso ─────────
|
| 81 |
mode_label = {
|
| 82 |
"preguntas": "Práctica – Preguntas sueltas",
|
| 83 |
-
"caso":
|
| 84 |
-
"examen":
|
|
|
|
| 85 |
}
|
| 86 |
|
| 87 |
st.subheader(mode_label[st.session_state.mode])
|
|
@@ -91,8 +100,18 @@ if st.session_state.mode == "examen":
|
|
| 91 |
progreso = f"{st.session_state.exam_idx + 1} / {len(st.session_state.exam_items)}"
|
| 92 |
elif st.session_state.mode == "caso":
|
| 93 |
progreso = f"{st.session_state.case_idx + 1} / {len(st.session_state.case_list)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
if progreso:
|
| 96 |
st.caption(progreso)
|
| 97 |
|
| 98 |
# ───────── Pregunta ─────────
|
|
@@ -111,12 +130,12 @@ selected = st.radio(
|
|
| 111 |
)
|
| 112 |
|
| 113 |
col1, col2 = st.columns(2)
|
| 114 |
-
comprobar
|
| 115 |
-
siguiente
|
| 116 |
|
| 117 |
# contenedores feedback
|
| 118 |
feedback_box = st.empty()
|
| 119 |
-
justif_box
|
| 120 |
|
| 121 |
# ───────── Comprobar ─────────
|
| 122 |
if comprobar and selected:
|
|
@@ -138,7 +157,7 @@ if comprobar and selected:
|
|
| 138 |
|
| 139 |
# ───────── Siguiente ─────────
|
| 140 |
if siguiente:
|
| 141 |
-
feedback_box.empty(); justif_box.empty()
|
| 142 |
|
| 143 |
if st.session_state.mode == "preguntas":
|
| 144 |
st.session_state.question = random_question()
|
|
@@ -157,20 +176,18 @@ if siguiente:
|
|
| 157 |
elif st.session_state.mode == "examen":
|
| 158 |
st.session_state.exam_idx += 1
|
| 159 |
if st.session_state.exam_idx == len(st.session_state.exam_items):
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
pts_casos = 0; detalles = []
|
| 164 |
|
| 165 |
for cid, tot in st.session_state.total_case.items():
|
| 166 |
-
peso_por_preg = 6 / tot
|
| 167 |
aciertos = st.session_state.hits_case.get(cid, 0)
|
| 168 |
pts = aciertos * peso_por_preg
|
| 169 |
pts_casos += pts
|
| 170 |
detalles.append(f"{cid}: {pts:.2f} / 6")
|
| 171 |
|
| 172 |
total = pts_preg + pts_casos
|
| 173 |
-
|
| 174 |
aprobado = total >= 7.5
|
| 175 |
st.balloons()
|
| 176 |
st.markdown(
|
|
@@ -178,11 +195,17 @@ if siguiente:
|
|
| 178 |
f"**Preguntas (máx 4):** {pts_preg:.2f}\n\n"
|
| 179 |
+ "\n".join(detalles) +
|
| 180 |
f"\n\n**TOTAL:** {total:.2f} / 16 → "
|
| 181 |
-
+ ("✅ Aprobado" if
|
| 182 |
)
|
| 183 |
st.stop()
|
| 184 |
|
| 185 |
st.session_state.question = \
|
| 186 |
st.session_state.exam_items[st.session_state.exam_idx]["data"]
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
st.rerun()
|
|
|
|
| 4 |
|
| 5 |
DATA_FILE = Path(__file__).parent / "master_fundamentos_evaluado.json"
|
| 6 |
|
|
|
|
| 7 |
@st.cache_data
|
| 8 |
def load_data(path):
|
| 9 |
with open(path, encoding="utf-8") as f:
|
|
|
|
| 22 |
preguntas = random.sample(data["preguntas"], 25)
|
| 23 |
casos = random.sample(data["casos_clinicos"], 2)
|
| 24 |
items = [{"grupo": "normal", "data": q} for q in preguntas]
|
| 25 |
+
for c in casos:
|
| 26 |
for q in c["preguntas"]:
|
| 27 |
+
items.append({
|
| 28 |
+
"grupo": c["id"],
|
| 29 |
+
"data": {**q, "caso": c["titulo"], "context": c["contexto"]}
|
| 30 |
+
})
|
| 31 |
return items
|
| 32 |
|
| 33 |
# ───────── Estado inicial ─────────
|
| 34 |
if "mode" not in st.session_state:
|
| 35 |
+
st.session_state.mode = "preguntas"
|
| 36 |
+
st.session_state.question = random_question()
|
| 37 |
+
st.session_state.case_list = []
|
| 38 |
+
st.session_state.case_idx = 0
|
| 39 |
st.session_state.exam_items = []
|
| 40 |
+
st.session_state.exam_idx = 0
|
| 41 |
+
st.session_state.hits_norm = 0
|
| 42 |
+
st.session_state.hits_case = {}
|
| 43 |
st.session_state.total_case = {}
|
| 44 |
+
st.session_state.recorrido_idx = 0 # nuevo
|
| 45 |
|
| 46 |
# ───────── Barra lateral ─────────
|
| 47 |
st.sidebar.title("Fundamentos")
|
|
|
|
| 76 |
st.session_state.question = st.session_state.exam_items[0]["data"]
|
| 77 |
st.rerun()
|
| 78 |
|
| 79 |
+
if st.sidebar.button("Recorrido completo"):
|
| 80 |
+
st.session_state.mode = "recorrido"
|
| 81 |
+
st.session_state.recorrido_idx = 0
|
| 82 |
+
st.session_state.question = data["preguntas"][0]
|
| 83 |
+
st.rerun()
|
| 84 |
+
|
| 85 |
st.sidebar.markdown("---")
|
| 86 |
st.sidebar.markdown("Creado con ❤️ por Requetito")
|
| 87 |
|
| 88 |
# ───────── Encabezado: modo + progreso ─────────
|
| 89 |
mode_label = {
|
| 90 |
"preguntas": "Práctica – Preguntas sueltas",
|
| 91 |
+
"caso": "Práctica – Casos clínicos",
|
| 92 |
+
"examen": "Examen final",
|
| 93 |
+
"recorrido": "Recorrido completo – Todas las preguntas"
|
| 94 |
}
|
| 95 |
|
| 96 |
st.subheader(mode_label[st.session_state.mode])
|
|
|
|
| 100 |
progreso = f"{st.session_state.exam_idx + 1} / {len(st.session_state.exam_items)}"
|
| 101 |
elif st.session_state.mode == "caso":
|
| 102 |
progreso = f"{st.session_state.case_idx + 1} / {len(st.session_state.case_list)}"
|
| 103 |
+
elif st.session_state.mode == "recorrido":
|
| 104 |
+
total = len(data["preguntas"])
|
| 105 |
+
idx = st.session_state.recorrido_idx
|
| 106 |
+
progreso = f"{idx + 1} / {total}"
|
| 107 |
+
st.caption(progreso)
|
| 108 |
+
nuevo_idx = st.number_input("Ir a la pregunta n.º:", min_value=1, max_value=total, value=idx + 1, step=1)
|
| 109 |
+
if nuevo_idx - 1 != idx:
|
| 110 |
+
st.session_state.recorrido_idx = nuevo_idx - 1
|
| 111 |
+
st.session_state.question = data["preguntas"][nuevo_idx - 1]
|
| 112 |
+
st.rerun()
|
| 113 |
|
| 114 |
+
if progreso and st.session_state.mode != "recorrido":
|
| 115 |
st.caption(progreso)
|
| 116 |
|
| 117 |
# ───────── Pregunta ─────────
|
|
|
|
| 130 |
)
|
| 131 |
|
| 132 |
col1, col2 = st.columns(2)
|
| 133 |
+
comprobar = col1.button("✅ Comprobar")
|
| 134 |
+
siguiente = col2.button("➡️ Siguiente")
|
| 135 |
|
| 136 |
# contenedores feedback
|
| 137 |
feedback_box = st.empty()
|
| 138 |
+
justif_box = st.empty()
|
| 139 |
|
| 140 |
# ───────── Comprobar ─────────
|
| 141 |
if comprobar and selected:
|
|
|
|
| 157 |
|
| 158 |
# ───────── Siguiente ─────────
|
| 159 |
if siguiente:
|
| 160 |
+
feedback_box.empty(); justif_box.empty()
|
| 161 |
|
| 162 |
if st.session_state.mode == "preguntas":
|
| 163 |
st.session_state.question = random_question()
|
|
|
|
| 176 |
elif st.session_state.mode == "examen":
|
| 177 |
st.session_state.exam_idx += 1
|
| 178 |
if st.session_state.exam_idx == len(st.session_state.exam_items):
|
| 179 |
+
pts_preg = st.session_state.hits_norm * (4 / 25)
|
| 180 |
+
pts_casos = 0
|
| 181 |
+
detalles = []
|
|
|
|
| 182 |
|
| 183 |
for cid, tot in st.session_state.total_case.items():
|
| 184 |
+
peso_por_preg = 6 / tot
|
| 185 |
aciertos = st.session_state.hits_case.get(cid, 0)
|
| 186 |
pts = aciertos * peso_por_preg
|
| 187 |
pts_casos += pts
|
| 188 |
detalles.append(f"{cid}: {pts:.2f} / 6")
|
| 189 |
|
| 190 |
total = pts_preg + pts_casos
|
|
|
|
| 191 |
aprobado = total >= 7.5
|
| 192 |
st.balloons()
|
| 193 |
st.markdown(
|
|
|
|
| 195 |
f"**Preguntas (máx 4):** {pts_preg:.2f}\n\n"
|
| 196 |
+ "\n".join(detalles) +
|
| 197 |
f"\n\n**TOTAL:** {total:.2f} / 16 → "
|
| 198 |
+
+ ("✅ Aprobado" if aprobado else "❌ No aprobado")
|
| 199 |
)
|
| 200 |
st.stop()
|
| 201 |
|
| 202 |
st.session_state.question = \
|
| 203 |
st.session_state.exam_items[st.session_state.exam_idx]["data"]
|
| 204 |
|
| 205 |
+
elif st.session_state.mode == "recorrido":
|
| 206 |
+
st.session_state.recorrido_idx += 1
|
| 207 |
+
if st.session_state.recorrido_idx >= len(data["preguntas"]):
|
| 208 |
+
st.session_state.recorrido_idx = 0
|
| 209 |
+
st.session_state.question = data["preguntas"][st.session_state.recorrido_idx]
|
| 210 |
+
|
| 211 |
st.rerun()
|