From 290faf0a80b372fcc1672b6153c28e086d6756b0 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Thu, 15 Jan 2026 16:37:15 +0100 Subject: [PATCH] Prettify the output of the statistics calculation --- .../commands/recalculate_statistics.py | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/wger/trophies/management/commands/recalculate_statistics.py b/wger/trophies/management/commands/recalculate_statistics.py index 4da4af6cc..1e701a45e 100644 --- a/wger/trophies/management/commands/recalculate_statistics.py +++ b/wger/trophies/management/commands/recalculate_statistics.py @@ -26,6 +26,9 @@ from django.core.management.base import ( ) from django.utils import timezone +# Third Party +from tqdm import tqdm + # wger from wger.trophies.services.statistics import UserStatisticsService @@ -128,22 +131,23 @@ class Command(BaseCommand): processed = 0 errors = 0 - for user in users: - try: - UserStatisticsService.update_statistics(user) - processed += 1 + with tqdm(total=total_users, unit='B', unit_scale=True) as pbar: + for user in users: + try: + UserStatisticsService.update_statistics(user) + processed += 1 - if verbosity >= 2: - self.stdout.write(self.style.SUCCESS(f'✓ Processed: {user.username}')) - elif verbosity >= 1 and processed % 100 == 0: - self.stdout.write(f' Processed {processed}/{total_users} users...') + if verbosity >= 2: + self.stdout.write(self.style.SUCCESS(f'✓ Processed: {user.username}')) + elif verbosity >= 1: + pbar.update(1) - except Exception as e: - errors += 1 - if verbosity >= 1: - self.stdout.write( - self.style.ERROR(f'✗ Error processing {user.username}: {str(e)}') - ) + except Exception as e: + errors += 1 + if verbosity >= 1: + self.stdout.write( + self.style.ERROR(f'✗ Error processing {user.username}: {str(e)}') + ) if verbosity >= 1: self.stdout.write(