Update modules/studentact/student_activities_v2.py
Browse files
modules/studentact/student_activities_v2.py
CHANGED
@@ -467,16 +467,81 @@ def display_morphosyntax_activities(username: str, t: dict):
|
|
467 |
st.error(t.get('error_morpho', 'Error al mostrar análisis morfosintáctico'))
|
468 |
|
469 |
|
470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
def display_discourse_activities(username: str, t: dict):
|
473 |
-
"""Muestra actividades de análisis del discurso"""
|
474 |
try:
|
475 |
logger.info(f"Recuperando análisis del discurso para {username}")
|
476 |
analyses = get_student_discourse_analysis(username)
|
477 |
|
478 |
if not analyses:
|
479 |
logger.info("No se encontraron análisis del discurso")
|
|
|
480 |
st.info(t.get('no_discourse_analyses', 'No hay análisis comparados de textos registrados'))
|
481 |
return
|
482 |
|
@@ -484,8 +549,8 @@ def display_discourse_activities(username: str, t: dict):
|
|
484 |
for analysis in analyses:
|
485 |
try:
|
486 |
# Verificar campos mínimos necesarios
|
487 |
-
if
|
488 |
-
logger.warning(f"Análisis
|
489 |
continue
|
490 |
|
491 |
# Formatear fecha
|
@@ -516,40 +581,48 @@ def display_discourse_activities(username: str, t: dict):
|
|
516 |
# Mostrar gráficos
|
517 |
st.markdown("### Visualización comparativa")
|
518 |
|
519 |
-
# Verificar y mostrar gráficos si existen
|
520 |
-
graph_col1, graph_col2 = st.columns(2)
|
521 |
has_graphs = False
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
|
551 |
if not has_graphs:
|
552 |
-
st.info(t.get('no_visualization', 'No hay visualización
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
|
554 |
except Exception as e:
|
555 |
logger.error(f"Error procesando análisis individual: {str(e)}")
|
@@ -557,11 +630,9 @@ def display_discourse_activities(username: str, t: dict):
|
|
557 |
|
558 |
except Exception as e:
|
559 |
logger.error(f"Error mostrando análisis del discurso: {str(e)}")
|
|
|
560 |
st.error(t.get('error_discourse', 'Error al mostrar análisis comparado de textos'))
|
561 |
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
#################################################################################
|
566 |
|
567 |
def display_discourse_comparison(analysis: dict, t: dict):
|
|
|
467 |
st.error(t.get('error_morpho', 'Error al mostrar análisis morfosintáctico'))
|
468 |
|
469 |
|
470 |
+
def display_semantic_activities(username: str, t: dict):
|
471 |
+
"""Muestra actividades de análisis semántico"""
|
472 |
+
try:
|
473 |
+
logger.info(f"Recuperando análisis semántico para {username}")
|
474 |
+
analyses = get_student_semantic_analysis(username)
|
475 |
+
|
476 |
+
if not analyses:
|
477 |
+
logger.info("No se encontraron análisis semánticos")
|
478 |
+
st.info(t.get('no_semantic_analyses', 'No hay análisis semánticos registrados'))
|
479 |
+
return
|
480 |
+
|
481 |
+
logger.info(f"Procesando {len(analyses)} análisis semánticos")
|
482 |
+
|
483 |
+
for analysis in analyses:
|
484 |
+
try:
|
485 |
+
# Verificar campos necesarios
|
486 |
+
if not all(key in analysis for key in ['timestamp', 'concept_graph']):
|
487 |
+
logger.warning(f"Análisis incompleto: {analysis.keys()}")
|
488 |
+
continue
|
489 |
+
|
490 |
+
# Formatear fecha
|
491 |
+
timestamp = datetime.fromisoformat(analysis['timestamp'].replace('Z', '+00:00'))
|
492 |
+
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
|
493 |
+
|
494 |
+
# Crear expander
|
495 |
+
with st.expander(f"{t.get('analysis_date', 'Fecha')}: {formatted_date}", expanded=False):
|
496 |
+
# Procesar y mostrar gráfico
|
497 |
+
if analysis.get('concept_graph'):
|
498 |
+
try:
|
499 |
+
# Convertir de base64 a bytes
|
500 |
+
logger.debug("Decodificando gráfico de conceptos")
|
501 |
+
image_data = analysis['concept_graph']
|
502 |
+
|
503 |
+
# Si el gráfico ya es bytes, usarlo directamente
|
504 |
+
if isinstance(image_data, bytes):
|
505 |
+
image_bytes = image_data
|
506 |
+
else:
|
507 |
+
# Si es string base64, decodificar
|
508 |
+
image_bytes = base64.b64decode(image_data)
|
509 |
+
|
510 |
+
logger.debug(f"Longitud de bytes de imagen: {len(image_bytes)}")
|
511 |
+
|
512 |
+
# Mostrar imagen
|
513 |
+
st.image(
|
514 |
+
image_bytes,
|
515 |
+
caption=t.get('concept_network', 'Red de Conceptos'),
|
516 |
+
use_container_width=True
|
517 |
+
)
|
518 |
+
logger.debug("Gráfico mostrado exitosamente")
|
519 |
+
|
520 |
+
except Exception as img_error:
|
521 |
+
logger.error(f"Error procesando gráfico: {str(img_error)}")
|
522 |
+
st.error(t.get('error_loading_graph', 'Error al cargar el gráfico'))
|
523 |
+
else:
|
524 |
+
st.info(t.get('no_graph', 'No hay visualización disponible'))
|
525 |
|
526 |
+
except Exception as e:
|
527 |
+
logger.error(f"Error procesando análisis individual: {str(e)}")
|
528 |
+
continue
|
529 |
+
|
530 |
+
except Exception as e:
|
531 |
+
logger.error(f"Error mostrando análisis semántico: {str(e)}")
|
532 |
+
st.error(t.get('error_semantic', 'Error al mostrar análisis semántico'))
|
533 |
+
|
534 |
+
|
535 |
+
###############################################################################################
|
536 |
def display_discourse_activities(username: str, t: dict):
|
537 |
+
"""Muestra actividades de análisis del discurso (mostrado como 'Análisis comparado de textos' en la UI)"""
|
538 |
try:
|
539 |
logger.info(f"Recuperando análisis del discurso para {username}")
|
540 |
analyses = get_student_discourse_analysis(username)
|
541 |
|
542 |
if not analyses:
|
543 |
logger.info("No se encontraron análisis del discurso")
|
544 |
+
# Usamos el término "análisis comparado de textos" en la UI
|
545 |
st.info(t.get('no_discourse_analyses', 'No hay análisis comparados de textos registrados'))
|
546 |
return
|
547 |
|
|
|
549 |
for analysis in analyses:
|
550 |
try:
|
551 |
# Verificar campos mínimos necesarios
|
552 |
+
if not all(key in analysis for key in ['timestamp']):
|
553 |
+
logger.warning(f"Análisis incompleto: {analysis.keys()}")
|
554 |
continue
|
555 |
|
556 |
# Formatear fecha
|
|
|
581 |
# Mostrar gráficos
|
582 |
st.markdown("### Visualización comparativa")
|
583 |
|
|
|
|
|
584 |
has_graphs = False
|
585 |
|
586 |
+
# Mostrar graph1 (Documento 1)
|
587 |
+
if 'graph1' in analysis:
|
588 |
+
try:
|
589 |
+
# Verificar que sea bytes
|
590 |
+
if isinstance(analysis['graph1'], bytes):
|
591 |
+
st.image(analysis['graph1'],
|
592 |
+
caption="Documento 1",
|
593 |
+
use_container_width=True) # Usar use_container_width en lugar de use_column_width
|
594 |
+
has_graphs = True
|
595 |
+
else:
|
596 |
+
logger.warning(f"graph1 no es bytes: {type(analysis['graph1'])}")
|
597 |
+
except Exception as e:
|
598 |
+
logger.error(f"Error mostrando graph1: {str(e)}")
|
599 |
|
600 |
+
# Mostrar graph2 (Documento 2)
|
601 |
+
if 'graph2' in analysis:
|
602 |
+
try:
|
603 |
+
# Verificar que sea bytes
|
604 |
+
if isinstance(analysis['graph2'], bytes):
|
605 |
+
st.image(analysis['graph2'],
|
606 |
+
caption="Documento 2",
|
607 |
+
use_container_width=True) # Usar use_container_width en lugar de use_column_width
|
608 |
+
has_graphs = True
|
609 |
+
else:
|
610 |
+
logger.warning(f"graph2 no es bytes: {type(analysis['graph2'])}")
|
611 |
+
except Exception as e:
|
612 |
+
logger.error(f"Error mostrando graph2: {str(e)}")
|
613 |
|
614 |
if not has_graphs:
|
615 |
+
st.info(t.get('no_visualization', 'No hay visualización disponible'))
|
616 |
+
|
617 |
+
# Añadir leyenda de interpretación
|
618 |
+
st.markdown("### 📊 " + t.get('graph_interpretation', 'Interpretación del grafo:'))
|
619 |
+
|
620 |
+
st.markdown("""
|
621 |
+
* 🔀 Las flechas indican la dirección de la relación entre conceptos
|
622 |
+
* 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
623 |
+
* ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
624 |
+
* ↔️ El grosor de las líneas indica la fuerza de la conexión
|
625 |
+
""")
|
626 |
|
627 |
except Exception as e:
|
628 |
logger.error(f"Error procesando análisis individual: {str(e)}")
|
|
|
630 |
|
631 |
except Exception as e:
|
632 |
logger.error(f"Error mostrando análisis del discurso: {str(e)}")
|
633 |
+
# Usamos el término "análisis comparado de textos" en la UI
|
634 |
st.error(t.get('error_discourse', 'Error al mostrar análisis comparado de textos'))
|
635 |
|
|
|
|
|
|
|
636 |
#################################################################################
|
637 |
|
638 |
def display_discourse_comparison(analysis: dict, t: dict):
|