Fix coverage: add /api/coverage route, remove stray gather code from loadCoverage
This commit is contained in:
114
scripts/rebuild_index.py
Executable file
114
scripts/rebuild_index.py
Executable file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Reconstruit l'index.json de la webapp à partir de l'inventaire complet.
|
||||
Prend en compte tous les fichiers HDF5 sur tous les disques.
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from collections import defaultdict
|
||||
|
||||
def main():
|
||||
# Charger l'inventaire
|
||||
inv_path = Path(r'F:\seismic_webapp\inventory.json')
|
||||
inv = json.load(open(inv_path))
|
||||
print(f"Inventaire charge: {len(inv)} fichiers")
|
||||
|
||||
# Charger l'index existant pour garder les positions
|
||||
idx_path = Path(r'F:\seismic_webapp\data\index.json')
|
||||
old_idx = json.load(open(idx_path))
|
||||
print(f"Index existant: {len(old_idx.get('nodes', {}))} nodes")
|
||||
|
||||
# Construire le nouvel index
|
||||
nodes = {}
|
||||
|
||||
# Copier les positions existantes
|
||||
for node_id, node_data in old_idx.get('nodes', {}).items():
|
||||
nodes[node_id] = {
|
||||
'position': node_data.get('position'),
|
||||
'dates': {},
|
||||
'hasDates': False
|
||||
}
|
||||
|
||||
# Ajouter les fichiers de l'inventaire
|
||||
files_added = 0
|
||||
for f in inv:
|
||||
bumper_id = f['bumper_id']
|
||||
if not bumper_id:
|
||||
continue
|
||||
|
||||
# Créer le node s'il n'existe pas
|
||||
if bumper_id not in nodes:
|
||||
nodes[bumper_id] = {
|
||||
'position': None,
|
||||
'dates': {},
|
||||
'hasDates': False
|
||||
}
|
||||
|
||||
# Calculer la date depuis l'epoch
|
||||
if f['epoch_time']:
|
||||
dt = datetime.fromtimestamp(f['epoch_time'])
|
||||
date_str = dt.strftime('%Y-%m-%d')
|
||||
else:
|
||||
continue
|
||||
|
||||
# Ajouter à la liste des dates
|
||||
if date_str not in nodes[bumper_id]['dates']:
|
||||
nodes[bumper_id]['dates'][date_str] = []
|
||||
|
||||
# Déterminer les canaux (extraire du nom de fichier)
|
||||
channel = f['channel']
|
||||
channels = [channel] if channel else []
|
||||
|
||||
# Ajouter le fichier
|
||||
file_info = {
|
||||
'path': f['filepath'],
|
||||
'timestamp': f['epoch_time'],
|
||||
'channels': channels,
|
||||
'size_bytes': 0 # On n'a pas cette info
|
||||
}
|
||||
|
||||
# Éviter les doublons
|
||||
existing_paths = [fi['path'] for fi in nodes[bumper_id]['dates'][date_str]]
|
||||
if f['filepath'] not in existing_paths:
|
||||
nodes[bumper_id]['dates'][date_str].append(file_info)
|
||||
files_added += 1
|
||||
|
||||
# Marquer les nodes qui ont des dates
|
||||
for node_id, node_data in nodes.items():
|
||||
node_data['hasDates'] = len(node_data['dates']) > 0
|
||||
|
||||
# Statistiques
|
||||
nodes_with_data = sum(1 for n in nodes.values() if n['hasDates'])
|
||||
total_files = sum(
|
||||
len(files)
|
||||
for n in nodes.values()
|
||||
for files in n['dates'].values()
|
||||
)
|
||||
|
||||
print(f"\nNouvel index:")
|
||||
print(f" Nodes total: {len(nodes)}")
|
||||
print(f" Nodes avec donnees: {nodes_with_data}")
|
||||
print(f" Fichiers indexes: {total_files}")
|
||||
|
||||
# Sauvegarder
|
||||
new_idx = {
|
||||
'nodes': nodes,
|
||||
'sampleRateHz': old_idx.get('sampleRateHz', 200),
|
||||
'generated': datetime.now().isoformat()
|
||||
}
|
||||
|
||||
# Backup de l'ancien
|
||||
backup_path = idx_path.with_suffix('.json.bak')
|
||||
with open(backup_path, 'w') as f:
|
||||
json.dump(old_idx, f)
|
||||
print(f"\nBackup sauvegarde: {backup_path}")
|
||||
|
||||
# Sauvegarder le nouveau
|
||||
with open(idx_path, 'w') as f:
|
||||
json.dump(new_idx, f, indent=2)
|
||||
print(f"Nouvel index sauvegarde: {idx_path}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user