histlearn commited on
Commit
e74ded2
·
verified ·
1 Parent(s): be49d76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -182,47 +182,47 @@ def generate_pdf_report(dataframe, media_tempo_medio_turma, output_pdf_path):
182
  pdf.add_table(dataframe)
183
 
184
  # Gerar gráficos e adicionar ao PDF
185
- def add_bar_labels(ax):
186
- for bar in ax.patches:
187
  height = bar.get_height()
188
- ax.annotate(f'{height}',
189
- xy=(bar.get_x() + bar.get_width() / 2, height),
190
- xytext=(0, 3), # 3 points vertical offset
191
- textcoords="offset points",
192
- ha='center', va='bottom')
193
 
194
  top_students = dataframe.nlargest(5, 'Acertos Absolutos')
195
  plt.figure(figsize=(10, 6))
196
- ax = plt.bar(top_students['Nome do Aluno'], top_students['Acertos Absolutos'], color='blue')
197
  plt.xlabel('Nome do Aluno')
198
  plt.ylabel('Acertos Absolutos')
199
  plt.title('Top 5 Alunos - Acertos Absolutos')
200
  plt.xticks(rotation=45, ha='right')
201
- add_bar_labels(ax)
202
  plt.tight_layout()
203
  graph_path = 'top_5_acertos_absolutos.png'
204
  plt.savefig(graph_path)
205
  pdf.add_image(graph_path)
206
 
207
  plt.figure(figsize=(10, 6))
208
- ax = plt.bar(top_students['Nome do Aluno'], top_students['Média de Acertos'].str.rstrip('%').astype('float'), color='green')
209
  plt.xlabel('Nome do Aluno')
210
  plt.ylabel('Percentual de Acertos (%)')
211
  plt.title('Top 5 Alunos - Percentual de Acertos')
212
  plt.xticks(rotation=45, ha='right')
213
- add_bar_labels(ax)
214
  plt.tight_layout()
215
  graph_path = 'top_5_percentual_acertos.png'
216
  plt.savefig(graph_path)
217
  pdf.add_image(graph_path)
218
 
219
  plt.figure(figsize=(10, 6))
220
- ax = plt.bar(top_students['Nome do Aluno'], top_students['Tarefas Completadas'], color='red')
221
  plt.xlabel('Nome do Aluno')
222
  plt.ylabel('Tarefas Completadas')
223
  plt.title('Top 5 Alunos - Tarefas Completadas')
224
  plt.xticks(rotation=45, ha='right')
225
- add_bar_labels(ax)
226
  plt.tight_layout()
227
  graph_path = 'top_5_tarefas_completadas.png'
228
  plt.savefig(graph_path)
@@ -290,4 +290,3 @@ with gr.Blocks() as interface:
290
  generate_btn.click(fn=wrapper, inputs=[html_file, excel_files], outputs=[output_html, download_html_btn, download_pdf_btn])
291
 
292
  interface.launch()
293
-
 
182
  pdf.add_table(dataframe)
183
 
184
  # Gerar gráficos e adicionar ao PDF
185
+ def add_bar_labels(bars):
186
+ for bar in bars:
187
  height = bar.get_height()
188
+ plt.annotate(f'{height}',
189
+ xy=(bar.get_x() + bar.get_width() / 2, height),
190
+ xytext=(0, 3), # 3 points vertical offset
191
+ textcoords="offset points",
192
+ ha='center', va='bottom')
193
 
194
  top_students = dataframe.nlargest(5, 'Acertos Absolutos')
195
  plt.figure(figsize=(10, 6))
196
+ bars = plt.bar(top_students['Nome do Aluno'], top_students['Acertos Absolutos'], color='blue')
197
  plt.xlabel('Nome do Aluno')
198
  plt.ylabel('Acertos Absolutos')
199
  plt.title('Top 5 Alunos - Acertos Absolutos')
200
  plt.xticks(rotation=45, ha='right')
201
+ add_bar_labels(bars)
202
  plt.tight_layout()
203
  graph_path = 'top_5_acertos_absolutos.png'
204
  plt.savefig(graph_path)
205
  pdf.add_image(graph_path)
206
 
207
  plt.figure(figsize=(10, 6))
208
+ bars = plt.bar(top_students['Nome do Aluno'], top_students['Média de Acertos'].str.rstrip('%').astype('float'), color='green')
209
  plt.xlabel('Nome do Aluno')
210
  plt.ylabel('Percentual de Acertos (%)')
211
  plt.title('Top 5 Alunos - Percentual de Acertos')
212
  plt.xticks(rotation=45, ha='right')
213
+ add_bar_labels(bars)
214
  plt.tight_layout()
215
  graph_path = 'top_5_percentual_acertos.png'
216
  plt.savefig(graph_path)
217
  pdf.add_image(graph_path)
218
 
219
  plt.figure(figsize=(10, 6))
220
+ bars = plt.bar(top_students['Nome do Aluno'], top_students['Tarefas Completadas'], color='red')
221
  plt.xlabel('Nome do Aluno')
222
  plt.ylabel('Tarefas Completadas')
223
  plt.title('Top 5 Alunos - Tarefas Completadas')
224
  plt.xticks(rotation=45, ha='right')
225
+ add_bar_labels(bars)
226
  plt.tight_layout()
227
  graph_path = 'top_5_tarefas_completadas.png'
228
  plt.savefig(graph_path)
 
290
  generate_btn.click(fn=wrapper, inputs=[html_file, excel_files], outputs=[output_html, download_html_btn, download_pdf_btn])
291
 
292
  interface.launch()