Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
@@ -33,6 +33,37 @@ plt.rcParams['axes.spines.right'] = False
|
|
33 |
logger = logging.getLogger(__name__)
|
34 |
####################################
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
def display_current_situation_interface(lang_code, nlp_models, t):
|
37 |
"""
|
38 |
Interfaz simplificada con gráfico de radar para visualizar métricas.
|
@@ -48,6 +79,17 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
48 |
st.session_state.current_metrics = None
|
49 |
|
50 |
# st.markdown("## Análisis Inicial de Escritura")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
try:
|
53 |
# Container principal con dos columnas
|
@@ -117,16 +159,40 @@ def display_results(metrics):
|
|
117 |
# Crear dos columnas para métricas y gráfico
|
118 |
metrics_col, graph_col = st.columns([1, 1.5])
|
119 |
|
|
|
120 |
metrics_config = [
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
]
|
126 |
|
127 |
# Mostrar métricas verticalmente
|
128 |
with metrics_col:
|
129 |
-
# Contenedor con bordes para las métricas
|
130 |
st.markdown("""
|
131 |
<style>
|
132 |
.metric-container {
|
@@ -139,52 +205,70 @@ def display_results(metrics):
|
|
139 |
</style>
|
140 |
""", unsafe_allow_html=True)
|
141 |
|
142 |
-
for
|
143 |
with st.container():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
st.metric(
|
145 |
-
label,
|
146 |
f"{value:.2f}",
|
147 |
-
"Meta:
|
148 |
-
delta_color=
|
149 |
-
help=
|
150 |
)
|
151 |
st.markdown("<div style='margin-bottom: 1rem;'></div>", unsafe_allow_html=True)
|
152 |
|
153 |
# Gráfico radar en la columna derecha
|
154 |
with graph_col:
|
155 |
# Preparar datos para el gráfico
|
156 |
-
categories = [m[
|
157 |
-
values_user = [m[
|
158 |
-
|
|
|
159 |
|
160 |
# Crear y configurar gráfico
|
161 |
-
fig = plt.figure(figsize=(8, 8))
|
162 |
ax = fig.add_subplot(111, projection='polar')
|
163 |
|
164 |
-
# Configurar
|
165 |
angles = [n / float(len(categories)) * 2 * np.pi for n in range(len(categories))]
|
166 |
angles += angles[:1]
|
167 |
values_user += values_user[:1]
|
168 |
-
|
|
|
169 |
|
170 |
# Configurar ejes
|
171 |
ax.set_xticks(angles[:-1])
|
172 |
-
ax.set_xticklabels(categories, fontsize=10)
|
173 |
circle_ticks = np.arange(0, 1.1, 0.2)
|
174 |
ax.set_yticks(circle_ticks)
|
175 |
ax.set_yticklabels([f'{tick:.1f}' for tick in circle_ticks], fontsize=8)
|
176 |
ax.set_ylim(0, 1)
|
177 |
|
178 |
-
# Dibujar
|
179 |
-
ax.plot(angles,
|
180 |
-
ax.
|
|
|
|
|
|
|
|
|
181 |
ax.plot(angles, values_user, '#3498db', linewidth=2, label='Tu escritura')
|
182 |
ax.fill(angles, values_user, '#3498db', alpha=0.2)
|
183 |
-
|
184 |
# Ajustar leyenda
|
185 |
ax.legend(
|
186 |
-
loc='upper right',
|
187 |
-
bbox_to_anchor=(0.1, 0.1),
|
188 |
fontsize=10,
|
189 |
frameon=True,
|
190 |
facecolor='white',
|
|
|
33 |
logger = logging.getLogger(__name__)
|
34 |
####################################
|
35 |
|
36 |
+
TEXT_TYPES = {
|
37 |
+
'academic_article': {
|
38 |
+
'name': 'Artículo Académico',
|
39 |
+
'thresholds': {
|
40 |
+
'vocabulary': {'min': 0.70, 'target': 0.85},
|
41 |
+
'structure': {'min': 0.75, 'target': 0.90},
|
42 |
+
'cohesion': {'min': 0.65, 'target': 0.80},
|
43 |
+
'clarity': {'min': 0.70, 'target': 0.85}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
'student_essay': {
|
47 |
+
'name': 'Trabajo Universitario',
|
48 |
+
'thresholds': {
|
49 |
+
'vocabulary': {'min': 0.60, 'target': 0.75},
|
50 |
+
'structure': {'min': 0.65, 'target': 0.80},
|
51 |
+
'cohesion': {'min': 0.55, 'target': 0.70},
|
52 |
+
'clarity': {'min': 0.60, 'target': 0.75}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
'general_communication': {
|
56 |
+
'name': 'Comunicación General',
|
57 |
+
'thresholds': {
|
58 |
+
'vocabulary': {'min': 0.50, 'target': 0.65},
|
59 |
+
'structure': {'min': 0.55, 'target': 0.70},
|
60 |
+
'cohesion': {'min': 0.45, 'target': 0.60},
|
61 |
+
'clarity': {'min': 0.50, 'target': 0.65}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
}
|
65 |
+
####################################
|
66 |
+
|
67 |
def display_current_situation_interface(lang_code, nlp_models, t):
|
68 |
"""
|
69 |
Interfaz simplificada con gráfico de radar para visualizar métricas.
|
|
|
79 |
st.session_state.current_metrics = None
|
80 |
|
81 |
# st.markdown("## Análisis Inicial de Escritura")
|
82 |
+
|
83 |
+
# Añadir selector de tipo de texto
|
84 |
+
text_type = st.selectbox(
|
85 |
+
"Tipo de texto a analizar:",
|
86 |
+
options=list(TEXT_TYPES.keys()),
|
87 |
+
format_func=lambda x: TEXT_TYPES[x]['name'],
|
88 |
+
help="Selecciona el tipo de texto para ajustar los criterios de evaluación"
|
89 |
+
)
|
90 |
+
|
91 |
+
# Guardar el tipo seleccionado en session_state
|
92 |
+
st.session_state.current_text_type = text_type
|
93 |
|
94 |
try:
|
95 |
# Container principal con dos columnas
|
|
|
159 |
# Crear dos columnas para métricas y gráfico
|
160 |
metrics_col, graph_col = st.columns([1, 1.5])
|
161 |
|
162 |
+
# Configuración de métricas con sus umbrales
|
163 |
metrics_config = [
|
164 |
+
{
|
165 |
+
'label': "Vocabulario",
|
166 |
+
'key': 'vocabulary',
|
167 |
+
'value': metrics['vocabulary']['normalized_score'],
|
168 |
+
'help': "Riqueza y variedad del vocabulario",
|
169 |
+
'thresholds': {'min': 0.60, 'target': 0.75}
|
170 |
+
},
|
171 |
+
{
|
172 |
+
'label': "Estructura",
|
173 |
+
'key': 'structure',
|
174 |
+
'value': metrics['structure']['normalized_score'],
|
175 |
+
'help': "Organización y complejidad de oraciones",
|
176 |
+
'thresholds': {'min': 0.65, 'target': 0.80}
|
177 |
+
},
|
178 |
+
{
|
179 |
+
'label': "Cohesión",
|
180 |
+
'key': 'cohesion',
|
181 |
+
'value': metrics['cohesion']['normalized_score'],
|
182 |
+
'help': "Conexión y fluidez entre ideas",
|
183 |
+
'thresholds': {'min': 0.55, 'target': 0.70}
|
184 |
+
},
|
185 |
+
{
|
186 |
+
'label': "Claridad",
|
187 |
+
'key': 'clarity',
|
188 |
+
'value': metrics['clarity']['normalized_score'],
|
189 |
+
'help': "Facilidad de comprensión del texto",
|
190 |
+
'thresholds': {'min': 0.60, 'target': 0.75}
|
191 |
+
}
|
192 |
]
|
193 |
|
194 |
# Mostrar métricas verticalmente
|
195 |
with metrics_col:
|
|
|
196 |
st.markdown("""
|
197 |
<style>
|
198 |
.metric-container {
|
|
|
205 |
</style>
|
206 |
""", unsafe_allow_html=True)
|
207 |
|
208 |
+
for metric in metrics_config:
|
209 |
with st.container():
|
210 |
+
# Determinar estado basado en umbrales
|
211 |
+
value = metric['value']
|
212 |
+
if value < metric['thresholds']['min']:
|
213 |
+
status = "⚠️ Por mejorar"
|
214 |
+
color = "inverse"
|
215 |
+
elif value < metric['thresholds']['target']:
|
216 |
+
status = "📈 Aceptable"
|
217 |
+
color = "off"
|
218 |
+
else:
|
219 |
+
status = "✅ Óptimo"
|
220 |
+
color = "normal"
|
221 |
+
|
222 |
st.metric(
|
223 |
+
metric['label'],
|
224 |
f"{value:.2f}",
|
225 |
+
f"{status} (Meta: {metric['thresholds']['target']:.2f})",
|
226 |
+
delta_color=color,
|
227 |
+
help=metric['help']
|
228 |
)
|
229 |
st.markdown("<div style='margin-bottom: 1rem;'></div>", unsafe_allow_html=True)
|
230 |
|
231 |
# Gráfico radar en la columna derecha
|
232 |
with graph_col:
|
233 |
# Preparar datos para el gráfico
|
234 |
+
categories = [m['label'] for m in metrics_config]
|
235 |
+
values_user = [m['value'] for m in metrics_config]
|
236 |
+
min_values = [m['thresholds']['min'] for m in metrics_config]
|
237 |
+
target_values = [m['thresholds']['target'] for m in metrics_config]
|
238 |
|
239 |
# Crear y configurar gráfico
|
240 |
+
fig = plt.figure(figsize=(8, 8))
|
241 |
ax = fig.add_subplot(111, projection='polar')
|
242 |
|
243 |
+
# Configurar radar
|
244 |
angles = [n / float(len(categories)) * 2 * np.pi for n in range(len(categories))]
|
245 |
angles += angles[:1]
|
246 |
values_user += values_user[:1]
|
247 |
+
min_values += min_values[:1]
|
248 |
+
target_values += target_values[:1]
|
249 |
|
250 |
# Configurar ejes
|
251 |
ax.set_xticks(angles[:-1])
|
252 |
+
ax.set_xticklabels(categories, fontsize=10)
|
253 |
circle_ticks = np.arange(0, 1.1, 0.2)
|
254 |
ax.set_yticks(circle_ticks)
|
255 |
ax.set_yticklabels([f'{tick:.1f}' for tick in circle_ticks], fontsize=8)
|
256 |
ax.set_ylim(0, 1)
|
257 |
|
258 |
+
# Dibujar áreas de umbrales
|
259 |
+
ax.plot(angles, min_values, '#e74c3c', linestyle='--', linewidth=1, label='Mínimo', alpha=0.5)
|
260 |
+
ax.plot(angles, target_values, '#2ecc71', linestyle='--', linewidth=1, label='Meta', alpha=0.5)
|
261 |
+
ax.fill_between(angles, target_values, [1]*len(angles), color='#2ecc71', alpha=0.1)
|
262 |
+
ax.fill_between(angles, [0]*len(angles), min_values, color='#e74c3c', alpha=0.1)
|
263 |
+
|
264 |
+
# Dibujar valores del usuario
|
265 |
ax.plot(angles, values_user, '#3498db', linewidth=2, label='Tu escritura')
|
266 |
ax.fill(angles, values_user, '#3498db', alpha=0.2)
|
267 |
+
|
268 |
# Ajustar leyenda
|
269 |
ax.legend(
|
270 |
+
loc='upper right',
|
271 |
+
bbox_to_anchor=(0.1, 0.1),
|
272 |
fontsize=10,
|
273 |
frameon=True,
|
274 |
facecolor='white',
|