Spaces:
Running on Zero
Running on Zero
Olivier commited on
Upload game_engine.py
Browse files- game_engine.py +15 -5
game_engine.py
CHANGED
|
@@ -200,7 +200,7 @@ class MathGame:
|
|
| 200 |
def start_game(self, duration: str, operation: str, difficulty: str) -> tuple[str, Image.Image, str, str, gr.update, gr.update, str]:
|
| 201 |
"""Démarre le jeu avec la configuration choisie"""
|
| 202 |
|
| 203 |
-
log_memory_usage("avant nettoyage start_game")
|
| 204 |
|
| 205 |
# Configuration
|
| 206 |
self.duration = 60 if duration == "60 secondes" else 30
|
|
@@ -238,7 +238,7 @@ class MathGame:
|
|
| 238 |
self.export_result = None
|
| 239 |
|
| 240 |
gc.collect()
|
| 241 |
-
log_memory_usage("après nettoyage start_game")
|
| 242 |
|
| 243 |
# Première opération
|
| 244 |
operation_str, answer = self.generate_operation(self.operation_type, self.difficulty)
|
|
@@ -323,7 +323,7 @@ class MathGame:
|
|
| 323 |
|
| 324 |
self.is_running = False
|
| 325 |
|
| 326 |
-
log_memory_usage("début end_game")
|
| 327 |
|
| 328 |
if final_image is not None:
|
| 329 |
self.user_images.append(final_image)
|
|
@@ -345,13 +345,20 @@ class MathGame:
|
|
| 345 |
images_saved = 0
|
| 346 |
total_image_size_kb = 0
|
| 347 |
|
| 348 |
-
# Traitement optimisé
|
| 349 |
print(f"🔄 Traitement de {total_questions} images...")
|
|
|
|
| 350 |
|
| 351 |
for i, (image, expected, operation_data) in enumerate(zip(self.user_images, self.expected_answers, self.operations_history)):
|
|
|
|
|
|
|
|
|
|
| 352 |
row_data = create_result_row_with_images(i, image, expected, operation_data)
|
| 353 |
table_rows_html += row_data['html_row']
|
| 354 |
|
|
|
|
|
|
|
|
|
|
| 355 |
if row_data['is_correct']:
|
| 356 |
correct_answers += 1
|
| 357 |
|
|
@@ -398,6 +405,9 @@ class MathGame:
|
|
| 398 |
|
| 399 |
self.session_data.append(entry)
|
| 400 |
|
|
|
|
|
|
|
|
|
|
| 401 |
accuracy = (correct_answers / total_questions * 100) if total_questions > 0 else 0
|
| 402 |
|
| 403 |
for entry in self.session_data:
|
|
@@ -412,7 +422,7 @@ class MathGame:
|
|
| 412 |
pass
|
| 413 |
|
| 414 |
gc.collect()
|
| 415 |
-
log_memory_usage("après nettoyage end_game")
|
| 416 |
|
| 417 |
# HTML résultats
|
| 418 |
table_html = f"""
|
|
|
|
| 200 |
def start_game(self, duration: str, operation: str, difficulty: str) -> tuple[str, Image.Image, str, str, gr.update, gr.update, str]:
|
| 201 |
"""Démarre le jeu avec la configuration choisie"""
|
| 202 |
|
| 203 |
+
# log_memory_usage("avant nettoyage start_game") # DEBUG: Désactivé
|
| 204 |
|
| 205 |
# Configuration
|
| 206 |
self.duration = 60 if duration == "60 secondes" else 30
|
|
|
|
| 238 |
self.export_result = None
|
| 239 |
|
| 240 |
gc.collect()
|
| 241 |
+
# log_memory_usage("après nettoyage start_game") # DEBUG: Désactivé
|
| 242 |
|
| 243 |
# Première opération
|
| 244 |
operation_str, answer = self.generate_operation(self.operation_type, self.difficulty)
|
|
|
|
| 323 |
|
| 324 |
self.is_running = False
|
| 325 |
|
| 326 |
+
# log_memory_usage("début end_game") # DEBUG: Désactivé
|
| 327 |
|
| 328 |
if final_image is not None:
|
| 329 |
self.user_images.append(final_image)
|
|
|
|
| 345 |
images_saved = 0
|
| 346 |
total_image_size_kb = 0
|
| 347 |
|
| 348 |
+
# Traitement optimisé avec DEBUG
|
| 349 |
print(f"🔄 Traitement de {total_questions} images...")
|
| 350 |
+
start_processing = time.time()
|
| 351 |
|
| 352 |
for i, (image, expected, operation_data) in enumerate(zip(self.user_images, self.expected_answers, self.operations_history)):
|
| 353 |
+
print(f" → Image {i+1}/{total_questions}...")
|
| 354 |
+
img_start = time.time()
|
| 355 |
+
|
| 356 |
row_data = create_result_row_with_images(i, image, expected, operation_data)
|
| 357 |
table_rows_html += row_data['html_row']
|
| 358 |
|
| 359 |
+
img_time = time.time() - img_start
|
| 360 |
+
print(f" ✅ Traitée en {img_time:.1f}s")
|
| 361 |
+
|
| 362 |
if row_data['is_correct']:
|
| 363 |
correct_answers += 1
|
| 364 |
|
|
|
|
| 405 |
|
| 406 |
self.session_data.append(entry)
|
| 407 |
|
| 408 |
+
processing_time = time.time() - start_processing
|
| 409 |
+
print(f"⏱️ Traitement total: {processing_time:.1f}s")
|
| 410 |
+
|
| 411 |
accuracy = (correct_answers / total_questions * 100) if total_questions > 0 else 0
|
| 412 |
|
| 413 |
for entry in self.session_data:
|
|
|
|
| 422 |
pass
|
| 423 |
|
| 424 |
gc.collect()
|
| 425 |
+
# log_memory_usage("après nettoyage end_game") # DEBUG: Désactivé
|
| 426 |
|
| 427 |
# HTML résultats
|
| 428 |
table_html = f"""
|