Update modules/studentact/student_activities_v2.py
Browse files
modules/studentact/student_activities_v2.py
CHANGED
@@ -86,13 +86,27 @@ def display_current_situation_activities(username: str, t: dict):
|
|
86 |
try:
|
87 |
# Recuperar datos de ambas colecciones
|
88 |
logger.info(f"Recuperando análisis de situación actual para {username}")
|
89 |
-
#situation_analyses = get_current_situation_analysis(username)
|
90 |
situation_analyses = get_current_situation_analysis(username, limit=5)
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
logger.info(f"Recuperando recomendaciones de Claude para {username}")
|
94 |
claude_recommendations = get_claude_recommendations(username)
|
95 |
|
|
|
|
|
|
|
|
|
|
|
96 |
# Verificar si hay algún tipo de análisis disponible
|
97 |
if not situation_analyses and not claude_recommendations:
|
98 |
logger.info("No se encontraron análisis de situación actual ni recomendaciones")
|
@@ -137,7 +151,7 @@ def display_current_situation_activities(username: str, t: dict):
|
|
137 |
logger.info(f"Procesando {len(paired_analyses)} pares de análisis")
|
138 |
|
139 |
# Mostrar cada par de análisis
|
140 |
-
for timestamp_key, analysis_pair in paired_analyses:
|
141 |
try:
|
142 |
# Obtener datos de situación y recomendación
|
143 |
situation_data = analysis_pair.get('situation', {})
|
@@ -171,16 +185,20 @@ def display_current_situation_activities(username: str, t: dict):
|
|
171 |
}.get(text_type, text_type)
|
172 |
title += f" - {text_type_display}"
|
173 |
|
|
|
|
|
|
|
174 |
# Mostrar el análisis en un expander
|
175 |
with st.expander(title, expanded=False):
|
176 |
-
# Mostrar texto analizado
|
177 |
st.subheader(t.get('analyzed_text', 'Texto analizado'))
|
178 |
st.text_area(
|
179 |
-
"",
|
180 |
value=text_to_show,
|
181 |
height=100,
|
182 |
disabled=True,
|
183 |
-
label_visibility="collapsed"
|
|
|
184 |
)
|
185 |
|
186 |
# Crear tabs para separar diagnóstico y recomendaciones
|
@@ -194,48 +212,62 @@ def display_current_situation_activities(username: str, t: dict):
|
|
194 |
if situation_data and 'metrics' in situation_data:
|
195 |
metrics = situation_data['metrics']
|
196 |
|
197 |
-
#
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
with col1:
|
202 |
-
st.subheader(t.get('key_metrics', 'Métricas clave'))
|
203 |
|
204 |
-
#
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
|
|
|
|
|
|
230 |
|
231 |
-
#
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
else:
|
238 |
st.info(t.get('no_diagnosis', 'No hay datos de diagnóstico disponibles'))
|
|
|
|
|
239 |
|
240 |
# Tab de recomendaciones
|
241 |
with recommendations_tab:
|
|
|
86 |
try:
|
87 |
# Recuperar datos de ambas colecciones
|
88 |
logger.info(f"Recuperando análisis de situación actual para {username}")
|
|
|
89 |
situation_analyses = get_current_situation_analysis(username, limit=5)
|
90 |
|
91 |
+
# Verificar si hay datos
|
92 |
+
if situation_analyses:
|
93 |
+
logger.info(f"Recuperados {len(situation_analyses)} análisis de situación")
|
94 |
+
# Depurar para ver la estructura de datos
|
95 |
+
for i, analysis in enumerate(situation_analyses):
|
96 |
+
logger.info(f"Análisis #{i+1}: Claves disponibles: {list(analysis.keys())}")
|
97 |
+
if 'metrics' in analysis:
|
98 |
+
logger.info(f"Métricas disponibles: {list(analysis['metrics'].keys())}")
|
99 |
+
else:
|
100 |
+
logger.warning("No se encontraron análisis de situación actual")
|
101 |
|
102 |
logger.info(f"Recuperando recomendaciones de Claude para {username}")
|
103 |
claude_recommendations = get_claude_recommendations(username)
|
104 |
|
105 |
+
if claude_recommendations:
|
106 |
+
logger.info(f"Recuperadas {len(claude_recommendations)} recomendaciones de Claude")
|
107 |
+
else:
|
108 |
+
logger.warning("No se encontraron recomendaciones de Claude")
|
109 |
+
|
110 |
# Verificar si hay algún tipo de análisis disponible
|
111 |
if not situation_analyses and not claude_recommendations:
|
112 |
logger.info("No se encontraron análisis de situación actual ni recomendaciones")
|
|
|
151 |
logger.info(f"Procesando {len(paired_analyses)} pares de análisis")
|
152 |
|
153 |
# Mostrar cada par de análisis
|
154 |
+
for i, (timestamp_key, analysis_pair) in enumerate(paired_analyses):
|
155 |
try:
|
156 |
# Obtener datos de situación y recomendación
|
157 |
situation_data = analysis_pair.get('situation', {})
|
|
|
185 |
}.get(text_type, text_type)
|
186 |
title += f" - {text_type_display}"
|
187 |
|
188 |
+
# Usar un ID único para cada expander
|
189 |
+
expander_id = f"analysis_{i}_{timestamp_key}"
|
190 |
+
|
191 |
# Mostrar el análisis en un expander
|
192 |
with st.expander(title, expanded=False):
|
193 |
+
# Mostrar texto analizado con key único
|
194 |
st.subheader(t.get('analyzed_text', 'Texto analizado'))
|
195 |
st.text_area(
|
196 |
+
"Text Content",
|
197 |
value=text_to_show,
|
198 |
height=100,
|
199 |
disabled=True,
|
200 |
+
label_visibility="collapsed",
|
201 |
+
key=f"text_area_{expander_id}"
|
202 |
)
|
203 |
|
204 |
# Crear tabs para separar diagnóstico y recomendaciones
|
|
|
212 |
if situation_data and 'metrics' in situation_data:
|
213 |
metrics = situation_data['metrics']
|
214 |
|
215 |
+
# Verificar si metrics es un diccionario y tiene elementos
|
216 |
+
if isinstance(metrics, dict) and metrics:
|
217 |
+
# Dividir en dos columnas
|
218 |
+
col1, col2 = st.columns(2)
|
|
|
|
|
219 |
|
220 |
+
# Principales métricas en formato de tarjetas
|
221 |
+
with col1:
|
222 |
+
st.subheader(t.get('key_metrics', 'Métricas clave'))
|
223 |
+
|
224 |
+
# Mostrar cada métrica principal
|
225 |
+
for metric_name, metric_data in metrics.items():
|
226 |
+
try:
|
227 |
+
# Verificar si metric_data es un diccionario y tiene normalized_score
|
228 |
+
if isinstance(metric_data, dict) and 'normalized_score' in metric_data:
|
229 |
+
score = metric_data['normalized_score']
|
230 |
+
|
231 |
+
# Determinar color y emoji basado en la puntuación
|
232 |
+
if score < 0.5:
|
233 |
+
emoji = "🔴"
|
234 |
+
color = "#ffcccc" # light red
|
235 |
+
elif score < 0.75:
|
236 |
+
emoji = "🟡"
|
237 |
+
color = "#ffffcc" # light yellow
|
238 |
+
else:
|
239 |
+
emoji = "🟢"
|
240 |
+
color = "#ccffcc" # light green
|
241 |
+
|
242 |
+
# Mostrar la métrica con estilo
|
243 |
+
st.markdown(f"""
|
244 |
+
<div style="background-color:{color}; padding:10px; border-radius:5px; margin-bottom:10px;">
|
245 |
+
<b>{emoji} {metric_name.capitalize()}:</b> {score:.2f}
|
246 |
+
</div>
|
247 |
+
""", unsafe_allow_html=True)
|
248 |
+
except Exception as e:
|
249 |
+
logger.error(f"Error procesando métrica {metric_name}: {str(e)}")
|
250 |
|
251 |
+
# Mostrar detalles adicionales si están disponibles
|
252 |
+
with col2:
|
253 |
+
st.subheader(t.get('details', 'Detalles'))
|
254 |
+
|
255 |
+
# Para cada métrica, mostrar sus detalles si existen
|
256 |
+
for metric_name, metric_data in metrics.items():
|
257 |
+
try:
|
258 |
+
if isinstance(metric_data, dict) and 'details' in metric_data and metric_data['details']:
|
259 |
+
# Usar st.json con un key único
|
260 |
+
st.write(f"**{metric_name.capitalize()}**")
|
261 |
+
st.json(metric_data['details'], expanded=False)
|
262 |
+
except Exception as e:
|
263 |
+
logger.error(f"Error mostrando detalles de {metric_name}: {str(e)}")
|
264 |
+
else:
|
265 |
+
st.info(t.get('no_metrics_data', 'No hay datos de métricas disponibles'))
|
266 |
+
logger.warning(f"La estructura de métricas no es válida: {metrics}")
|
267 |
else:
|
268 |
st.info(t.get('no_diagnosis', 'No hay datos de diagnóstico disponibles'))
|
269 |
+
if situation_data:
|
270 |
+
logger.warning(f"Claves disponibles en situation_data: {list(situation_data.keys())}")
|
271 |
|
272 |
# Tab de recomendaciones
|
273 |
with recommendations_tab:
|