Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import os
|
|
5 |
import matplotlib.pyplot as plt
|
6 |
from datetime import timedelta
|
7 |
from fpdf import FPDF
|
|
|
8 |
|
9 |
def parse_duration(duration_str):
|
10 |
try:
|
@@ -51,7 +52,7 @@ def match_alunos(tarefas_csv_path, alunos_csv_path, contador_csv_path):
|
|
51 |
tarefas_df.columns = tarefas_df.columns.str.strip()
|
52 |
alunos_df.columns = alunos_df.columns.str.strip()
|
53 |
|
54 |
-
if 'Aluno' not in tarefas_df.columns or 'Nota' not in tarefas_df.columns or 'Duração'
|
55 |
print(f"Colunas 'Aluno', 'Nota' ou 'Duração' não encontradas no arquivo {tarefas_csv_path}. Pulando este arquivo.")
|
56 |
return
|
57 |
|
@@ -105,6 +106,11 @@ def match_alunos(tarefas_csv_path, alunos_csv_path, contador_csv_path):
|
|
105 |
|
106 |
return result_df
|
107 |
|
|
|
|
|
|
|
|
|
|
|
108 |
def process_all_tarefas_in_directory(directory, alunos_csv_path, contador_csv_path, relatorio_csv_path):
|
109 |
tarefas_files = [os.path.join(directory, f) for f in os.listdir(directory) if f.endswith('.csv') and f not in ['alunos_fim.csv', 'contador_tarefas.csv']]
|
110 |
|
@@ -120,14 +126,21 @@ def process_relatorios(contador_csv_path, relatorio_csv_path):
|
|
120 |
contador_df['Tempo Médio por Tarefa'] = (contador_df['Total Tempo'] / contador_df['Tarefas Completadas']).apply(format_timedelta)
|
121 |
contador_df['Total Tempo'] = contador_df['Total Tempo'].apply(format_timedelta)
|
122 |
contador_df = contador_df.sort_values(by='Tarefas Completadas', ascending=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
contador_df.to_csv(relatorio_csv_path, index=False)
|
124 |
-
return contador_df
|
125 |
|
126 |
-
def generate_pdf_report(dataframe, output_pdf_path):
|
127 |
class PDF(FPDF):
|
128 |
def header(self):
|
129 |
self.set_font('Arial', 'B', 12)
|
130 |
self.cell(0, 10, 'Relatório de Tarefas', 0, 1, 'C')
|
|
|
131 |
|
132 |
def footer(self):
|
133 |
self.set_y(-15)
|
@@ -144,12 +157,19 @@ def generate_pdf_report(dataframe, output_pdf_path):
|
|
144 |
self.cell(col_width, row_height * 2, col, border=1)
|
145 |
self.ln(row_height * 2)
|
146 |
|
147 |
-
# Adiciona os dados
|
148 |
self.set_font('Arial', '', 10)
|
149 |
for row in dataframe.itertuples(index=False):
|
150 |
for item in row:
|
151 |
self.cell(col_width, row_height * 2, str(item), border=1)
|
152 |
self.ln(row_height * 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
def add_image(self, image_path):
|
155 |
self.add_page()
|
@@ -228,14 +248,14 @@ def processar_relatorio(html_file, tarefa_files):
|
|
228 |
contador_csv_path = os.path.join(output_directory, "contador_tarefas.csv")
|
229 |
relatorio_csv_path = os.path.join(output_directory, "relatorio_final.csv")
|
230 |
process_all_tarefas_in_directory(output_directory, alunos_csv_path, contador_csv_path, relatorio_csv_path)
|
231 |
-
df = process_relatorios(contador_csv_path, relatorio_csv_path)
|
232 |
|
233 |
# Salva o relatório em HTML e PDF
|
234 |
html_output_path = os.path.join(output_directory, "relatorio_final.html")
|
235 |
df.to_html(html_output_path, index=False)
|
236 |
|
237 |
pdf_output_path = os.path.join(output_directory, "relatorio_final.pdf")
|
238 |
-
generate_pdf_report(df, pdf_output_path)
|
239 |
|
240 |
return df.to_html(index=False), html_output_path, pdf_output_path
|
241 |
|
|
|
5 |
import matplotlib.pyplot as plt
|
6 |
from datetime import timedelta
|
7 |
from fpdf import FPDF
|
8 |
+
import numpy as np
|
9 |
|
10 |
def parse_duration(duration_str):
|
11 |
try:
|
|
|
52 |
tarefas_df.columns = tarefas_df.columns.str.strip()
|
53 |
alunos_df.columns = alunos_df.columns.str.strip()
|
54 |
|
55 |
+
if 'Aluno' not in tarefas_df.columns or 'Nota' not in tarefas_df.columns or 'Duração' não in tarefas_df.columns:
|
56 |
print(f"Colunas 'Aluno', 'Nota' ou 'Duração' não encontradas no arquivo {tarefas_csv_path}. Pulando este arquivo.")
|
57 |
return
|
58 |
|
|
|
106 |
|
107 |
return result_df
|
108 |
|
109 |
+
def remove_outliers(data, column, threshold=3):
|
110 |
+
mean = data[column].mean()
|
111 |
+
std = data[column].std()
|
112 |
+
return data[(data[column] > mean - threshold * std) & (data[column] < mean + threshold * std)]
|
113 |
+
|
114 |
def process_all_tarefas_in_directory(directory, alunos_csv_path, contador_csv_path, relatorio_csv_path):
|
115 |
tarefas_files = [os.path.join(directory, f) for f in os.listdir(directory) if f.endswith('.csv') and f not in ['alunos_fim.csv', 'contador_tarefas.csv']]
|
116 |
|
|
|
126 |
contador_df['Tempo Médio por Tarefa'] = (contador_df['Total Tempo'] / contador_df['Tarefas Completadas']).apply(format_timedelta)
|
127 |
contador_df['Total Tempo'] = contador_df['Total Tempo'].apply(format_timedelta)
|
128 |
contador_df = contador_df.sort_values(by='Tarefas Completadas', ascending=False)
|
129 |
+
|
130 |
+
# Remove outliers e calcula o tempo médio por tarefa da turma
|
131 |
+
tempo_medio_por_tarefa = remove_outliers(contador_df, 'Tempo Médio por Tarefa')
|
132 |
+
media_tempo_medio_turma = tempo_medio_por_tarefa['Tempo Médio por Tarefa'].mean()
|
133 |
+
media_tempo_medio_turma = format_timedelta(media_tempo_medio_turma)
|
134 |
+
|
135 |
contador_df.to_csv(relatorio_csv_path, index=False)
|
136 |
+
return contador_df, media_tempo_medio_turma
|
137 |
|
138 |
+
def generate_pdf_report(dataframe, media_tempo_medio_turma, output_pdf_path):
|
139 |
class PDF(FPDF):
|
140 |
def header(self):
|
141 |
self.set_font('Arial', 'B', 12)
|
142 |
self.cell(0, 10, 'Relatório de Tarefas', 0, 1, 'C')
|
143 |
+
self.cell(0, 10, f'Tempo Médio por Tarefa da Turma (ajustado): {media_tempo_medio_turma}', 0, 1, 'C')
|
144 |
|
145 |
def footer(self):
|
146 |
self.set_y(-15)
|
|
|
157 |
self.cell(col_width, row_height * 2, col, border=1)
|
158 |
self.ln(row_height * 2)
|
159 |
|
160 |
+
# Adiciona os dados com quebras de página
|
161 |
self.set_font('Arial', '', 10)
|
162 |
for row in dataframe.itertuples(index=False):
|
163 |
for item in row:
|
164 |
self.cell(col_width, row_height * 2, str(item), border=1)
|
165 |
self.ln(row_height * 2)
|
166 |
+
if self.get_y() > self.page_break_trigger - 2 * row_height:
|
167 |
+
self.add_page()
|
168 |
+
self.set_font('Arial', 'B', 10)
|
169 |
+
for col in dataframe.columns:
|
170 |
+
self.cell(col_width, row_height * 2, col, border=1)
|
171 |
+
self.ln(row_height * 2)
|
172 |
+
self.set_font('Arial', '', 10)
|
173 |
|
174 |
def add_image(self, image_path):
|
175 |
self.add_page()
|
|
|
248 |
contador_csv_path = os.path.join(output_directory, "contador_tarefas.csv")
|
249 |
relatorio_csv_path = os.path.join(output_directory, "relatorio_final.csv")
|
250 |
process_all_tarefas_in_directory(output_directory, alunos_csv_path, contador_csv_path, relatorio_csv_path)
|
251 |
+
df, media_tempo_medio_turma = process_relatorios(contador_csv_path, relatorio_csv_path)
|
252 |
|
253 |
# Salva o relatório em HTML e PDF
|
254 |
html_output_path = os.path.join(output_directory, "relatorio_final.html")
|
255 |
df.to_html(html_output_path, index=False)
|
256 |
|
257 |
pdf_output_path = os.path.join(output_directory, "relatorio_final.pdf")
|
258 |
+
generate_pdf_report(df, media_tempo_medio_turma, pdf_output_path)
|
259 |
|
260 |
return df.to_html(index=False), html_output_path, pdf_output_path
|
261 |
|