Fix coverage: add /api/coverage route, remove stray gather code from loadCoverage

This commit is contained in:
Floppyrj45
2026-02-19 14:53:10 +01:00
parent 61b25ab734
commit bbd6a22b57
80 changed files with 27884 additions and 1 deletions

108
index_ultimate_v2.py Normal file
View File

@@ -0,0 +1,108 @@
import os, re, json, h5py
from pathlib import Path
from datetime import datetime, timedelta
from tqdm import tqdm
DATA_ROOTS = [Path("/mnt/kingston"), Path("/mnt/data_sdb1")]
POSITIONS_CSV = Path("/mnt/kingston/Copie de SETE_AUV_DARFV4-Copier(1).csv")
OUTPUT_INDEX = Path("/mnt/kingston/seismic_webapp/data/index.json")
SAMPLE_RATE = 200
def load_pos():
positions = {}
if not POSITIONS_CSV.exists(): return {}
with open(POSITIONS_CSV, 'r', encoding='utf-8', errors='replace') as f:
lines = f.readlines()
if len(lines) < 5: return {}
headers = lines[3].strip().split(',')
try:
ni = headers.index('NodeCode')
ei = headers.index('Aslaid Easting') if 'Aslaid Easting' in headers else headers.index('Preplot Easting')
oi = headers.index('Aslaid Northing') if 'Aslaid Northing' in headers else headers.index('Preplot Northing')
except: return {}
for line in lines[4:]:
parts = line.strip().split(',')
try:
nid = parts[ni].strip()
positions[nid] = {
'easting': float(parts[ei]),
'northing': float(parts[oi]),
'depth': float(parts[headers.index('Aslaid Depth')]) if 'Aslaid Depth' in headers else 0.0
}
except: continue
return positions
def scan():
pos = load_pos()
nodes = {}
all_dates = set()
file_count = 0
print("🔍 Scanning all H5 files (Trusting filenames/folders for dates)...")
all_h5_files = []
for root in DATA_ROOTS:
all_h5_files.extend(list(root.rglob("*.h5")))
for h5_path in tqdm(all_h5_files):
try:
# Pattern: auto_{julian}_{time}_b{node}_..._{ts}.h5
match = re.search(r'auto_(\d+)_(\d{6})_b(\d+)_.*?_(\d{10})\.h5$', h5_path.name)
if not match: continue
julian_day = int(match.group(1))
time_str = match.group(2)
node_id = match.group(3)
internal_ts = int(match.group(4))
# Calculer la date réelle à partir du Julian Day (2020)
# Julian 1 = Jan 1. Julian 255 = Sept 11.
date_ref = datetime(2020, 1, 1) + timedelta(days=julian_day - 1)
date_str = date_ref.strftime('%Y-%m-%d')
# Heure du fichier
hours = int(time_str[:2])
minutes = int(time_str[2:4])
seconds = int(time_str[4:6])
# Timestamp calculé (plus fiable pour le matching que l'interne buggé)
actual_start_ts = int(datetime(2020, 1, 1).timestamp() + (julian_day - 1) * 86400 + hours * 3600 + minutes * 60 + seconds)
with h5py.File(h5_path, 'r') as f:
if 'adc_values' not in f: continue
duration = f['adc_values'].shape[0] / SAMPLE_RATE
actual_end_ts = actual_start_ts + duration
all_dates.add(date_str)
if node_id not in nodes:
nodes[node_id] = {
'id': node_id,
'position': pos.get(node_id),
'files': []
}
nodes[node_id]['files'].append({
'path': str(h5_path),
'start': actual_start_ts,
'end': actual_end_ts,
'julian': julian_day,
'channels': ['ch0', 'ch1', 'ch2', 'ch3']
})
file_count += 1
except: continue
# Sauvegarder l'index complet
result = {
'generated_at': datetime.now().isoformat(),
'sample_rate_hz': SAMPLE_RATE,
'nodes': nodes,
'dates': sorted(list(all_dates))
}
with open(OUTPUT_INDEX, 'w') as f:
json.dump(result, f, indent=2)
print(f"✅ Indexing complete: {file_count} files, {len(nodes)} nodes, {len(all_dates)} dates.")
print(f"📅 Dates covered: {sorted(list(all_dates))}")
if __name__ == '__main__': scan()