Add progress bar to player processing and clean up code

This commit is contained in:
zhangyuheng
2026-02-10 15:44:38 +08:00
parent 99bf3f05c6
commit d8bb134d33

View File

@@ -5,6 +5,7 @@ import re
import time import time
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from datetime import datetime from datetime import datetime
from tqdm import tqdm # Add tqdm for progress bars
BASE_URL = "http://x2.sjcmc.cn:15960/stats/" BASE_URL = "http://x2.sjcmc.cn:15960/stats/"
STATS_DIR = "stats" STATS_DIR = "stats"
@@ -49,9 +50,6 @@ def get_player_name(uuid):
def process_player(filename): def process_player(filename):
uuid = filename.replace(".json", "") uuid = filename.replace(".json", "")
json_path = os.path.join(STATS_DIR, filename) json_path = os.path.join(STATS_DIR, filename)
# img_path = os.path.join(IMAGE_DIR, f"{uuid}.png") # No longer used
print(f"Processing {uuid}...")
# 1. Download/Load JSON # 1. Download/Load JSON
data = None data = None
@@ -155,14 +153,12 @@ def process_player(filename):
} }
} }
# Process in parallel # Process in parallel with progress bar
# Reduce max_workers to avoid hitting API limits too hard locally
results = [] results = []
if files:
with ThreadPoolExecutor(max_workers=4) as executor: with ThreadPoolExecutor(max_workers=4) as executor:
# Process only first 50 for testing? No, user wants all. # Use tqdm to show progress
# But for a script I am writing for them, I should let them run it. results = list(tqdm(executor.map(process_player, files), total=len(files), desc="Processing players"))
# I will process ALL found files.
results = list(executor.map(process_player, files))
results = [r for r in results if r is not None] results = [r for r in results if r is not None]