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