|
|
|
|
|
import streamlit as st |
|
import logging |
|
from ..utils.widget_utils import generate_unique_key |
|
from .current_situation_analysis import ( |
|
analyze_text_dimensions, |
|
create_vocabulary_network, |
|
create_syntax_complexity_graph, |
|
create_cohesion_heatmap |
|
) |
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
def display_current_situation_interface(lang_code, nlp_models, t): |
|
""" |
|
Interfaz modular para el análisis de la situación actual del estudiante. |
|
Esta función maneja la presentación y la interacción con el usuario. |
|
|
|
Args: |
|
lang_code: Código del idioma actual |
|
nlp_models: Diccionario de modelos de spaCy cargados |
|
t: Diccionario de traducciones |
|
""" |
|
st.markdown("## Mi Situación Actual de Escritura") |
|
|
|
|
|
with st.container(): |
|
|
|
text_col, visual_col = st.columns([1,2]) |
|
|
|
with text_col: |
|
|
|
text_input = st.text_area( |
|
t.get('current_situation_input', "Ingresa tu texto para analizar:"), |
|
height=400, |
|
key=generate_unique_key("current_situation", "input") |
|
) |
|
|
|
|
|
if st.button( |
|
t.get('analyze_button', "Explorar mi escritura"), |
|
type="primary", |
|
disabled=not text_input, |
|
key=generate_unique_key("current_situation", "analyze") |
|
): |
|
try: |
|
with st.spinner(t.get('processing', "Analizando texto...")): |
|
|
|
doc = nlp_models[lang_code](text_input) |
|
metrics = analyze_text_dimensions(doc) |
|
|
|
|
|
with visual_col: |
|
from .current_situation_analysis import display_current_situation_visual |
|
display_current_situation_visual(doc, metrics) |
|
|
|
|
|
feedback = get_claude_feedback(metrics, text_input) |
|
|
|
|
|
from ..database.current_situation_mongo_db import store_current_situation_result |
|
|
|
if store_current_situation_result( |
|
st.session_state.username, |
|
text_input, |
|
metrics, |
|
feedback |
|
): |
|
st.success(t.get('save_success', "Análisis guardado exitosamente")) |
|
|
|
|
|
show_recommendations(feedback, t) |
|
|
|
except Exception as e: |
|
logger.error(f"Error en análisis de situación actual: {str(e)}") |
|
st.error(t.get('analysis_error', "Error al procesar el análisis")) |
|
|
|
def display_current_situation_visual(doc, metrics): |
|
"""Visualización de resultados""" |
|
try: |
|
with st.container(): |
|
st.subheader("Riqueza de Vocabulario") |
|
vocabulary_graph = create_vocabulary_network(doc) |
|
if vocabulary_graph: |
|
st.pyplot(vocabulary_graph) |
|
plt.close(vocabulary_graph) |
|
|
|
st.subheader("Estructura de Oraciones") |
|
syntax_graph = create_syntax_complexity_graph(doc) |
|
if syntax_graph: |
|
st.pyplot(syntax_graph) |
|
plt.close(syntax_graph) |
|
|
|
st.subheader("Cohesión del Texto") |
|
cohesion_map = create_cohesion_heatmap(doc) |
|
if cohesion_map: |
|
st.pyplot(cohesion_map) |
|
plt.close(cohesion_map) |
|
|
|
except Exception as e: |
|
logger.error(f"Error mostrando visualizaciones: {str(e)}") |
|
st.error("Error al generar visualizaciones") |
|
|
|
def show_recommendations(feedback, t): |
|
""" |
|
Muestra las recomendaciones y ejercicios personalizados para el estudiante, |
|
permitiendo el seguimiento de su progreso. |
|
|
|
Args: |
|
feedback: Diccionario con retroalimentación y ejercicios recomendados |
|
t: Diccionario de traducciones |
|
""" |
|
st.markdown("### " + t.get('recommendations_title', "Recomendaciones para mejorar")) |
|
|
|
for area, exercises in feedback['recommendations'].items(): |
|
with st.expander(f"💡 {area}"): |
|
try: |
|
|
|
st.markdown(exercises['description']) |
|
|
|
|
|
from ..database.current_situation_mongo_db import get_student_exercises_history |
|
exercises_history = get_student_exercises_history(st.session_state.username) |
|
|
|
|
|
completed = exercises_history.get(area, []) |
|
|
|
|
|
progress_col1, progress_col2 = st.columns([3,1]) |
|
with progress_col1: |
|
st.markdown("**Ejercicio sugerido:**") |
|
st.markdown(exercises['activity']) |
|
|
|
with progress_col2: |
|
|
|
exercise_key = f"{area}_{exercises['activity']}" |
|
is_completed = exercise_key in completed |
|
|
|
if is_completed: |
|
st.success("✅ Completado") |
|
else: |
|
|
|
if st.button( |
|
t.get('mark_complete', "Marcar como completado"), |
|
key=generate_unique_key("exercise", area), |
|
type="primary" |
|
): |
|
try: |
|
from ..database.current_situation_mongo_db import update_exercise_status |
|
|
|
|
|
success = update_exercise_status( |
|
username=st.session_state.username, |
|
area=area, |
|
exercise=exercises['activity'], |
|
completed=True |
|
) |
|
|
|
if success: |
|
st.success(t.get( |
|
'exercise_completed', |
|
"¡Ejercicio marcado como completado!" |
|
)) |
|
st.rerun() |
|
else: |
|
st.error(t.get( |
|
'exercise_error', |
|
"Error al actualizar el estado del ejercicio" |
|
)) |
|
except Exception as e: |
|
logger.error(f"Error actualizando estado del ejercicio: {str(e)}") |
|
st.error(t.get('update_error', "Error al actualizar el ejercicio")) |
|
|
|
|
|
if 'resources' in exercises: |
|
st.markdown("**Recursos adicionales:**") |
|
for resource in exercises['resources']: |
|
st.markdown(f"- {resource}") |
|
|
|
|
|
if is_completed: |
|
completion_date = exercises_history[exercise_key].get('completion_date') |
|
if completion_date: |
|
st.caption( |
|
t.get('completed_on', "Completado el") + |
|
f": {completion_date.strftime('%d/%m/%Y %H:%M')}" |
|
) |
|
|
|
except Exception as e: |
|
logger.error(f"Error mostrando recomendaciones para {area}: {str(e)}") |
|
st.error(t.get( |
|
'recommendations_error', |
|
f"Error al mostrar las recomendaciones para {area}" |
|
)) |