Spaces:
Sleeping
Sleeping
Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
|
@@ -1,15 +1,14 @@
|
|
| 1 |
# modules/studentact/current_situation_interface-vOK.py
|
| 2 |
-
|
| 3 |
import streamlit as st
|
| 4 |
import logging
|
| 5 |
from ..utils.widget_utils import generate_unique_key
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
import numpy as np
|
|
|
|
| 8 |
|
| 9 |
# Importaciones locales
|
| 10 |
-
from translations import get_translations
|
| 11 |
-
|
| 12 |
-
from ..database.current_situation_mongo_db import store_current_situation_result
|
| 13 |
|
| 14 |
from .current_situation_analysis import (
|
| 15 |
analyze_text_dimensions,
|
|
@@ -24,7 +23,7 @@ from .current_situation_analysis import (
|
|
| 24 |
generate_connection_paths,
|
| 25 |
create_vocabulary_network,
|
| 26 |
create_syntax_complexity_graph,
|
| 27 |
-
create_cohesion_heatmap
|
| 28 |
)
|
| 29 |
|
| 30 |
# Configuración del estilo de matplotlib para el gráfico de radar
|
|
@@ -160,7 +159,6 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
| 160 |
|
| 161 |
###################################3333
|
| 162 |
|
| 163 |
-
'''
|
| 164 |
def display_results(metrics, text_type=None):
|
| 165 |
"""
|
| 166 |
Muestra los resultados del análisis: métricas verticalmente y gráfico radar.
|
|
@@ -237,91 +235,7 @@ def display_results(metrics, text_type=None):
|
|
| 237 |
except Exception as e:
|
| 238 |
logger.error(f"Error mostrando resultados: {str(e)}")
|
| 239 |
st.error("Error al mostrar los resultados")
|
| 240 |
-
'''
|
| 241 |
|
| 242 |
-
def display_results(metrics, text_type=None, t=None):
|
| 243 |
-
"""
|
| 244 |
-
Muestra los resultados del análisis: métricas verticalmente y gráfico radar,
|
| 245 |
-
junto con recomendaciones personalizadas en el idioma seleccionado.
|
| 246 |
-
"""
|
| 247 |
-
try:
|
| 248 |
-
# Usar valor por defecto si no se especifica tipo
|
| 249 |
-
text_type = text_type or 'student_essay'
|
| 250 |
-
|
| 251 |
-
# Obtener el código de idioma actual
|
| 252 |
-
lang_code = st.session_state.lang_code
|
| 253 |
-
|
| 254 |
-
# Obtener traducciones si no se proporcionaron
|
| 255 |
-
if t is None:
|
| 256 |
-
t = get_translations(lang_code)
|
| 257 |
-
|
| 258 |
-
# Obtener umbrales según el tipo de texto
|
| 259 |
-
thresholds = TEXT_TYPES[text_type]['thresholds']
|
| 260 |
-
|
| 261 |
-
# Crear dos columnas para las métricas y el gráfico
|
| 262 |
-
metrics_col, graph_col = st.columns([1, 1.5])
|
| 263 |
-
|
| 264 |
-
# Columna de métricas
|
| 265 |
-
with metrics_col:
|
| 266 |
-
metrics_config = [
|
| 267 |
-
{
|
| 268 |
-
'label': t.get('SITUATION_ANALYSIS', {}).get('vocabulary', "Vocabulario"),
|
| 269 |
-
'key': 'vocabulary',
|
| 270 |
-
'value': metrics['vocabulary']['normalized_score'],
|
| 271 |
-
'help': t.get('SITUATION_ANALYSIS', {}).get('vocabulary_help', "Riqueza y variedad del vocabulario"),
|
| 272 |
-
'thresholds': thresholds['vocabulary']
|
| 273 |
-
},
|
| 274 |
-
{
|
| 275 |
-
'label': t.get('SITUATION_ANALYSIS', {}).get('structure', "Estructura"),
|
| 276 |
-
'key': 'structure',
|
| 277 |
-
'value': metrics['structure']['normalized_score'],
|
| 278 |
-
'help': t.get('SITUATION_ANALYSIS', {}).get('structure_help', "Organización y complejidad de oraciones"),
|
| 279 |
-
'thresholds': thresholds['structure']
|
| 280 |
-
},
|
| 281 |
-
{
|
| 282 |
-
'label': t.get('SITUATION_ANALYSIS', {}).get('cohesion', "Cohesión"),
|
| 283 |
-
'key': 'cohesion',
|
| 284 |
-
'value': metrics['cohesion']['normalized_score'],
|
| 285 |
-
'help': t.get('SITUATION_ANALYSIS', {}).get('cohesion_help', "Conexión entre ideas y párrafos"),
|
| 286 |
-
'thresholds': thresholds['cohesion']
|
| 287 |
-
},
|
| 288 |
-
{
|
| 289 |
-
'label': t.get('SITUATION_ANALYSIS', {}).get('clarity', "Claridad"),
|
| 290 |
-
'key': 'clarity',
|
| 291 |
-
'value': metrics['clarity']['normalized_score'],
|
| 292 |
-
'help': t.get('SITUATION_ANALYSIS', {}).get('clarity_help', "Facilidad de comprensión"),
|
| 293 |
-
'thresholds': thresholds['clarity']
|
| 294 |
-
}
|
| 295 |
-
]
|
| 296 |
-
|
| 297 |
-
# Mostrar las métricas como barras verticales
|
| 298 |
-
for metric in metrics_config:
|
| 299 |
-
st.metric(
|
| 300 |
-
label=f"{metric['label']} - {int(metric['value']*100)}%" or "Métrica",
|
| 301 |
-
value="",
|
| 302 |
-
help=metric['help']
|
| 303 |
-
)
|
| 304 |
-
st.progress(metric['value'])
|
| 305 |
-
st.markdown("---")
|
| 306 |
-
|
| 307 |
-
# Columna del gráfico radar
|
| 308 |
-
with graph_col:
|
| 309 |
-
# Generar y mostrar el gráfico radar
|
| 310 |
-
fig = create_radar_chart(metrics, t)
|
| 311 |
-
st.pyplot(fig)
|
| 312 |
-
|
| 313 |
-
# Generar recomendaciones basadas en métricas y tipo de texto
|
| 314 |
-
recommendations = generate_recommendations(metrics, text_type, lang_code, t)
|
| 315 |
-
|
| 316 |
-
# Mostrar sección de recomendaciones
|
| 317 |
-
st.subheader(t.get('SITUATION_ANALYSIS', {}).get('recommendations_title', "Recomendaciones para mejorar"))
|
| 318 |
-
|
| 319 |
-
# Mostrar recomendaciones en tarjetas con estilo
|
| 320 |
-
display_recommendations(recommendations, t)
|
| 321 |
-
|
| 322 |
-
except Exception as e:
|
| 323 |
-
logger.error(f"Error displaying results: {str(e)}")
|
| 324 |
-
st.error(t.get('SITUATION_ANALYSIS', {}).get('display_error', "Error al mostrar los resultados del análisis"))
|
| 325 |
|
| 326 |
######################################
|
| 327 |
def display_radar_chart(metrics_config, thresholds):
|
|
@@ -382,4 +296,93 @@ def display_radar_chart(metrics_config, thresholds):
|
|
| 382 |
except Exception as e:
|
| 383 |
logger.error(f"Error mostrando gráfico radar: {str(e)}")
|
| 384 |
st.error("Error al mostrar el gráfico")
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# modules/studentact/current_situation_interface-vOK.py
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
import logging
|
| 5 |
from ..utils.widget_utils import generate_unique_key
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
import numpy as np
|
| 8 |
+
from ..database.current_situation_mongo_db import store_current_situation_result
|
| 9 |
|
| 10 |
# Importaciones locales
|
| 11 |
+
from translations import get_translations
|
|
|
|
|
|
|
| 12 |
|
| 13 |
from .current_situation_analysis import (
|
| 14 |
analyze_text_dimensions,
|
|
|
|
| 23 |
generate_connection_paths,
|
| 24 |
create_vocabulary_network,
|
| 25 |
create_syntax_complexity_graph,
|
| 26 |
+
create_cohesion_heatmap,
|
| 27 |
)
|
| 28 |
|
| 29 |
# Configuración del estilo de matplotlib para el gráfico de radar
|
|
|
|
| 159 |
|
| 160 |
###################################3333
|
| 161 |
|
|
|
|
| 162 |
def display_results(metrics, text_type=None):
|
| 163 |
"""
|
| 164 |
Muestra los resultados del análisis: métricas verticalmente y gráfico radar.
|
|
|
|
| 235 |
except Exception as e:
|
| 236 |
logger.error(f"Error mostrando resultados: {str(e)}")
|
| 237 |
st.error("Error al mostrar los resultados")
|
|
|
|
| 238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
######################################
|
| 241 |
def display_radar_chart(metrics_config, thresholds):
|
|
|
|
| 296 |
except Exception as e:
|
| 297 |
logger.error(f"Error mostrando gráfico radar: {str(e)}")
|
| 298 |
st.error("Error al mostrar el gráfico")
|
| 299 |
+
|
| 300 |
+
#####################################################
|
| 301 |
+
def display_recommendations(recommendations, t):
|
| 302 |
+
"""
|
| 303 |
+
Muestra las recomendaciones con un diseño de tarjetas.
|
| 304 |
+
"""
|
| 305 |
+
# Definir colores para cada categoría
|
| 306 |
+
colors = {
|
| 307 |
+
'vocabulary': '#2E86C1', # Azul
|
| 308 |
+
'structure': '#28B463', # Verde
|
| 309 |
+
'cohesion': '#F39C12', # Naranja
|
| 310 |
+
'clarity': '#9B59B6', # Púrpura
|
| 311 |
+
'priority': '#E74C3C' # Rojo para la categoría prioritaria
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
# Iconos para cada categoría
|
| 315 |
+
icons = {
|
| 316 |
+
'vocabulary': '📚',
|
| 317 |
+
'structure': '🏗️',
|
| 318 |
+
'cohesion': '🔄',
|
| 319 |
+
'clarity': '💡',
|
| 320 |
+
'priority': '⭐'
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
# Obtener traducciones para cada dimensión
|
| 324 |
+
dimension_names = {
|
| 325 |
+
'vocabulary': t.get('SITUATION_ANALYSIS', {}).get('vocabulary', "Vocabulario"),
|
| 326 |
+
'structure': t.get('SITUATION_ANALYSIS', {}).get('structure', "Estructura"),
|
| 327 |
+
'cohesion': t.get('SITUATION_ANALYSIS', {}).get('cohesion', "Cohesión"),
|
| 328 |
+
'clarity': t.get('SITUATION_ANALYSIS', {}).get('clarity', "Claridad"),
|
| 329 |
+
'priority': t.get('SITUATION_ANALYSIS', {}).get('priority', "Prioridad")
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
# Título de la sección prioritaria
|
| 333 |
+
priority_focus = t.get('SITUATION_ANALYSIS', {}).get('priority_focus', 'Área prioritaria para mejorar')
|
| 334 |
+
st.markdown(f"### {icons['priority']} {priority_focus}")
|
| 335 |
+
|
| 336 |
+
# Determinar área prioritaria (la que tiene menor puntuación)
|
| 337 |
+
priority_area = recommendations.get('priority', 'vocabulary')
|
| 338 |
+
priority_title = dimension_names.get(priority_area, "Área prioritaria")
|
| 339 |
+
|
| 340 |
+
# Determinar el contenido para mostrar
|
| 341 |
+
if isinstance(recommendations[priority_area], dict) and 'title' in recommendations[priority_area]:
|
| 342 |
+
priority_title = recommendations[priority_area]['title']
|
| 343 |
+
priority_content = recommendations[priority_area]['content']
|
| 344 |
+
else:
|
| 345 |
+
priority_content = recommendations[priority_area]
|
| 346 |
+
|
| 347 |
+
# Mostrar la recomendación prioritaria con un estilo destacado
|
| 348 |
+
with st.container():
|
| 349 |
+
st.markdown(
|
| 350 |
+
f"""
|
| 351 |
+
<div style="border:2px solid {colors['priority']}; border-radius:5px; padding:15px; margin-bottom:20px;">
|
| 352 |
+
<h4 style="color:{colors['priority']};">{priority_title}</h4>
|
| 353 |
+
<p>{priority_content}</p>
|
| 354 |
+
</div>
|
| 355 |
+
""",
|
| 356 |
+
unsafe_allow_html=True
|
| 357 |
+
)
|
| 358 |
+
|
| 359 |
+
# Crear dos columnas para las tarjetas de recomendaciones restantes
|
| 360 |
+
col1, col2 = st.columns(2)
|
| 361 |
+
|
| 362 |
+
# Distribuir las recomendaciones en las columnas
|
| 363 |
+
categories = ['vocabulary', 'structure', 'cohesion', 'clarity']
|
| 364 |
+
for i, category in enumerate(categories):
|
| 365 |
+
# Saltar si esta categoría ya es la prioritaria
|
| 366 |
+
if category == priority_area:
|
| 367 |
+
continue
|
| 368 |
+
|
| 369 |
+
# Determinar título y contenido
|
| 370 |
+
if isinstance(recommendations[category], dict) and 'title' in recommendations[category]:
|
| 371 |
+
category_title = recommendations[category]['title']
|
| 372 |
+
category_content = recommendations[category]['content']
|
| 373 |
+
else:
|
| 374 |
+
category_title = dimension_names.get(category, category)
|
| 375 |
+
category_content = recommendations[category]
|
| 376 |
+
|
| 377 |
+
# Alternar entre columnas
|
| 378 |
+
with col1 if i % 2 == 0 else col2:
|
| 379 |
+
# Crear tarjeta para cada recomendación
|
| 380 |
+
st.markdown(
|
| 381 |
+
f"""
|
| 382 |
+
<div style="border:1px solid {colors[category]}; border-radius:5px; padding:10px; margin-bottom:15px;">
|
| 383 |
+
<h4 style="color:{colors[category]};">{icons[category]} {category_title}</h4>
|
| 384 |
+
<p>{category_content}</p>
|
| 385 |
+
</div>
|
| 386 |
+
""",
|
| 387 |
+
unsafe_allow_html=True
|
| 388 |
+
)
|