Fix coverage: add /api/coverage route, remove stray gather code from loadCoverage
This commit is contained in:
53
scripts/migrate_to_db.py
Normal file
53
scripts/migrate_to_db.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import h5py
|
||||
import numpy as np
|
||||
import psycopg2
|
||||
from psycopg2.extras import execute_values
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
|
||||
DB_URL = "postgresql://postgres:seismic_pass@db:5432/seismic_data"
|
||||
|
||||
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 migrate_file(h5_path, node_id, channel, start_offset_sec=0, duration_sec=3600):
|
||||
h5_path = fix_path(h5_path)
|
||||
conn = psycopg2.connect(DB_URL)
|
||||
cur = conn.cursor()
|
||||
|
||||
with h5py.File(h5_path, 'r') as f:
|
||||
ds = f['adc_values']
|
||||
start_ts = int(ds.attrs['timestamp'])
|
||||
# On calcule le début réel
|
||||
actual_start = start_ts + start_offset_sec
|
||||
start_idx = start_offset_sec * 200
|
||||
end_idx = start_idx + (duration_sec * 200)
|
||||
|
||||
data = ds[start_idx:end_idx]
|
||||
print(f"Migrating {len(data)} samples...")
|
||||
|
||||
# Préparation des tuples pour insertion par lots
|
||||
batch_size = 10000
|
||||
for i in range(0, len(data), batch_size):
|
||||
batch = data[i:i+batch_size]
|
||||
values = []
|
||||
for j, val in enumerate(batch):
|
||||
ts = datetime.fromtimestamp(actual_start + (i + j) / 200, tz=timezone.utc)
|
||||
values.append((ts, node_id, channel, float(val)))
|
||||
|
||||
execute_values(cur, "INSERT INTO adc_samples (time, node_id, channel, value) VALUES %s", values)
|
||||
conn.commit()
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
print("Done.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Test sur Node 193, 1er septembre (Julian 245), 10 minutes
|
||||
# On cherche un fichier du node 193
|
||||
import sys
|
||||
migrate_file(sys.argv[1], sys.argv[2], sys.argv[3], duration_sec=600)
|
||||
Reference in New Issue
Block a user