File size: 38,628 Bytes
14300fd 6e67ca9 14300fd 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 29af09f 6e67ca9 29af09f 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 10c6edf 6e67ca9 29af09f 6e67ca9 01bf4be 14300fd c58df45 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 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 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
##############
###modules/studentact/student_activities_v2.py
import streamlit as st
import re
import io
from io import BytesIO
import pandas as pd
import numpy as np
import time
import matplotlib.pyplot as plt
from datetime import datetime
from spacy import displacy
import random
import base64
import seaborn as sns
import logging
# Importaciones de la base de datos
from ..database.morphosintax_mongo_db import get_student_morphosyntax_analysis
from ..database.semantic_mongo_db import get_student_semantic_analysis
from ..database.discourse_mongo_db import get_student_discourse_analysis
from ..database.chat_mongo_db import get_chat_history
logger = logging.getLogger(__name__)
###################################################################################
def display_student_activities(username: str, lang_code: str, t: dict):
"""
Muestra todas las actividades del estudiante
Args:
username: Nombre del estudiante
lang_code: Código del idioma
t: Diccionario de traducciones
"""
try:
st.header(t.get('activities_title', 'Mis Actividades'))
# Tabs para diferentes tipos de análisis
tabs = st.tabs([
t.get('morpho_activities', 'Análisis Morfosintáctico'),
t.get('semantic_activities', 'Análisis Semántico'),
t.get('discourse_activities', 'Análisis del Discurso'),
t.get('chat_activities', 'Conversaciones con el Asistente')
])
# Tab de Análisis Morfosintáctico
with tabs[0]:
display_morphosyntax_activities(username, t)
# Tab de Análisis Semántico
with tabs[1]:
display_semantic_activities(username, t)
# Tab de Análisis del Discurso
with tabs[2]:
display_discourse_activities(username, t)
# Tab de Conversaciones del Chat
with tabs[3]:
display_chat_activities(username, t)
except Exception as e:
logger.error(f"Error mostrando actividades: {str(e)}")
st.error(t.get('error_loading_activities', 'Error al cargar las actividades'))
###############################################################################################
def display_morphosyntax_activities(username: str, t: dict):
"""Muestra actividades de análisis morfosintáctico"""
try:
analyses = get_student_morphosyntax_analysis(username)
if not analyses:
st.info(t.get('no_morpho_analyses', 'No hay análisis morfosintácticos registrados'))
return
for analysis in analyses:
with st.expander(
f"{t.get('analysis_date', 'Fecha')}: {analysis['timestamp']}",
expanded=False
):
st.text(f"{t.get('analyzed_text', 'Texto analizado')}:")
st.write(analysis['text'])
if 'arc_diagrams' in analysis:
st.subheader(t.get('syntactic_diagrams', 'Diagramas sintácticos'))
for diagram in analysis['arc_diagrams']:
st.write(diagram, unsafe_allow_html=True)
except Exception as e:
logger.error(f"Error mostrando análisis morfosintáctico: {str(e)}")
st.error(t.get('error_morpho', 'Error al mostrar análisis morfosintáctico'))
###############################################################################################
def display_semantic_activities(username: str, t: dict):
"""Muestra actividades de análisis semántico"""
try:
logger.info(f"Recuperando análisis semántico para {username}")
analyses = get_student_semantic_analysis(username)
if not analyses:
logger.info("No se encontraron análisis semánticos")
st.info(t.get('no_semantic_analyses', 'No hay análisis semánticos registrados'))
return
logger.info(f"Procesando {len(analyses)} análisis semánticos")
for analysis in analyses:
try:
# Verificar campos mínimos necesarios
if not all(key in analysis for key in ['timestamp', 'concept_graph']):
logger.warning(f"Análisis incompleto: {analysis.keys()}")
continue
# Formatear fecha
timestamp = datetime.fromisoformat(analysis['timestamp'].replace('Z', '+00:00'))
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
with st.expander(f"{t.get('analysis_date', 'Fecha')}: {formatted_date}", expanded=False):
if analysis['concept_graph']:
logger.debug("Decodificando gráfico de conceptos")
try:
image_bytes = base64.b64decode(analysis['concept_graph'])
st.image(image_bytes, use_column_width=True)
logger.debug("Gráfico mostrado exitosamente")
except Exception as img_error:
logger.error(f"Error decodificando imagen: {str(img_error)}")
st.error(t.get('error_loading_graph', 'Error al cargar el gráfico'))
else:
st.info(t.get('no_graph', 'No hay visualización disponible'))
except Exception as e:
logger.error(f"Error procesando análisis individual: {str(e)}")
continue
except Exception as e:
logger.error(f"Error mostrando análisis semántico: {str(e)}")
st.error(t.get('error_semantic', 'Error al mostrar análisis semántico'))
###################################################################################################
def display_discourse_activities(username: str, t: dict):
"""Muestra actividades de análisis del discurso"""
try:
logger.info(f"Recuperando análisis del discurso para {username}")
analyses = get_student_discourse_analysis(username)
if not analyses:
logger.info("No se encontraron análisis del discurso")
st.info(t.get('no_discourse_analyses', 'No hay análisis del discurso registrados'))
return
logger.info(f"Procesando {len(analyses)} análisis del discurso")
for analysis in analyses:
try:
# Verificar campos mínimos necesarios
if not all(key in analysis for key in ['timestamp', 'combined_graph']):
logger.warning(f"Análisis incompleto: {analysis.keys()}")
continue
# Formatear fecha
timestamp = datetime.fromisoformat(analysis['timestamp'].replace('Z', '+00:00'))
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
with st.expander(f"{t.get('analysis_date', 'Fecha')}: {formatted_date}", expanded=False):
if analysis['combined_graph']:
logger.debug("Decodificando gráfico combinado")
try:
image_bytes = base64.b64decode(analysis['combined_graph'])
st.image(image_bytes, use_column_width=True)
logger.debug("Gráfico mostrado exitosamente")
except Exception as img_error:
logger.error(f"Error decodificando imagen: {str(img_error)}")
st.error(t.get('error_loading_graph', 'Error al cargar el gráfico'))
else:
st.info(t.get('no_visualization', 'No hay visualización comparativa disponible'))
except Exception as e:
logger.error(f"Error procesando análisis individual: {str(e)}")
continue
except Exception as e:
logger.error(f"Error mostrando análisis del discurso: {str(e)}")
st.error(t.get('error_discourse', 'Error al mostrar análisis del discurso'))
#################################################################################
def display_discourse_comparison(analysis: dict, t: dict):
"""Muestra la comparación de análisis del discurso"""
st.subheader(t.get('comparison_results', 'Resultados de la comparación'))
col1, col2 = st.columns(2)
with col1:
st.markdown(f"**{t.get('concepts_text_1', 'Conceptos Texto 1')}**")
df1 = pd.DataFrame(analysis['key_concepts1'])
st.dataframe(df1)
with col2:
st.markdown(f"**{t.get('concepts_text_2', 'Conceptos Texto 2')}**")
df2 = pd.DataFrame(analysis['key_concepts2'])
st.dataframe(df2)
#################################################################################
def display_chat_activities(username: str, t: dict):
"""
Muestra historial de conversaciones del chat
"""
try:
# Obtener historial del chat
chat_history = get_chat_history(
username=username,
analysis_type='sidebar',
limit=50
)
if not chat_history:
st.info(t.get('no_chat_history', 'No hay conversaciones registradas'))
return
for chat in reversed(chat_history): # Mostrar las más recientes primero
try:
# Convertir timestamp a datetime para formato
timestamp = datetime.fromisoformat(chat['timestamp'].replace('Z', '+00:00'))
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
with st.expander(
f"{t.get('chat_date', 'Fecha de conversación')}: {formatted_date}",
expanded=False
):
if 'messages' in chat and chat['messages']:
# Mostrar cada mensaje en la conversación
for message in chat['messages']:
role = message.get('role', 'unknown')
content = message.get('content', '')
# Usar el componente de chat de Streamlit
with st.chat_message(role):
st.markdown(content)
# Agregar separador entre mensajes
st.divider()
else:
st.warning(t.get('invalid_chat_format', 'Formato de chat no válido'))
except Exception as e:
logger.error(f"Error mostrando conversación: {str(e)}")
continue
except Exception as e:
logger.error(f"Error mostrando historial del chat: {str(e)}")
st.error(t.get('error_chat', 'Error al mostrar historial del chat'))
'''
##########versión 25-9-2024---02:30 ################ OK (username)####################
def display_student_progress(username, lang_code, t, student_data):
st.title(f"{t.get('progress_of', 'Progreso de')} {username}")
if not student_data or len(student_data.get('entries', [])) == 0:
st.warning(t.get("no_data_warning", "No se encontraron datos para este estudiante."))
st.info(t.get("try_analysis", "Intenta realizar algunos análisis de texto primero."))
return
with st.expander(t.get("activities_summary", "Resumen de Actividades"), expanded=True):
total_entries = len(student_data['entries'])
st.write(f"{t.get('total_analyses', 'Total de análisis realizados')}: {total_entries}")
# Gráfico de tipos de análisis
analysis_types = [entry['analysis_type'] for entry in student_data['entries']]
analysis_counts = pd.Series(analysis_types).value_counts()
fig, ax = plt.subplots()
analysis_counts.plot(kind='bar', ax=ax)
ax.set_title(t.get("analysis_types_chart", "Tipos de análisis realizados"))
ax.set_xlabel(t.get("analysis_type", "Tipo de análisis"))
ax.set_ylabel(t.get("count", "Cantidad"))
st.pyplot(fig)
# Mostrar los últimos análisis morfosintácticos
with st.expander(t.get("morphosyntax_history", "Histórico de Análisis Morfosintácticos")):
morphosyntax_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'morphosyntax']
for entry in morphosyntax_entries[:5]: # Mostrar los últimos 5
st.subheader(f"{t.get('analysis_of', 'Análisis del')} {entry['timestamp']}")
if 'arc_diagrams' in entry and entry['arc_diagrams']:
st.components.v1.html(entry['arc_diagrams'][0], height=300, scrolling=True)
# Añadir secciones similares para análisis semánticos y discursivos si es necesario
# Mostrar el historial de chat
with st.expander(t.get("chat_history", "Historial de Chat")):
if 'chat_history' in student_data:
for chat in student_data['chat_history'][:5]: # Mostrar las últimas 5 conversaciones
st.subheader(f"{t.get('chat_from', 'Chat del')} {chat['timestamp']}")
for message in chat['messages']:
st.write(f"{message['role'].capitalize()}: {message['content']}")
st.write("---")
else:
st.write(t.get("no_chat_history", "No hay historial de chat disponible."))
##########versión 24-9-2024---17:30 ################ OK FROM--V2 de def get_student_data(username)####################
def display_student_progress(username, lang_code, t, student_data):
if not student_data or len(student_data['entries']) == 0:
st.warning(t.get("no_data_warning", "No se encontraron datos para este estudiante."))
st.info(t.get("try_analysis", "Intenta realizar algunos análisis de texto primero."))
return
st.title(f"{t.get('progress_of', 'Progreso de')} {username}")
with st.expander(t.get("activities_summary", "Resumen de Actividades y Progreso"), expanded=True):
total_entries = len(student_data['entries'])
st.write(f"{t.get('total_analyses', 'Total de análisis realizados')}: {total_entries}")
# Gráfico de tipos de análisis
analysis_types = [entry['analysis_type'] for entry in student_data['entries']]
analysis_counts = pd.Series(analysis_types).value_counts()
fig, ax = plt.subplots(figsize=(8, 4))
analysis_counts.plot(kind='bar', ax=ax)
ax.set_title(t.get("analysis_types_chart", "Tipos de análisis realizados"))
ax.set_xlabel(t.get("analysis_type", "Tipo de análisis"))
ax.set_ylabel(t.get("count", "Cantidad"))
st.pyplot(fig)
# Histórico de Análisis Morfosintácticos
with st.expander(t.get("morphosyntax_history", "Histórico de Análisis Morfosintácticos")):
morphosyntax_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'morphosyntax']
if not morphosyntax_entries:
st.warning("No se encontraron análisis morfosintácticos.")
for entry in morphosyntax_entries:
st.subheader(f"{t.get('analysis_of', 'Análisis del')} {entry['timestamp']}")
if 'arc_diagrams' in entry and entry['arc_diagrams']:
try:
st.write(entry['arc_diagrams'][0], unsafe_allow_html=True)
except Exception as e:
logger.error(f"Error al mostrar diagrama de arco: {str(e)}")
st.error("Error al mostrar el diagrama de arco.")
else:
st.write(t.get("no_arc_diagram", "No se encontró diagrama de arco para este análisis."))
# Histórico de Análisis Semánticos
with st.expander(t.get("semantic_history", "Histórico de Análisis Semánticos")):
semantic_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'semantic']
if not semantic_entries:
st.warning("No se encontraron análisis semánticos.")
for entry in semantic_entries:
st.subheader(f"{t.get('analysis_of', 'Análisis del')} {entry['timestamp']}")
if 'key_concepts' in entry:
st.write(t.get("key_concepts", "Conceptos clave:"))
concepts_str = " | ".join([f"{concept} ({frequency:.2f})" for concept, frequency in entry['key_concepts']])
st.markdown(f"<div style='background-color: #f0f2f6; padding: 10px; border-radius: 5px;'>{concepts_str}</div>", unsafe_allow_html=True)
if 'graph' in entry:
try:
img_bytes = base64.b64decode(entry['graph'])
st.image(img_bytes, caption=t.get("conceptual_relations_graph", "Gráfico de relaciones conceptuales"))
except Exception as e:
logger.error(f"Error al mostrar gráfico semántico: {str(e)}")
st.error(t.get("graph_display_error", f"No se pudo mostrar el gráfico: {str(e)}"))
# Histórico de Análisis Discursivos
with st.expander(t.get("discourse_history", "Histórico de Análisis Discursivos")):
discourse_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'discourse']
for entry in discourse_entries:
st.subheader(f"{t.get('analysis_of', 'Análisis del')} {entry['timestamp']}")
for i in [1, 2]:
if f'key_concepts{i}' in entry:
st.write(f"{t.get('key_concepts', 'Conceptos clave')} {t.get('document', 'documento')} {i}:")
concepts_str = " | ".join([f"{concept} ({frequency:.2f})" for concept, frequency in entry[f'key_concepts{i}']])
st.markdown(f"<div style='background-color: #f0f2f6; padding: 10px; border-radius: 5px;'>{concepts_str}</div>", unsafe_allow_html=True)
try:
if 'combined_graph' in entry and entry['combined_graph']:
img_bytes = base64.b64decode(entry['combined_graph'])
st.image(img_bytes, caption=t.get("combined_graph", "Gráfico combinado"))
elif 'graph1' in entry and 'graph2' in entry:
col1, col2 = st.columns(2)
with col1:
if entry['graph1']:
img_bytes1 = base64.b64decode(entry['graph1'])
st.image(img_bytes1, caption=t.get("graph_doc1", "Gráfico documento 1"))
with col2:
if entry['graph2']:
img_bytes2 = base64.b64decode(entry['graph2'])
st.image(img_bytes2, caption=t.get("graph_doc2", "Gráfico documento 2"))
except Exception as e:
st.error(t.get("graph_display_error", f"No se pudieron mostrar los gráficos: {str(e)}"))
# Histórico de Conversaciones con el ChatBot
with st.expander(t.get("chatbot_history", "Histórico de Conversaciones con el ChatBot")):
if 'chat_history' in student_data and student_data['chat_history']:
for i, chat in enumerate(student_data['chat_history']):
st.subheader(f"{t.get('conversation', 'Conversación')} {i+1} - {chat['timestamp']}")
for message in chat['messages']:
if message['role'] == 'user':
st.write(f"{t.get('user', 'Usuario')}: {message['content']}")
else:
st.write(f"{t.get('assistant', 'Asistente')}: {message['content']}")
st.write("---")
else:
st.write(t.get("no_chat_history", "No se encontraron conversaciones con el ChatBot."))
# Añadir logs para depuración
if st.checkbox(t.get("show_debug_data", "Mostrar datos de depuración")):
st.write(t.get("student_debug_data", "Datos del estudiante (para depuración):"))
st.json(student_data)
# Mostrar conteo de tipos de análisis
analysis_types = [entry['analysis_type'] for entry in student_data['entries']]
type_counts = {t: analysis_types.count(t) for t in set(analysis_types)}
st.write("Conteo de tipos de análisis:")
st.write(type_counts)
#############################--- Update 16:00 24-9 #########################################
def display_student_progress(username, lang_code, t, student_data):
try:
st.subheader(t.get('student_activities', 'Student Activitie'))
if not student_data or all(len(student_data.get(key, [])) == 0 for key in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses']):
st.warning(t.get('no_data_warning', 'No analysis data found for this student.'))
return
# Resumen de actividades
total_analyses = sum(len(student_data.get(key, [])) for key in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses'])
st.write(f"{t.get('total_analyses', 'Total analyses performed')}: {total_analyses}")
# Gráfico de tipos de análisis
analysis_counts = {
t.get('morpho_analyses', 'Morphosyntactic Analyses'): len(student_data.get('morphosyntax_analyses', [])),
t.get('semantic_analyses', 'Semantic Analyses'): len(student_data.get('semantic_analyses', [])),
t.get('discourse_analyses', 'Discourse Analyses'): len(student_data.get('discourse_analyses', []))
}
# Configurar el estilo de seaborn para un aspecto más atractivo
sns.set_style("whitegrid")
# Crear una figura más pequeña
fig, ax = plt.subplots(figsize=(6, 4))
# Usar colores más atractivos
colors = ['#ff9999', '#66b3ff', '#99ff99']
# Crear el gráfico de barras
bars = ax.bar(analysis_counts.keys(), analysis_counts.values(), color=colors)
# Añadir etiquetas de valor encima de cada barra
for bar in bars:
height = bar.get_height()
ax.text(bar.get_x() + bar.get_width()/2., height,
f'{height}',
ha='center', va='bottom')
# Configurar el título y las etiquetas
ax.set_title(t.get('analysis_types_chart', 'Types of analyses performed'), fontsize=12)
ax.set_ylabel(t.get('count', 'Count'), fontsize=10)
# Rotar las etiquetas del eje x para mejor legibilidad
plt.xticks(rotation=45, ha='right')
# Ajustar el diseño para que todo quepa
plt.tight_layout()
# Mostrar el gráfico en Streamlit
st.pyplot(fig)
# Mostrar los últimos análisis
for analysis_type in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses']:
with st.expander(t.get(f'{analysis_type}_expander', f'{analysis_type.capitalize()} History')):
for analysis in student_data.get(analysis_type, [])[:5]: # Mostrar los últimos 5
st.subheader(f"{t.get('analysis_from', 'Analysis from')} {analysis.get('timestamp', 'N/A')}")
if analysis_type == 'morphosyntax_analyses':
if 'arc_diagrams' in analysis:
st.write(analysis['arc_diagrams'][0], unsafe_allow_html=True)
elif analysis_type == 'semantic_analyses':
if 'key_concepts' in analysis:
st.write(t.get('key_concepts', 'Key concepts'))
st.write(", ".join([f"{concept} ({freq:.2f})" for concept, freq in analysis['key_concepts']]))
if 'graph' in analysis:
st.image(base64.b64decode(analysis['graph']))
elif analysis_type == 'discourse_analyses':
for i in [1, 2]:
if f'key_concepts{i}' in analysis:
st.write(f"{t.get('key_concepts', 'Key concepts')} {t.get('document', 'Document')} {i}")
st.write(", ".join([f"{concept} ({freq:.2f})" for concept, freq in analysis[f'key_concepts{i}']]))
if 'combined_graph' in analysis:
st.image(base64.b64decode(analysis['combined_graph']))
# Mostrar el historial de chat
with st.expander(t.get('chat_history_expander', 'Chat History')):
for chat in student_data.get('chat_history', [])[:5]: # Mostrar las últimas 5 conversaciones
st.subheader(f"{t.get('chat_from', 'Chat from')} {chat.get('timestamp', 'N/A')}")
for message in chat.get('messages', []):
st.write(f"{message.get('role', 'Unknown').capitalize()}: {message.get('content', 'No content')}")
st.write("---")
except Exception as e:
logger.error(f"Error in display_student_progress: {str(e)}", exc_info=True)
st.error(t.get('error_loading_progress', 'Error loading student progress. Please try again later.'))
#####################################################################
def display_student_progress(username, lang_code, t, student_data):
st.subheader(t['student_progress'])
if not student_data or all(len(student_data[key]) == 0 for key in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses']):
st.warning(t['no_data_warning'])
return
# Resumen de actividades
total_analyses = sum(len(student_data[key]) for key in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses'])
st.write(f"{t['total_analyses']}: {total_analyses}")
# Gráfico de tipos de análisis
analysis_counts = {
t['morpho_analyses']: len(student_data['morphosyntax_analyses']),
t['semantic_analyses']: len(student_data['semantic_analyses']),
t['discourse_analyses']: len(student_data['discourse_analyses'])
}
fig, ax = plt.subplots()
ax.bar(analysis_counts.keys(), analysis_counts.values())
ax.set_title(t['analysis_types_chart'])
st.pyplot(fig)
# Mostrar los últimos análisis
for analysis_type in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses']:
with st.expander(t[f'{analysis_type}_expander']):
for analysis in student_data[analysis_type][:5]: # Mostrar los últimos 5
st.subheader(f"{t['analysis_from']} {analysis['timestamp']}")
if analysis_type == 'morphosyntax_analyses':
if 'arc_diagrams' in analysis:
st.write(analysis['arc_diagrams'][0], unsafe_allow_html=True)
elif analysis_type == 'semantic_analyses':
if 'key_concepts' in analysis:
st.write(t['key_concepts'])
st.write(", ".join([f"{concept} ({freq:.2f})" for concept, freq in analysis['key_concepts']]))
if 'graph' in analysis:
st.image(base64.b64decode(analysis['graph']))
elif analysis_type == 'discourse_analyses':
for i in [1, 2]:
if f'key_concepts{i}' in analysis:
st.write(f"{t['key_concepts']} {t['document']} {i}")
st.write(", ".join([f"{concept} ({freq:.2f})" for concept, freq in analysis[f'key_concepts{i}']]))
if 'combined_graph' in analysis:
st.image(base64.b64decode(analysis['combined_graph']))
# Mostrar el historial de chat
with st.expander(t['chat_history_expander']):
for chat in student_data['chat_history'][:5]: # Mostrar las últimas 5 conversaciones
st.subheader(f"{t['chat_from']} {chat['timestamp']}")
for message in chat['messages']:
st.write(f"{message['role'].capitalize()}: {message['content']}")
st.write("---")
def display_student_progress(username, lang_code, t, student_data):
st.subheader(t['student_activities'])
if not student_data or all(len(student_data[key]) == 0 for key in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses']):
st.warning(t['no_data_warning'])
return
# Resumen de actividades
total_analyses = sum(len(student_data[key]) for key in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses'])
st.write(f"{t['total_analyses']}: {total_analyses}")
# Gráfico de tipos de análisis
analysis_counts = {
t['morphological_analysis']: len(student_data['morphosyntax_analyses']),
t['semantic_analyses']: len(student_data['semantic_analyses']),
t['discourse_analyses']: len(student_data['discourse_analyses'])
}
fig, ax = plt.subplots()
ax.bar(analysis_counts.keys(), analysis_counts.values())
ax.set_title(t['analysis_types_chart'])
st.pyplot(fig)
# Mostrar los últimos análisis
for analysis_type in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses']:
with st.expander(t[f'{analysis_type}_expander']):
for analysis in student_data[analysis_type][:5]: # Mostrar los últimos 5
st.subheader(f"{t['analysis_from']} {analysis['timestamp']}")
if analysis_type == 'morphosyntax_analyses':
if 'arc_diagrams' in analysis:
st.write(analysis['arc_diagrams'][0], unsafe_allow_html=True)
elif analysis_type == 'semantic_analyses':
if 'key_concepts' in analysis:
st.write(t['key_concepts'])
st.write(", ".join([f"{concept} ({freq:.2f})" for concept, freq in analysis['key_concepts']]))
if 'graph' in analysis:
st.image(base64.b64decode(analysis['graph']))
elif analysis_type == 'discourse_analyses':
for i in [1, 2]:
if f'key_concepts{i}' in analysis:
st.write(f"{t['key_concepts']} {t['document']} {i}")
st.write(", ".join([f"{concept} ({freq:.2f})" for concept, freq in analysis[f'key_concepts{i}']]))
if 'combined_graph' in analysis:
st.image(base64.b64decode(analysis['combined_graph']))
# Mostrar el historial de chat
with st.expander(t['chat_history_expander']):
for chat in student_data['chat_history'][:5]: # Mostrar las últimas 5 conversaciones
st.subheader(f"{t['chat_from']} {chat['timestamp']}")
for message in chat['messages']:
st.write(f"{message['role'].capitalize()}: {message['content']}")
st.write("---")
def display_student_progress(username, lang_code, t, student_data):
st.subheader(t['student_activities'])
if not student_data or all(len(student_data[key]) == 0 for key in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses']):
st.warning(t['no_data_warning'])
return
# Resumen de actividades
total_analyses = sum(len(student_data[key]) for key in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses'])
st.write(f"{t['total_analyses']}: {total_analyses}")
# Gráfico de tipos de análisis
analysis_counts = {
t['morphological_analysis']: len(student_data['morphosyntax_analyses']),
t['semantic_analyses']: len(student_data['semantic_analyses']),
t['discourse_analyses']: len(student_data['discourse_analyses'])
}
fig, ax = plt.subplots()
ax.bar(analysis_counts.keys(), analysis_counts.values())
ax.set_title(t['analysis_types_chart'])
st.pyplot(fig)
# Mostrar los últimos análisis
for analysis_type in ['morphosyntax_analyses', 'semantic_analyses', 'discourse_analyses']:
with st.expander(t[f'{analysis_type}_expander']):
for analysis in student_data[analysis_type][:5]: # Mostrar los últimos 5
st.subheader(f"{t['analysis_from']} {analysis['timestamp']}")
if analysis_type == 'morphosyntax_analyses':
if 'arc_diagrams' in analysis:
st.write(analysis['arc_diagrams'][0], unsafe_allow_html=True)
elif analysis_type == 'semantic_analyses':
if 'key_concepts' in analysis:
st.write(t['key_concepts'])
st.write(", ".join([f"{concept} ({freq:.2f})" for concept, freq in analysis['key_concepts']]))
if 'graph' in analysis:
st.image(base64.b64decode(analysis['graph']))
elif analysis_type == 'discourse_analyses':
for i in [1, 2]:
if f'key_concepts{i}' in analysis:
st.write(f"{t['key_concepts']} {t['document']} {i}")
st.write(", ".join([f"{concept} ({freq:.2f})" for concept, freq in analysis[f'key_concepts{i}']]))
if 'combined_graph' in analysis:
st.image(base64.b64decode(analysis['combined_graph']))
# Mostrar el historial de chat
with st.expander(t['chat_history_expander']):
for chat in student_data['chat_history'][:5]: # Mostrar las últimas 5 conversaciones
st.subheader(f"{t['chat_from']} {chat['timestamp']}")
for message in chat['messages']:
st.write(f"{message['role'].capitalize()}: {message['content']}")
st.write("---")
def display_student_progress(username, lang_code, t):
st.subheader(t['student_activities'])
st.write(f"{t['activities_message']} {username}")
# Aquí puedes agregar más contenido estático o placeholder
st.info(t['activities_placeholder'])
# Si necesitas mostrar algún dato, puedes usar datos de ejemplo o placeholders
col1, col2, col3 = st.columns(3)
col1.metric(t['morpho_analyses'], "5") # Ejemplo de dato
col2.metric(t['semantic_analyses'], "3") # Ejemplo de dato
col3.metric(t['discourse_analyses'], "2") # Ejemplo de dato
def display_student_progress(username, lang_code, t):
st.title(f"Actividades de {username}")
# Obtener todos los datos del estudiante
student_data = get_student_data(username)
if not student_data or len(student_data.get('entries', [])) == 0:
st.warning("No se encontraron datos de análisis para este estudiante.")
st.info("Intenta realizar algunos análisis de texto primero.")
return
# Resumen de actividades
with st.expander("Resumen de Actividades", expanded=True):
total_entries = len(student_data['entries'])
st.write(f"Total de análisis realizados: {total_entries}")
# Gráfico de tipos de análisis
analysis_types = [entry['analysis_type'] for entry in student_data['entries']]
analysis_counts = pd.Series(analysis_types).value_counts()
fig, ax = plt.subplots()
analysis_counts.plot(kind='bar', ax=ax)
ax.set_title("Tipos de análisis realizados")
ax.set_xlabel("Tipo de análisis")
ax.set_ylabel("Cantidad")
st.pyplot(fig)
# Histórico de Análisis Morfosintácticos
with st.expander("Histórico de Análisis Morfosintácticos"):
morpho_analyses = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'morphosyntax']
for analysis in morpho_analyses[:5]: # Mostrar los últimos 5
st.subheader(f"Análisis del {analysis['timestamp']}")
if 'arc_diagrams' in analysis:
st.write(analysis['arc_diagrams'][0], unsafe_allow_html=True)
# Histórico de Análisis Semánticos
with st.expander("Histórico de Análisis Semánticos"):
semantic_analyses = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'semantic']
for analysis in semantic_analyses[:5]: # Mostrar los últimos 5
st.subheader(f"Análisis del {analysis['timestamp']}")
if 'key_concepts' in analysis:
concepts_str = " | ".join([f"{concept} ({frequency:.2f})" for concept, frequency in analysis['key_concepts']])
st.markdown(f"<div style='background-color: #f0f2f6; padding: 10px; border-radius: 5px;'>{concepts_str}</div>", unsafe_allow_html=True)
if 'graph' in analysis:
try:
img_bytes = base64.b64decode(analysis['graph'])
st.image(img_bytes, caption="Gráfico de relaciones conceptuales")
except Exception as e:
st.error(f"No se pudo mostrar el gráfico: {str(e)}")
# Histórico de Análisis Discursivos
with st.expander("Histórico de Análisis Discursivos"):
discourse_analyses = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'discourse']
for analysis in discourse_analyses[:5]: # Mostrar los últimos 5
st.subheader(f"Análisis del {analysis['timestamp']}")
for i in [1, 2]:
if f'key_concepts{i}' in analysis:
concepts_str = " | ".join([f"{concept} ({frequency:.2f})" for concept, frequency in analysis[f'key_concepts{i}']])
st.write(f"Conceptos clave del documento {i}:")
st.markdown(f"<div style='background-color: #f0f2f6; padding: 10px; border-radius: 5px;'>{concepts_str}</div>", unsafe_allow_html=True)
if 'combined_graph' in analysis:
try:
img_bytes = base64.b64decode(analysis['combined_graph'])
st.image(img_bytes)
except Exception as e:
st.error(f"No se pudo mostrar el gráfico combinado: {str(e)}")
# Histórico de Conversaciones con el ChatBot
with st.expander("Histórico de Conversaciones con el ChatBot"):
if 'chat_history' in student_data:
for i, chat in enumerate(student_data['chat_history'][:5]): # Mostrar las últimas 5 conversaciones
st.subheader(f"Conversación {i+1} - {chat['timestamp']}")
for message in chat['messages']:
st.write(f"{message['role'].capitalize()}: {message['content']}")
st.write("---")
else:
st.write("No se encontraron conversaciones con el ChatBot.")
# Opción para mostrar datos de depuración
if st.checkbox("Mostrar datos de depuración"):
st.write("Datos del estudiante (para depuración):")
st.json(student_data)
''' |