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

View File

@@ -1628,7 +1628,48 @@ def real_shots():
return jsonify({'error': 'real_shots.json not found'}), 404
with open(shot_path) as f:
return jsonify(json.load(f))
@app.route("/api/coverage")def get_coverage(): """Get coverage data for all H5 files.""" import re as _re try: darf = {} if os.path.exists(DARF_FILE): with open(DARF_FILE) as _f: darf = json.load(_f) result = [] for f in os.listdir(DATA_DIR): if not f.endswith(".h5"): continue fpath = os.path.join(DATA_DIR, f) info = {"name": f, "size": os.path.getsize(fpath)} m = _re.match(r"auto_(d+)_(d{2})(d{2})(d{2})_b(d+)_rsn(d+)_seq(d+)_(d+)", f) if m: day, hh, mm, ss, board_id, rsn, seq, ts = m.groups() info["board_id"] = int(board_id) info["day"] = int(day) from datetime import datetime as _dt, timedelta as _td base = _dt(2020, 1, 1) + _td(days=int(day)-1, hours=int(hh), minutes=int(mm), seconds=int(ss)) info["date_str"] = base.isoformat() bid_str = str(board_id) if bid_str in darf: info["line"] = darf[bid_str].get("line") info["point"] = darf[bid_str].get("point") info["duration_sec"] = 8000 try: import h5py with h5py.File(fpath, "r") as h5f: attrs = dict(h5f.attrs) info["duration_sec"] = float(attrs.get("duration", attrs.get("record_length", 8000))) except: pass result.append(info) result.sort(key=lambda x: x.get("date_str", "")) return jsonify({"files": result, "count": len(result)}) except Exception as e: return jsonify({"error": str(e)}), 500
@app.route('/api/coverage')
def get_coverage():
"""Get coverage data for all H5 files."""
import re as _re
try:
darf = {}
if os.path.exists(DARF_FILE):
with open(DARF_FILE) as _f:
darf = json.load(_f)
result = []
for f in os.listdir(DATA_DIR):
if not f.endswith('.h5'):
continue
fpath = os.path.join(DATA_DIR, f)
info = {'name': f, 'size': os.path.getsize(fpath)}
m = _re.match(r'auto_(\d+)_(\d{2})(\d{2})(\d{2})_b(\d+)_rsn(\d+)_seq(\d+)_(\d+)', f)
if m:
day, hh, mm, ss, board_id, rsn, seq, ts = m.groups()
info['board_id'] = int(board_id)
info['day'] = int(day)
from datetime import datetime as _dt, timedelta as _td
base = _dt(2020, 1, 1) + _td(days=int(day)-1, hours=int(hh), minutes=int(mm), seconds=int(ss))
info['date_str'] = base.isoformat()
bid_str = str(board_id)
if bid_str in darf:
info['line'] = darf[bid_str].get('line')
info['point'] = darf[bid_str].get('point')
info['duration_sec'] = 8000
try:
import h5py
with h5py.File(fpath, 'r') as h5f:
attrs = dict(h5f.attrs)
info['duration_sec'] = float(attrs.get('duration', attrs.get('record_length', 8000)))
except:
pass
result.append(info)
result.sort(key=lambda x: x.get('date_str', ''))
return jsonify({'files': result, 'count': len(result)})
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3001, debug=False)