64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
import json, sys, os, numpy as np, h5py
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
from tqdm import tqdm
|
|
|
|
INDEX_PATH = Path("/mnt/kingston/seismic_webapp/data/index.json")
|
|
OUTPUT_DIR = Path("/mnt/kingston/seismic_webapp/data/rms_cache")
|
|
SAMPLE_RATE = 200
|
|
|
|
def fix_path(p):
|
|
p = p.replace('\\', '/')
|
|
if p.startswith('F:/'): return '/mnt/kingston/' + p[3:]
|
|
if p.startswith('E:/'): return '/mnt/data_sdb1/' + p[3:]
|
|
return p
|
|
|
|
def compute_rms(h5_path):
|
|
h5_path = fix_path(h5_path)
|
|
if not os.path.exists(h5_path): return None
|
|
try:
|
|
with h5py.File(h5_path, 'r') as f:
|
|
ds = f['adc_values']
|
|
start_ts = int(ds.attrs.get('timestamp', 0))
|
|
if start_ts == 0: return None
|
|
# On prend 5000 samples pour un RMS représentatif
|
|
samples = ds[0:5000]
|
|
rms = float(np.sqrt(np.mean(samples.astype(np.float64)**2)))
|
|
return [{'ts': start_ts, 'rms': rms}]
|
|
except: return None
|
|
|
|
def main():
|
|
with open(INDEX_PATH, 'r') as f: index = json.load(f)
|
|
nodes = index.get('nodes', {})
|
|
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Toutes les dates du système
|
|
all_dates = set()
|
|
for n in nodes.values():
|
|
if 'dates' in n: all_dates.update(n['dates'].keys())
|
|
|
|
print(f"Dates à traiter: {sorted(list(all_dates))}")
|
|
|
|
channel = "ch0"
|
|
for date in sorted(list(all_dates)):
|
|
output_file = OUTPUT_DIR / f"rms_{date}_{channel}.json"
|
|
# On force la régénération pour être sûr d'avoir tout
|
|
print(f"Processing {date}...")
|
|
results = {}
|
|
for nid, node in tqdm(nodes.items(), desc=f"Nodes {date}"):
|
|
files = node.get('dates', {}).get(date, [])
|
|
# On cherche les fichiers data prioritaires
|
|
target = next((f for f in files if '_data_' in f['path'] and f'_{channel}_' in f['path']), None)
|
|
if not target and files: target = files[0] # Fallback
|
|
|
|
if target:
|
|
data = compute_rms(target['path'])
|
|
if data: results[nid] = data
|
|
|
|
if results:
|
|
with open(output_file, 'w') as f:
|
|
json.dump({'date':date, 'channel':channel, 'nodes':results}, f)
|
|
print(f"Sauvegardé {output_file.name}: {len(results)} nodes")
|
|
|
|
if __name__ == '__main__': main()
|