AIdeaText commited on
Commit
1fe4fe1
1 Parent(s): 77fb91b

Update modules/ui.py

Browse files
Files changed (1) hide show
  1. modules/ui.py +17 -16
modules/ui.py CHANGED
@@ -172,28 +172,30 @@ def display_student_progress(username, lang_code='es'):
172
 
173
  if student_data['entries_count'] > 0:
174
  if 'word_count' in student_data and student_data['word_count']:
175
- st.subheader("Total de palabras por categoria gramatical")
176
 
177
  df = pd.DataFrame(list(student_data['word_count'].items()), columns=['category', 'count'])
178
- df['label'] = df.apply(lambda x: f"{POS_TRANSLATIONS[lang_code].get(x['category'], x['category'])}\n({x['count']})", axis=1)
179
 
180
- fig, ax = plt.subplots(figsize=(8, 6), dpi=100) # Tamaño reducido
181
- colors = [POS_COLORS.get(cat, '#CCCCCC') for cat in df['category']]
182
 
183
- squarify.plot(sizes=df['count'], label=df['label'], color=colors, alpha=0.8, ax=ax)
 
184
 
185
- for text in ax.texts:
186
- text.set_visible(False)
 
 
187
 
188
- norm = plt.Normalize(df['count'].min(), df['count'].max())
189
- for rect, label in zip(ax.patches, df['label']):
190
- x = rect.get_x() + rect.get_width()/2
191
- y = rect.get_y() + rect.get_height()/2
192
- size = norm(rect.get_height() * rect.get_width())
193
- ax.text(x, y, label, ha='center', va='center', fontsize=6+size*8) # Tamaño de fuente reducido
194
 
195
- plt.title('Treemap del total de palabras por categoria gramátical')
196
- plt.axis('off')
197
 
198
  buf = io.BytesIO()
199
  fig.savefig(buf, format='png')
@@ -226,7 +228,6 @@ def display_student_progress(username, lang_code='es'):
226
  st.warning("No se encontraron entradas para este estudiante.")
227
  st.info("Intenta realizar algunos análisis de texto primero.")
228
 
229
-
230
  ##############################################################Mostrar entradas recientes######################################################################
231
  #st.header("Entradas Recientes")
232
  #for i, entry in enumerate(student_data['entries'][:5]): # Mostrar las 5 entradas más recientes
 
172
 
173
  if student_data['entries_count'] > 0:
174
  if 'word_count' in student_data and student_data['word_count']:
175
+ st.subheader("Total de palabras por categoría gramatical")
176
 
177
  df = pd.DataFrame(list(student_data['word_count'].items()), columns=['category', 'count'])
178
+ df['label'] = df.apply(lambda x: f"{POS_TRANSLATIONS[lang_code].get(x['category'], x['category'])}", axis=1)
179
 
180
+ # Ordenar el DataFrame por conteo de palabras, de mayor a menor
181
+ df = df.sort_values('count', ascending=False)
182
 
183
+ fig, ax = plt.subplots(figsize=(12, 6))
184
+ bars = ax.bar(df['label'], df['count'], color=[POS_COLORS.get(cat, '#CCCCCC') for cat in df['category']])
185
 
186
+ ax.set_xlabel('Categoría Gramatical')
187
+ ax.set_ylabel('Cantidad de Palabras')
188
+ ax.set_title('Total de palabras por categoría gramatical')
189
+ plt.xticks(rotation=45, ha='right')
190
 
191
+ # Añadir etiquetas de valor en las barras
192
+ for bar in bars:
193
+ height = bar.get_height()
194
+ ax.text(bar.get_x() + bar.get_width()/2., height,
195
+ f'{height}',
196
+ ha='center', va='bottom')
197
 
198
+ plt.tight_layout()
 
199
 
200
  buf = io.BytesIO()
201
  fig.savefig(buf, format='png')
 
228
  st.warning("No se encontraron entradas para este estudiante.")
229
  st.info("Intenta realizar algunos análisis de texto primero.")
230
 
 
231
  ##############################################################Mostrar entradas recientes######################################################################
232
  #st.header("Entradas Recientes")
233
  #for i, entry in enumerate(student_data['entries'][:5]): # Mostrar las 5 entradas más recientes