Update modules/studentact/student_activities_v2.py
Browse files
modules/studentact/student_activities_v2.py
CHANGED
@@ -538,109 +538,157 @@ def display_semantic_activities(username: str, t: dict):
|
|
538 |
|
539 |
def display_discourse_activities(username: str, t: dict):
|
540 |
"""
|
541 |
-
|
542 |
-
Ahora muestra los dos gráficos principales uno al lado del otro
|
543 |
"""
|
544 |
try:
|
545 |
-
|
|
|
546 |
|
547 |
-
#
|
548 |
-
|
549 |
|
550 |
-
|
551 |
-
|
|
|
552 |
st.info(t.get('no_discourse_analyses', 'No hay análisis comparados de textos registrados'))
|
553 |
return
|
554 |
-
|
555 |
-
logger.info(f"Procesando {len(analyses)} análisis del discurso")
|
556 |
|
557 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
558 |
try:
|
559 |
-
#
|
|
|
560 |
try:
|
561 |
-
|
562 |
-
|
|
|
|
|
|
|
563 |
except:
|
564 |
-
formatted_date = str(
|
565 |
|
566 |
# Crear expander
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
|
|
|
|
|
|
572 |
|
573 |
-
# Mostrar
|
574 |
-
|
575 |
|
576 |
-
#
|
577 |
-
if
|
578 |
-
|
579 |
col1, col2 = st.columns(2)
|
580 |
|
581 |
-
#
|
582 |
with col1:
|
583 |
-
|
584 |
-
|
585 |
try:
|
586 |
-
#
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
|
|
|
|
|
|
|
|
596 |
else:
|
597 |
-
st.
|
598 |
|
599 |
-
#
|
600 |
with col2:
|
601 |
-
|
602 |
-
|
603 |
try:
|
604 |
-
#
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
|
|
|
|
|
|
|
|
614 |
else:
|
615 |
-
st.
|
616 |
|
617 |
-
#
|
618 |
-
|
619 |
-
|
620 |
-
st.markdown(f"### {t.get('combined_graph_title', 'Visualización Comparativa')}")
|
621 |
-
try:
|
622 |
-
# Si es bytes directamente
|
623 |
-
if isinstance(analysis['combined_graph'], bytes):
|
624 |
-
st.image(analysis['combined_graph'], use_column_width=True)
|
625 |
-
# Si es string base64
|
626 |
-
elif isinstance(analysis['combined_graph'], str):
|
627 |
-
image_bytes = base64.b64decode(analysis['combined_graph'])
|
628 |
-
st.image(image_bytes, use_column_width=True)
|
629 |
-
except Exception as e:
|
630 |
-
logger.error(f"Error mostrando combined_graph: {str(e)}")
|
631 |
-
st.error(t.get('error_graph', 'Error mostrando visualización comparativa'))
|
632 |
|
633 |
-
#
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
640 |
|
641 |
except Exception as e:
|
642 |
-
logger.error(f"Error
|
643 |
-
st.error(
|
|
|
|
|
644 |
|
645 |
#################################################################################
|
646 |
|
|
|
538 |
|
539 |
def display_discourse_activities(username: str, t: dict):
|
540 |
"""
|
541 |
+
Solución simplificada para mostrar análisis de discurso con máxima tolerancia a errores
|
|
|
542 |
"""
|
543 |
try:
|
544 |
+
# Importar directamente la colección
|
545 |
+
from ..database.mongo_db import get_collection
|
546 |
|
547 |
+
# Registrar información de inicio
|
548 |
+
logger.info(f"Intentando obtener análisis de discurso para {username}")
|
549 |
|
550 |
+
# Obtener colección directamente
|
551 |
+
collection = get_collection('student_discourse_analysis')
|
552 |
+
if not collection:
|
553 |
st.info(t.get('no_discourse_analyses', 'No hay análisis comparados de textos registrados'))
|
554 |
return
|
|
|
|
|
555 |
|
556 |
+
# Consulta simplificada: solo por username
|
557 |
+
results = list(collection.find({"username": username}).sort("timestamp", -1))
|
558 |
+
logger.info(f"Recuperados {len(results)} documentos para {username}")
|
559 |
+
|
560 |
+
if not results:
|
561 |
+
st.info(t.get('no_discourse_analyses', 'No hay análisis comparados de textos registrados'))
|
562 |
+
return
|
563 |
+
|
564 |
+
# Mostrar cada resultado
|
565 |
+
for doc in results:
|
566 |
try:
|
567 |
+
# Extraer y formatear fecha con manejo de errores
|
568 |
+
timestamp_str = doc.get('timestamp', 'Fecha desconocida')
|
569 |
try:
|
570 |
+
if isinstance(timestamp_str, str):
|
571 |
+
dt = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
|
572 |
+
formatted_date = dt.strftime("%d/%m/%Y %H:%M:%S")
|
573 |
+
else:
|
574 |
+
formatted_date = str(timestamp_str)
|
575 |
except:
|
576 |
+
formatted_date = str(timestamp_str)
|
577 |
|
578 |
# Crear expander
|
579 |
+
expander_label = f"Análisis: {formatted_date}"
|
580 |
+
with st.expander(expander_label):
|
581 |
+
# Mostrar texto si existe
|
582 |
+
if 'text1' in doc and doc['text1']:
|
583 |
+
st.text_area("Texto analizado",
|
584 |
+
value=doc['text1'],
|
585 |
+
height=100,
|
586 |
+
disabled=True)
|
587 |
|
588 |
+
# Mostrar conceptos clave si existen
|
589 |
+
has_concepts = False
|
590 |
|
591 |
+
# Intentar mostrar conceptos clave en dos columnas
|
592 |
+
if 'key_concepts1' in doc or 'key_concepts2' in doc:
|
593 |
+
has_concepts = True
|
594 |
col1, col2 = st.columns(2)
|
595 |
|
596 |
+
# Columna 1
|
597 |
with col1:
|
598 |
+
st.markdown("**Conceptos clave (Texto 1)**")
|
599 |
+
if 'key_concepts1' in doc and doc['key_concepts1']:
|
600 |
try:
|
601 |
+
# Mostrar simple como texto para evitar errores de formato
|
602 |
+
concepts = doc['key_concepts1']
|
603 |
+
if isinstance(concepts, list):
|
604 |
+
concept_text = ""
|
605 |
+
for c in concepts:
|
606 |
+
if isinstance(c, list) and len(c) >= 2:
|
607 |
+
concept_text += f"• {c[0]}: {c[1]}\n"
|
608 |
+
else:
|
609 |
+
concept_text += f"• {c}\n"
|
610 |
+
st.text(concept_text)
|
611 |
+
else:
|
612 |
+
st.text(str(concepts))
|
613 |
+
except:
|
614 |
+
st.text("Error mostrando conceptos")
|
615 |
else:
|
616 |
+
st.text("Sin conceptos disponibles")
|
617 |
|
618 |
+
# Columna 2
|
619 |
with col2:
|
620 |
+
st.markdown("**Conceptos clave (Texto 2)**")
|
621 |
+
if 'key_concepts2' in doc and doc['key_concepts2']:
|
622 |
try:
|
623 |
+
# Mostrar simple como texto para evitar errores de formato
|
624 |
+
concepts = doc['key_concepts2']
|
625 |
+
if isinstance(concepts, list):
|
626 |
+
concept_text = ""
|
627 |
+
for c in concepts:
|
628 |
+
if isinstance(c, list) and len(c) >= 2:
|
629 |
+
concept_text += f"• {c[0]}: {c[1]}\n"
|
630 |
+
else:
|
631 |
+
concept_text += f"• {c}\n"
|
632 |
+
st.text(concept_text)
|
633 |
+
else:
|
634 |
+
st.text(str(concepts))
|
635 |
+
except:
|
636 |
+
st.text("Error mostrando conceptos")
|
637 |
else:
|
638 |
+
st.text("Sin conceptos disponibles")
|
639 |
|
640 |
+
# Buscar visualizaciones
|
641 |
+
st.markdown("---")
|
642 |
+
st.markdown("**Visualizaciones**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
643 |
|
644 |
+
# Variable para verificar si se mostró alguna visualización
|
645 |
+
shown_images = 0
|
646 |
+
|
647 |
+
# Mostrar todas las visualizaciones posibles
|
648 |
+
for field_name in ['graph1', 'graph2', 'combined_graph']:
|
649 |
+
if field_name in doc and doc[field_name]:
|
650 |
+
try:
|
651 |
+
data = doc[field_name]
|
652 |
+
|
653 |
+
# Si es bytes, mostrar directamente
|
654 |
+
if isinstance(data, bytes):
|
655 |
+
st.image(data, caption=field_name, use_column_width=True)
|
656 |
+
shown_images += 1
|
657 |
+
|
658 |
+
# Si es string, intentar como base64
|
659 |
+
elif isinstance(data, str):
|
660 |
+
try:
|
661 |
+
import base64
|
662 |
+
image_bytes = base64.b64decode(data)
|
663 |
+
st.image(image_bytes, caption=field_name, use_column_width=True)
|
664 |
+
shown_images += 1
|
665 |
+
except:
|
666 |
+
# Si falla la decodificación, solo registrarlo
|
667 |
+
logger.error(f"No se pudo decodificar {field_name}")
|
668 |
+
except Exception as img_err:
|
669 |
+
logger.error(f"Error mostrando {field_name}: {str(img_err)}")
|
670 |
+
|
671 |
+
# Mensaje si no hay visualizaciones
|
672 |
+
if shown_images == 0:
|
673 |
+
st.info("No hay visualizaciones disponibles para este análisis")
|
674 |
+
|
675 |
+
# Mostrar los datos crudos para depuración (opcional)
|
676 |
+
with st.expander("Datos completos del análisis", expanded=False):
|
677 |
+
# Filtrar campos binarios y muy grandes
|
678 |
+
filtered_doc = {k: v for k, v in doc.items()
|
679 |
+
if not isinstance(v, bytes)
|
680 |
+
and not (isinstance(v, str) and len(str(v)) > 500)}
|
681 |
+
st.json(filtered_doc)
|
682 |
+
|
683 |
+
except Exception as doc_err:
|
684 |
+
logger.error(f"Error procesando documento: {str(doc_err)}")
|
685 |
+
st.error(f"Error procesando análisis: {str(doc_err)}")
|
686 |
|
687 |
except Exception as e:
|
688 |
+
logger.error(f"Error general: {str(e)}")
|
689 |
+
st.error(f"Error recuperando análisis: {str(e)}")
|
690 |
+
# Mostrar el error completo para depuración
|
691 |
+
st.exception(e)
|
692 |
|
693 |
#################################################################################
|
694 |
|