Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ import seaborn as sns
|
|
| 13 |
from matplotlib.colors import LinearSegmentedColormap
|
| 14 |
from matplotlib.ticker import MaxNLocator
|
| 15 |
from math import ceil
|
|
|
|
| 16 |
|
| 17 |
# Configura o estilo seaborn e suprime warnings
|
| 18 |
warnings.filterwarnings('ignore')
|
|
@@ -248,44 +249,29 @@ class ReportGenerator:
|
|
| 248 |
plt.grid(True, alpha=0.2, linestyle='--')
|
| 249 |
plt.gca().set_facecolor('#f8f9fa')
|
| 250 |
|
|
|
|
|
|
|
| 251 |
# Scatter plot com cores por nível
|
| 252 |
for nivel, color in self.colors.items():
|
| 253 |
mask = self.data['Nível'] == nivel
|
| 254 |
tempo = pd.to_timedelta(self.data[mask]['Total Tempo']).dt.total_seconds() / 60
|
|
|
|
| 255 |
|
| 256 |
-
|
| 257 |
-
|
| 258 |
|
| 259 |
-
#
|
| 260 |
-
for x, y, nome in zip(tempo, self.data[mask]['
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
plt.annotate(nome,
|
| 272 |
-
xy=(x, y),
|
| 273 |
-
xytext=(x + offset[0]/5, y + 0.3),
|
| 274 |
-
ha=ha,
|
| 275 |
-
va='bottom',
|
| 276 |
-
fontsize=8,
|
| 277 |
-
bbox=dict(
|
| 278 |
-
facecolor='white',
|
| 279 |
-
edgecolor='none',
|
| 280 |
-
alpha=0.8,
|
| 281 |
-
pad=0.5
|
| 282 |
-
),
|
| 283 |
-
arrowprops=dict(
|
| 284 |
-
arrowstyle='-',
|
| 285 |
-
color='gray',
|
| 286 |
-
alpha=0.3,
|
| 287 |
-
connectionstyle='arc3,rad=0'
|
| 288 |
-
))
|
| 289 |
|
| 290 |
plt.title('Relação entre Tempo e Acertos por Nível', pad=20)
|
| 291 |
plt.xlabel('Tempo Total (minutos)')
|
|
@@ -312,45 +298,21 @@ class ReportGenerator:
|
|
| 312 |
plt.grid(True, alpha=0.2, linestyle='--')
|
| 313 |
plt.gca().set_facecolor('#f8f9fa')
|
| 314 |
|
|
|
|
|
|
|
| 315 |
# Scatter plot com cores por nível
|
| 316 |
for nivel, color in self.colors.items():
|
| 317 |
mask = self.data['Nível'] == nivel
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
if x > np.median(self.data['Tarefas Completadas']):
|
| 329 |
-
ha = 'right'
|
| 330 |
-
offset = (-10, 0)
|
| 331 |
-
else:
|
| 332 |
-
ha = 'left'
|
| 333 |
-
offset = (10, 0)
|
| 334 |
-
|
| 335 |
-
# Adicionar pequena linha conectora
|
| 336 |
-
plt.annotate(row['Nome do Aluno'],
|
| 337 |
-
xy=(x, y),
|
| 338 |
-
xytext=(x + offset[0]/5, y + 0.3),
|
| 339 |
-
ha=ha,
|
| 340 |
-
va='bottom',
|
| 341 |
-
fontsize=8,
|
| 342 |
-
bbox=dict(
|
| 343 |
-
facecolor='white',
|
| 344 |
-
edgecolor='none',
|
| 345 |
-
alpha=0.8,
|
| 346 |
-
pad=0.5
|
| 347 |
-
),
|
| 348 |
-
arrowprops=dict(
|
| 349 |
-
arrowstyle='-',
|
| 350 |
-
color='gray',
|
| 351 |
-
alpha=0.3,
|
| 352 |
-
connectionstyle='arc3,rad=0'
|
| 353 |
-
))
|
| 354 |
|
| 355 |
# Linha de tendência
|
| 356 |
z = np.polyfit(self.data['Tarefas Completadas'],
|
|
@@ -362,6 +324,14 @@ class ReportGenerator:
|
|
| 362 |
plt.plot(x_range, p(x_range), "--", color='#e74c3c', alpha=0.8,
|
| 363 |
label='Tendência', linewidth=2)
|
| 364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
plt.title('Relação entre Tarefas Completadas e Acertos', pad=20)
|
| 366 |
plt.xlabel('Número de Tarefas Completadas')
|
| 367 |
plt.ylabel('Número de Acertos')
|
|
|
|
| 13 |
from matplotlib.colors import LinearSegmentedColormap
|
| 14 |
from matplotlib.ticker import MaxNLocator
|
| 15 |
from math import ceil
|
| 16 |
+
from adjustText import adjust_text
|
| 17 |
|
| 18 |
# Configura o estilo seaborn e suprime warnings
|
| 19 |
warnings.filterwarnings('ignore')
|
|
|
|
| 249 |
plt.grid(True, alpha=0.2, linestyle='--')
|
| 250 |
plt.gca().set_facecolor('#f8f9fa')
|
| 251 |
|
| 252 |
+
texts = [] # Lista para armazenar todos os textos
|
| 253 |
+
|
| 254 |
# Scatter plot com cores por nível
|
| 255 |
for nivel, color in self.colors.items():
|
| 256 |
mask = self.data['Nível'] == nivel
|
| 257 |
tempo = pd.to_timedelta(self.data[mask]['Total Tempo']).dt.total_seconds() / 60
|
| 258 |
+
acertos = self.data[mask]['Acertos Absolutos']
|
| 259 |
|
| 260 |
+
# Criar scatter plot
|
| 261 |
+
plt.scatter(tempo, acertos, c=color, label=nivel, alpha=0.7, s=150)
|
| 262 |
|
| 263 |
+
# Adicionar textos à lista
|
| 264 |
+
for x, y, nome in zip(tempo, acertos, self.data[mask]['Nome do Aluno']):
|
| 265 |
+
texts.append(plt.text(x, y, nome, fontsize=8,
|
| 266 |
+
bbox=dict(facecolor='white', edgecolor='none', alpha=0.8, pad=0.5)))
|
| 267 |
+
|
| 268 |
+
# Ajustar posição dos textos automaticamente
|
| 269 |
+
adjust_text(texts,
|
| 270 |
+
force_points=0.2, # Força entre pontos
|
| 271 |
+
force_text=0.2, # Força entre textos
|
| 272 |
+
expand_points=(1.2, 1.2), # Expansão dos pontos
|
| 273 |
+
expand_text=(1.2, 1.2), # Expansão dos textos
|
| 274 |
+
arrowprops=dict(arrowstyle='-', color='gray', alpha=0.3, lw=0.5))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
plt.title('Relação entre Tempo e Acertos por Nível', pad=20)
|
| 277 |
plt.xlabel('Tempo Total (minutos)')
|
|
|
|
| 298 |
plt.grid(True, alpha=0.2, linestyle='--')
|
| 299 |
plt.gca().set_facecolor('#f8f9fa')
|
| 300 |
|
| 301 |
+
texts = [] # Lista para armazenar todos os textos
|
| 302 |
+
|
| 303 |
# Scatter plot com cores por nível
|
| 304 |
for nivel, color in self.colors.items():
|
| 305 |
mask = self.data['Nível'] == nivel
|
| 306 |
+
tarefas = self.data[mask]['Tarefas Completadas']
|
| 307 |
+
acertos = self.data[mask]['Acertos Absolutos']
|
| 308 |
+
|
| 309 |
+
# Criar scatter plot
|
| 310 |
+
plt.scatter(tarefas, acertos, c=color, label=nivel, alpha=0.7, s=150)
|
| 311 |
+
|
| 312 |
+
# Adicionar textos à lista
|
| 313 |
+
for x, y, nome in zip(tarefas, acertos, self.data[mask]['Nome do Aluno']):
|
| 314 |
+
texts.append(plt.text(x, y, nome, fontsize=8,
|
| 315 |
+
bbox=dict(facecolor='white', edgecolor='none', alpha=0.8, pad=0.5)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
# Linha de tendência
|
| 318 |
z = np.polyfit(self.data['Tarefas Completadas'],
|
|
|
|
| 324 |
plt.plot(x_range, p(x_range), "--", color='#e74c3c', alpha=0.8,
|
| 325 |
label='Tendência', linewidth=2)
|
| 326 |
|
| 327 |
+
# Ajustar posição dos textos automaticamente
|
| 328 |
+
adjust_text(texts,
|
| 329 |
+
force_points=0.2,
|
| 330 |
+
force_text=0.2,
|
| 331 |
+
expand_points=(1.2, 1.2),
|
| 332 |
+
expand_text=(1.2, 1.2),
|
| 333 |
+
arrowprops=dict(arrowstyle='-', color='gray', alpha=0.3, lw=0.5))
|
| 334 |
+
|
| 335 |
plt.title('Relação entre Tarefas Completadas e Acertos', pad=20)
|
| 336 |
plt.xlabel('Número de Tarefas Completadas')
|
| 337 |
plt.ylabel('Número de Acertos')
|