Update modules/ui.py
Browse files- modules/ui.py +8 -27
modules/ui.py
CHANGED
@@ -170,53 +170,34 @@ def display_student_progress(username, lang_code='es'):
|
|
170 |
|
171 |
st.title(f"Progreso de {username}")
|
172 |
|
173 |
-
if student_data['
|
174 |
-
st.success(f"Datos obtenidos exitosamente para {username}")
|
175 |
-
|
176 |
-
# Mostrar estadísticas generales
|
177 |
-
st.header("Estadísticas Generales")
|
178 |
-
st.metric("Total de entradas", student_data['entries_count'])
|
179 |
-
|
180 |
-
# Treemap para el conteo de palabras por categoría
|
181 |
-
if student_data['word_count']:
|
182 |
st.subheader("Total de palabras por categoria gramatical")
|
183 |
|
184 |
df = pd.DataFrame(list(student_data['word_count'].items()), columns=['category', 'count'])
|
185 |
df['label'] = df.apply(lambda x: f"{POS_TRANSLATIONS[lang_code].get(x['category'], x['category'])}\n({x['count']})", axis=1)
|
186 |
|
187 |
-
|
188 |
-
print("df:", df)
|
189 |
-
|
190 |
-
fig, ax = plt.subplots(figsize=(8, 6), dpi=30)
|
191 |
colors = [POS_COLORS.get(cat, '#CCCCCC') for cat in df['category']]
|
192 |
-
print("colors:", colors)
|
193 |
-
print("labels:", df['label'].tolist())
|
194 |
|
195 |
-
# Generar el treemap
|
196 |
squarify.plot(sizes=df['count'], label=df['label'], color=colors, alpha=0.8, ax=ax)
|
197 |
-
|
198 |
-
# Después de crear la figura
|
199 |
-
buf = io.BytesIO()
|
200 |
-
fig.savefig(buf, format='png')
|
201 |
-
buf.seek(0)
|
202 |
-
st.image(buf, use_column_width=True)
|
203 |
|
204 |
-
# Ajustar las etiquetas
|
205 |
for text in ax.texts:
|
206 |
text.set_visible(False)
|
207 |
|
208 |
-
# Añadir etiquetas manualmente
|
209 |
norm = plt.Normalize(df['count'].min(), df['count'].max())
|
210 |
for rect, label in zip(ax.patches, df['label']):
|
211 |
x = rect.get_x() + rect.get_width()/2
|
212 |
y = rect.get_y() + rect.get_height()/2
|
213 |
size = norm(rect.get_height() * rect.get_width())
|
214 |
-
ax.text(x, y, label, ha='center', va='center', fontsize=
|
215 |
|
216 |
plt.title('Treemap del total de palabras por categoria gramátical')
|
217 |
plt.axis('off')
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
220 |
else:
|
221 |
st.info("No hay datos de conteo de palabras disponibles.")
|
222 |
|
|
|
170 |
|
171 |
st.title(f"Progreso de {username}")
|
172 |
|
173 |
+
if student_data['word_count']:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
st.subheader("Total de palabras por categoria gramatical")
|
175 |
|
176 |
df = pd.DataFrame(list(student_data['word_count'].items()), columns=['category', 'count'])
|
177 |
df['label'] = df.apply(lambda x: f"{POS_TRANSLATIONS[lang_code].get(x['category'], x['category'])}\n({x['count']})", axis=1)
|
178 |
|
179 |
+
fig, ax = plt.subplots(figsize=(8, 6), dpi=100) # Tamaño reducido
|
|
|
|
|
|
|
180 |
colors = [POS_COLORS.get(cat, '#CCCCCC') for cat in df['category']]
|
|
|
|
|
181 |
|
|
|
182 |
squarify.plot(sizes=df['count'], label=df['label'], color=colors, alpha=0.8, ax=ax)
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
|
|
184 |
for text in ax.texts:
|
185 |
text.set_visible(False)
|
186 |
|
|
|
187 |
norm = plt.Normalize(df['count'].min(), df['count'].max())
|
188 |
for rect, label in zip(ax.patches, df['label']):
|
189 |
x = rect.get_x() + rect.get_width()/2
|
190 |
y = rect.get_y() + rect.get_height()/2
|
191 |
size = norm(rect.get_height() * rect.get_width())
|
192 |
+
ax.text(x, y, label, ha='center', va='center', fontsize=6+size*8) # Tamaño de fuente reducido
|
193 |
|
194 |
plt.title('Treemap del total de palabras por categoria gramátical')
|
195 |
plt.axis('off')
|
196 |
+
|
197 |
+
buf = io.BytesIO()
|
198 |
+
fig.savefig(buf, format='png')
|
199 |
+
buf.seek(0)
|
200 |
+
st.image(buf, use_column_width=True)
|
201 |
else:
|
202 |
st.info("No hay datos de conteo de palabras disponibles.")
|
203 |
|