import json from collections import defaultdict d = json.load(open(r'F:\seismic_webapp\inventory.json')) by_channel = defaultdict(lambda: {'data': 0, 'aux': 0, 'bumpers': set()}) for f in d: ch = f['channel'] or 'unknown' if f['file_type'] == 'data': by_channel[ch]['data'] += 1 else: by_channel[ch]['aux'] += 1 if f['bumper_id']: by_channel[ch]['bumpers'].add(f['bumper_id']) print('=== RESUME PAR CANAL ===') print('Canal DATA AUX Bumpers') print('-' * 35) for ch in ['ch0', 'ch1', 'ch2', 'ch3', 'ch5', 'ch6', 'ch7', 'ch15', 'unknown']: if ch in by_channel: s = by_channel[ch] total = s['data'] + s['aux'] print(f'{ch:8} {s["data"]:4} {s["aux"]:4} {len(s["bumpers"]):3}') # Stats globales total_data = sum(s['data'] for s in by_channel.values()) total_aux = sum(s['aux'] for s in by_channel.values()) all_bumpers = set() for s in by_channel.values(): all_bumpers.update(s['bumpers']) print('-' * 35) print(f'TOTAL {total_data:4} {total_aux:4} {len(all_bumpers):3}') errors = [f for f in d if f['error']] print(f'\nErreurs de lecture: {len(errors)} fichiers') if errors: for e in errors[:5]: print(f' - {e["filename"][:50]}...')