Spaces:
Sleeping
Sleeping
Update modules/studentact/student_activities_v2.py
Browse files
modules/studentact/student_activities_v2.py
CHANGED
|
@@ -22,6 +22,7 @@ from ..database.semantic_mongo_db import get_student_semantic_analysis
|
|
| 22 |
from ..database.discourse_mongo_db import get_student_discourse_analysis
|
| 23 |
from ..database.chat_mongo_db import get_chat_history
|
| 24 |
from ..database.current_situation_mongo_db import get_current_situation_analysis # Nueva importaci贸n
|
|
|
|
| 25 |
|
| 26 |
logger = logging.getLogger(__name__)
|
| 27 |
|
|
@@ -356,3 +357,83 @@ def display_chat_activities(username: str, t: dict):
|
|
| 356 |
logger.error(f"Error mostrando historial del chat: {str(e)}")
|
| 357 |
st.error(t.get('error_chat', 'Error al mostrar historial del chat'))
|
| 358 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
from ..database.discourse_mongo_db import get_student_discourse_analysis
|
| 23 |
from ..database.chat_mongo_db import get_chat_history
|
| 24 |
from ..database.current_situation_mongo_db import get_current_situation_analysis # Nueva importaci贸n
|
| 25 |
+
from ..database.claude_recommendations_mongo_db import get_claude_recommendations # Actualizada
|
| 26 |
|
| 27 |
logger = logging.getLogger(__name__)
|
| 28 |
|
|
|
|
| 357 |
logger.error(f"Error mostrando historial del chat: {str(e)}")
|
| 358 |
st.error(t.get('error_chat', 'Error al mostrar historial del chat'))
|
| 359 |
|
| 360 |
+
##############################################################################################
|
| 361 |
+
# Nueva funci贸n para mostrar las actividades de Situaci贸n Actual
|
| 362 |
+
def display_current_situation_activities(username: str, t: dict):
|
| 363 |
+
"""Muestra actividades de an谩lisis de situaci贸n actual con recomendaciones de Claude"""
|
| 364 |
+
try:
|
| 365 |
+
logger.info(f"Recuperando recomendaciones de Claude para {username}")
|
| 366 |
+
recommendations = get_claude_recommendations(username)
|
| 367 |
+
|
| 368 |
+
if not recommendations:
|
| 369 |
+
logger.info("No se encontraron recomendaciones de Claude")
|
| 370 |
+
st.info(t.get('no_recommendations', 'No hay recomendaciones de Claude registradas'))
|
| 371 |
+
return
|
| 372 |
+
|
| 373 |
+
logger.info(f"Procesando {len(recommendations)} recomendaciones de Claude")
|
| 374 |
+
|
| 375 |
+
for recommendation in recommendations:
|
| 376 |
+
try:
|
| 377 |
+
# Verificar campos necesarios
|
| 378 |
+
if not all(key in recommendation for key in ['timestamp', 'feedback']):
|
| 379 |
+
logger.warning(f"Recomendaci贸n incompleta: {recommendation.keys()}")
|
| 380 |
+
continue
|
| 381 |
+
|
| 382 |
+
# Formatear fecha
|
| 383 |
+
timestamp = datetime.fromisoformat(recommendation['timestamp'].replace('Z', '+00:00'))
|
| 384 |
+
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
|
| 385 |
+
|
| 386 |
+
# Crear expander con t铆tulo que incluye informaci贸n del tipo de texto si est谩 disponible
|
| 387 |
+
title = f"{t.get('recommendation_date', 'Fecha')}: {formatted_date}"
|
| 388 |
+
if 'text_type' in recommendation:
|
| 389 |
+
text_type_display = {
|
| 390 |
+
'academic_article': t.get('academic_article', 'Art铆culo acad茅mico'),
|
| 391 |
+
'university_work': t.get('university_work', 'Trabajo universitario'),
|
| 392 |
+
'general_communication': t.get('general_communication', 'Comunicaci贸n general')
|
| 393 |
+
}.get(recommendation['text_type'], recommendation['text_type'])
|
| 394 |
+
title += f" - {text_type_display}"
|
| 395 |
+
|
| 396 |
+
with st.expander(title, expanded=False):
|
| 397 |
+
# Mostrar el texto original analizado
|
| 398 |
+
st.subheader(t.get('analyzed_text', 'Texto analizado'))
|
| 399 |
+
st.text_area(
|
| 400 |
+
"",
|
| 401 |
+
value=recommendation.get('text', ''),
|
| 402 |
+
height=100,
|
| 403 |
+
disabled=True,
|
| 404 |
+
label_visibility="collapsed"
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
# Mostrar las recomendaciones generadas por Claude
|
| 408 |
+
st.subheader(t.get('recommendations', 'Recomendaciones de Claude'))
|
| 409 |
+
|
| 410 |
+
# Dar formato a las recomendaciones en un contenedor estilizado
|
| 411 |
+
st.markdown(f"""
|
| 412 |
+
<div style="padding: 20px; border-radius: 10px;
|
| 413 |
+
background-color: #f8f9fa; margin-bottom: 20px;">
|
| 414 |
+
{recommendation.get('feedback', 'No hay recomendaciones disponibles')}
|
| 415 |
+
</div>
|
| 416 |
+
""", unsafe_allow_html=True)
|
| 417 |
+
|
| 418 |
+
# Mostrar m茅tricas adicionales si est谩n disponibles
|
| 419 |
+
if 'metrics' in recommendation and recommendation['metrics']:
|
| 420 |
+
with st.expander(t.get('metrics_details', 'Detalles de m茅tricas')):
|
| 421 |
+
# Crear un DataFrame para mejor visualizaci贸n
|
| 422 |
+
metrics_data = []
|
| 423 |
+
for key, value in recommendation['metrics'].items():
|
| 424 |
+
if not isinstance(value, dict) and key not in ['test_type', 'timestamp']:
|
| 425 |
+
metrics_data.append({"M茅trica": key, "Valor": value})
|
| 426 |
+
|
| 427 |
+
if metrics_data:
|
| 428 |
+
metrics_df = pd.DataFrame(metrics_data)
|
| 429 |
+
st.dataframe(metrics_df, use_container_width=True)
|
| 430 |
+
else:
|
| 431 |
+
st.info(t.get('no_metrics', 'No hay m茅tricas disponibles'))
|
| 432 |
+
|
| 433 |
+
except Exception as e:
|
| 434 |
+
logger.error(f"Error procesando recomendaci贸n individual: {str(e)}")
|
| 435 |
+
continue
|
| 436 |
+
|
| 437 |
+
except Exception as e:
|
| 438 |
+
logger.error(f"Error mostrando recomendaciones de Claude: {str(e)}")
|
| 439 |
+
st.error(t.get('error_recommendations', 'Error al mostrar recomendaciones de Claude'))
|