Update modules/studentact/student_activities_v2.py
Browse files
modules/studentact/student_activities_v2.py
CHANGED
@@ -536,193 +536,113 @@ def display_semantic_activities(username: str, t: dict):
|
|
536 |
|
537 |
###################################################################################################
|
538 |
|
539 |
-
def
|
540 |
"""
|
541 |
-
Muestra
|
542 |
-
|
543 |
"""
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
return
|
552 |
-
|
553 |
-
logger.info(f"Procesando {len(analyses)} análisis del discurso")
|
554 |
-
for analysis in analyses:
|
555 |
try:
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
continue
|
560 |
-
|
561 |
-
# Formatear fecha
|
562 |
-
timestamp = datetime.fromisoformat(analysis['timestamp'].replace('Z', '+00:00'))
|
563 |
-
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
|
564 |
-
|
565 |
-
# Crear expander para cada análisis
|
566 |
-
with st.expander(f"{t.get('analysis_date', 'Fecha')}: {formatted_date}", expanded=False):
|
567 |
-
# Mostrar conceptos clave primero - esto da contexto al análisis
|
568 |
-
if 'key_concepts1' in analysis and 'key_concepts2' in analysis:
|
569 |
-
col1, col2 = st.columns(2)
|
570 |
-
|
571 |
-
with col1:
|
572 |
-
st.markdown(f"**{t.get('concepts_text_1', 'Conceptos Texto 1')}**")
|
573 |
-
if analysis['key_concepts1']:
|
574 |
-
df1 = pd.DataFrame(analysis['key_concepts1'], columns=['Concepto', 'Relevancia'])
|
575 |
-
st.dataframe(df1, use_container_width=True)
|
576 |
-
|
577 |
-
with col2:
|
578 |
-
st.markdown(f"**{t.get('concepts_text_2', 'Conceptos Texto 2')}**")
|
579 |
-
if analysis['key_concepts2']:
|
580 |
-
df2 = pd.DataFrame(analysis['key_concepts2'], columns=['Concepto', 'Relevancia'])
|
581 |
-
st.dataframe(df2, use_container_width=True)
|
582 |
-
|
583 |
-
# Mostrar los gráficos - siguiendo el estilo de display_semantic_activities
|
584 |
-
|
585 |
-
# Gráfico 1
|
586 |
-
if analysis.get('graph1'):
|
587 |
-
st.markdown("### " + t.get('graph1_title', 'Red de Conceptos - Texto 1'))
|
588 |
-
try:
|
589 |
-
image_data = analysis['graph1']
|
590 |
-
|
591 |
-
# Procesar la imagen según su tipo
|
592 |
-
if isinstance(image_data, bytes):
|
593 |
-
image_bytes = image_data
|
594 |
-
elif isinstance(image_data, str):
|
595 |
-
# Intentar decodificar base64
|
596 |
-
try:
|
597 |
-
if image_data.startswith('data:image'):
|
598 |
-
# Formato data URI
|
599 |
-
import base64
|
600 |
-
image_bytes = base64.b64decode(image_data.split(',')[1])
|
601 |
-
else:
|
602 |
-
# Base64 directo
|
603 |
-
import base64
|
604 |
-
image_bytes = base64.b64decode(image_data)
|
605 |
-
except:
|
606 |
-
logger.error("Error decodificando imagen 1")
|
607 |
-
image_bytes = None
|
608 |
-
else:
|
609 |
-
# Si es otro tipo (como un objeto matplotlib figure)
|
610 |
-
st.pyplot(image_data)
|
611 |
-
image_bytes = None
|
612 |
-
|
613 |
-
# Mostrar imagen si tenemos bytes
|
614 |
-
if image_bytes:
|
615 |
-
st.image(
|
616 |
-
image_bytes,
|
617 |
-
caption=t.get('graph1_caption', 'Red Semántica del Texto 1'),
|
618 |
-
use_column_width=True
|
619 |
-
)
|
620 |
-
except Exception as e:
|
621 |
-
logger.error(f"Error mostrando gráfico 1: {str(e)}")
|
622 |
-
st.error(t.get('error_graph1', 'Error al cargar el gráfico del Texto 1'))
|
623 |
-
|
624 |
-
# Gráfico 2
|
625 |
-
if analysis.get('graph2'):
|
626 |
-
st.markdown("### " + t.get('graph2_title', 'Red de Conceptos - Texto 2'))
|
627 |
-
try:
|
628 |
-
image_data = analysis['graph2']
|
629 |
-
|
630 |
-
# Procesar la imagen según su tipo
|
631 |
-
if isinstance(image_data, bytes):
|
632 |
-
image_bytes = image_data
|
633 |
-
elif isinstance(image_data, str):
|
634 |
-
# Intentar decodificar base64
|
635 |
-
try:
|
636 |
-
if image_data.startswith('data:image'):
|
637 |
-
# Formato data URI
|
638 |
-
import base64
|
639 |
-
image_bytes = base64.b64decode(image_data.split(',')[1])
|
640 |
-
else:
|
641 |
-
# Base64 directo
|
642 |
-
import base64
|
643 |
-
image_bytes = base64.b64decode(image_data)
|
644 |
-
except:
|
645 |
-
logger.error("Error decodificando imagen 2")
|
646 |
-
image_bytes = None
|
647 |
-
else:
|
648 |
-
# Si es otro tipo (como un objeto matplotlib figure)
|
649 |
-
st.pyplot(image_data)
|
650 |
-
image_bytes = None
|
651 |
-
|
652 |
-
# Mostrar imagen si tenemos bytes
|
653 |
-
if image_bytes:
|
654 |
-
st.image(
|
655 |
-
image_bytes,
|
656 |
-
caption=t.get('graph2_caption', 'Red Semántica del Texto 2'),
|
657 |
-
use_column_width=True
|
658 |
-
)
|
659 |
-
except Exception as e:
|
660 |
-
logger.error(f"Error mostrando gráfico 2: {str(e)}")
|
661 |
-
st.error(t.get('error_graph2', 'Error al cargar el gráfico del Texto 2'))
|
662 |
-
|
663 |
-
# Gráfico combinado - el más importante
|
664 |
-
if analysis.get('combined_graph'):
|
665 |
-
st.markdown("### " + t.get('combined_graph_title', 'Análisis Comparativo de Textos'))
|
666 |
-
try:
|
667 |
-
image_data = analysis['combined_graph']
|
668 |
-
|
669 |
-
# Procesar la imagen según su tipo
|
670 |
-
if isinstance(image_data, bytes):
|
671 |
-
image_bytes = image_data
|
672 |
-
elif isinstance(image_data, str):
|
673 |
-
# Intentar decodificar base64
|
674 |
-
try:
|
675 |
-
if image_data.startswith('data:image'):
|
676 |
-
# Formato data URI
|
677 |
-
import base64
|
678 |
-
image_bytes = base64.b64decode(image_data.split(',')[1])
|
679 |
-
else:
|
680 |
-
# Base64 directo
|
681 |
-
import base64
|
682 |
-
image_bytes = base64.b64decode(image_data)
|
683 |
-
except:
|
684 |
-
logger.error("Error decodificando imagen combinada")
|
685 |
-
image_bytes = None
|
686 |
-
else:
|
687 |
-
# Si es otro tipo (como un objeto matplotlib figure)
|
688 |
-
st.pyplot(image_data)
|
689 |
-
image_bytes = None
|
690 |
-
|
691 |
-
# Mostrar imagen si tenemos bytes
|
692 |
-
if image_bytes:
|
693 |
-
st.image(
|
694 |
-
image_bytes,
|
695 |
-
caption=t.get('combined_graph_caption', 'Visualización Comparativa de Redes Semánticas'),
|
696 |
-
use_column_width=True
|
697 |
-
)
|
698 |
-
except Exception as e:
|
699 |
-
logger.error(f"Error mostrando gráfico combinado: {str(e)}")
|
700 |
-
st.error(t.get('error_combined_graph', 'Error al cargar el gráfico comparativo'))
|
701 |
-
|
702 |
-
# Si no hay gráficos disponibles
|
703 |
-
if all(analysis.get(k) is None for k in ['graph1', 'graph2', 'combined_graph']):
|
704 |
-
st.info(t.get('no_graphs', 'No hay visualizaciones disponibles para este análisis'))
|
705 |
-
|
706 |
-
# Si tenemos al menos los conceptos clave, mostrar un mensaje más descriptivo
|
707 |
-
if 'key_concepts1' in analysis and 'key_concepts2' in analysis:
|
708 |
-
st.markdown(t.get('concepts_only_message',
|
709 |
-
"""
|
710 |
-
**Solo se muestran los conceptos clave extraídos de los textos.**
|
711 |
-
Las visualizaciones gráficas no están disponibles para este análisis.
|
712 |
-
"""))
|
713 |
-
|
714 |
except Exception as e:
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
726 |
|
727 |
|
728 |
#################################################################################
|
|
|
536 |
|
537 |
###################################################################################################
|
538 |
|
539 |
+
def display_discourse_comparison(analysis: dict, t: dict):
|
540 |
"""
|
541 |
+
Muestra la comparación de análisis del discurso de manera minimalista pero efectiva.
|
542 |
+
Incluye tanto las tablas de conceptos como los gráficos disponibles.
|
543 |
"""
|
544 |
+
st.subheader(t.get('comparison_results', 'Resultados de la comparación'))
|
545 |
+
|
546 |
+
# 1. Mostrar conceptos en columnas
|
547 |
+
col1, col2 = st.columns(2)
|
548 |
+
with col1:
|
549 |
+
st.markdown(f"**{t.get('concepts_text_1', 'Conceptos Texto 1')}**")
|
550 |
+
if 'key_concepts1' in analysis and analysis['key_concepts1']:
|
|
|
|
|
|
|
|
|
551 |
try:
|
552 |
+
df1 = pd.DataFrame(analysis['key_concepts1'],
|
553 |
+
columns=['Concepto', 'Relevancia'])
|
554 |
+
st.dataframe(df1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
except Exception as e:
|
556 |
+
# En caso de error, mostrar los datos sin procesar
|
557 |
+
st.write(analysis['key_concepts1'])
|
558 |
+
else:
|
559 |
+
st.info(t.get('no_concepts1', 'No hay conceptos disponibles'))
|
560 |
+
|
561 |
+
with col2:
|
562 |
+
st.markdown(f"**{t.get('concepts_text_2', 'Conceptos Texto 2')}**")
|
563 |
+
if 'key_concepts2' in analysis and analysis['key_concepts2']:
|
564 |
+
try:
|
565 |
+
df2 = pd.DataFrame(analysis['key_concepts2'],
|
566 |
+
columns=['Concepto', 'Relevancia'])
|
567 |
+
st.dataframe(df2)
|
568 |
+
except Exception as e:
|
569 |
+
# En caso de error, mostrar los datos sin procesar
|
570 |
+
st.write(analysis['key_concepts2'])
|
571 |
+
else:
|
572 |
+
st.info(t.get('no_concepts2', 'No hay conceptos disponibles'))
|
573 |
+
|
574 |
+
# 2. Mostrar los gráficos si están disponibles
|
575 |
+
st.markdown("---") # Separador
|
576 |
+
|
577 |
+
# Verificar y mostrar gráficos
|
578 |
+
has_graphs = False
|
579 |
+
|
580 |
+
# Gráfico 1
|
581 |
+
if 'graph1' in analysis and analysis['graph1']:
|
582 |
+
has_graphs = True
|
583 |
+
st.markdown(f"### {t.get('graph1_title', 'Gráfico Texto 1')}")
|
584 |
+
try:
|
585 |
+
# Intentar mostrar gráfico (asumiendo que es bytes o base64)
|
586 |
+
if isinstance(analysis['graph1'], bytes):
|
587 |
+
st.image(analysis['graph1'], use_column_width=True)
|
588 |
+
elif isinstance(analysis['graph1'], str):
|
589 |
+
import base64
|
590 |
+
try:
|
591 |
+
image_bytes = base64.b64decode(analysis['graph1'])
|
592 |
+
st.image(image_bytes, use_column_width=True)
|
593 |
+
except:
|
594 |
+
st.error(t.get('error_decoding', 'Error decodificando imagen'))
|
595 |
+
else:
|
596 |
+
# Intentar como objeto matplotlib
|
597 |
+
st.pyplot(analysis['graph1'])
|
598 |
+
except Exception as e:
|
599 |
+
st.error(t.get('error_graph1', 'Error mostrando gráfico 1'))
|
600 |
+
|
601 |
+
# Gráfico 2
|
602 |
+
if 'graph2' in analysis and analysis['graph2']:
|
603 |
+
has_graphs = True
|
604 |
+
st.markdown(f"### {t.get('graph2_title', 'Gráfico Texto 2')}")
|
605 |
+
try:
|
606 |
+
# Intentar mostrar gráfico (asumiendo que es bytes o base64)
|
607 |
+
if isinstance(analysis['graph2'], bytes):
|
608 |
+
st.image(analysis['graph2'], use_column_width=True)
|
609 |
+
elif isinstance(analysis['graph2'], str):
|
610 |
+
import base64
|
611 |
+
try:
|
612 |
+
image_bytes = base64.b64decode(analysis['graph2'])
|
613 |
+
st.image(image_bytes, use_column_width=True)
|
614 |
+
except:
|
615 |
+
st.error(t.get('error_decoding', 'Error decodificando imagen'))
|
616 |
+
else:
|
617 |
+
# Intentar como objeto matplotlib
|
618 |
+
st.pyplot(analysis['graph2'])
|
619 |
+
except Exception as e:
|
620 |
+
st.error(t.get('error_graph2', 'Error mostrando gráfico 2'))
|
621 |
+
|
622 |
+
# Gráfico combinado
|
623 |
+
if 'combined_graph' in analysis and analysis['combined_graph']:
|
624 |
+
has_graphs = True
|
625 |
+
st.markdown(f"### {t.get('combined_graph_title', 'Gráfico Comparativo')}")
|
626 |
+
try:
|
627 |
+
# Intentar mostrar gráfico (asumiendo que es bytes o base64)
|
628 |
+
if isinstance(analysis['combined_graph'], bytes):
|
629 |
+
st.image(analysis['combined_graph'], use_column_width=True)
|
630 |
+
elif isinstance(analysis['combined_graph'], str):
|
631 |
+
import base64
|
632 |
+
try:
|
633 |
+
image_bytes = base64.b64decode(analysis['combined_graph'])
|
634 |
+
st.image(image_bytes, use_column_width=True)
|
635 |
+
except:
|
636 |
+
st.error(t.get('error_decoding', 'Error decodificando imagen'))
|
637 |
+
else:
|
638 |
+
# Intentar como objeto matplotlib
|
639 |
+
st.pyplot(analysis['combined_graph'])
|
640 |
+
except Exception as e:
|
641 |
+
st.error(t.get('error_combined_graph', 'Error mostrando gráfico comparativo'))
|
642 |
+
|
643 |
+
# Mensaje si no hay gráficos
|
644 |
+
if not has_graphs:
|
645 |
+
st.info(t.get('no_graphs_available', 'No hay visualizaciones disponibles para este análisis.'))
|
646 |
|
647 |
|
648 |
#################################################################################
|