Implemented better testing and fixed skipepd frames

This commit is contained in:
Martino Ferrari
2026-07-01 16:39:34 +02:00
parent 7a326c5d78
commit 0bea41f866
46 changed files with 4358 additions and 1739 deletions
+39 -1
View File
@@ -21,6 +21,14 @@ Oracle (per signal)
phase offset automatically). nRMSE tolerance is relaxed by the quant step.
* **Fed reference** (when ``--tap`` given): each received value must be within
``tol`` of some tap value too.
* **Continuity** (always, ≥10 points): a stream that stalls (client falling
behind, hub failing to flush a window, ...) can still pass fidelity —
whatever few samples *did* arrive still match the ground truth — while the
plot shows gaping holes. Flags any inter-sample gaps that are >10x the
median spacing and fails when their *summed* duration exceeds 5% of the
capture span. Calibrated against the full scenario matrix: healthy streams
(bursty per-tick live pushes, decimation, fragmentation, multicast, ...) top
out at 0.7% outlier-gap time; a stalled stream showed 55-91%.
"""
import argparse
import json
@@ -122,6 +130,29 @@ def nearest_err(recv_v, truth_v):
return float(np.max(d)) if d.size else 0.0
def gap_check(t_recv, outlier_mult=10.0, max_outlier_frac=0.05):
"""Detect large discontiguous holes in a received time series.
A handful of gaps a few times the median spacing are normal (bursty
per-tick live pushes, decimation, LTTB). Returns (ok, gap_frac, n_gaps,
max_gap): ``gap_frac`` is the fraction of the total capture span consumed
by gaps larger than ``outlier_mult`` times the median inter-sample gap;
when that adds up to more than ``max_outlier_frac`` of the whole capture,
the stream stalled/dropped a chunk rather than merely being decimated.
"""
if t_recv.size < 10:
return True, 0.0, 0, 0.0
t = np.sort(t_recv.astype(np.float64))
dt = np.diff(t)
span = float(t[-1] - t[0])
med = float(np.median(dt))
if span <= 0.0 or med <= 0.0:
return True, 0.0, 0, 0.0
outliers = dt[dt > outlier_mult * med]
gap_frac = float(outliers.sum() / span)
return gap_frac <= max_outlier_frac, gap_frac, int(outliers.size), float(dt.max())
def sine_shape(t, v, freq):
"""Return (corr, nrmse, amp_fit) for a sinusoid fit at ``freq``."""
w = 2.0 * np.pi * freq
@@ -153,6 +184,13 @@ def compare_signal(gt, t_recv, v_recv, tap_v=None):
fidelity_ok = max_err <= tol
m["fidelity_ok"] = bool(fidelity_ok)
gap_ok, gap_frac, n_gaps, max_gap = gap_check(t_recv)
m.update(gap_ok=bool(gap_ok), gap_frac=round(gap_frac, 4),
n_gaps=n_gaps, max_gap=max_gap)
if not gap_ok:
m["reason"] = (f"data hole: {gap_frac:.1%} of capture span in "
f"{n_gaps} gaps >10x median spacing (max={max_gap:.4g}s)")
shape_ok = True
if gt["formula"] == "sine" and v_recv.size >= 8 and gt["freq"]:
corr, nrmse, amp = sine_shape(t_recv, v_recv, gt["freq"])
@@ -180,7 +218,7 @@ def compare_signal(gt, t_recv, v_recv, tap_v=None):
fed_ok = fed_err <= tol
m.update(fed_err=fed_err, fed_ok=bool(fed_ok))
m["pass"] = bool(fidelity_ok and shape_ok and fed_ok)
m["pass"] = bool(fidelity_ok and shape_ok and fed_ok and gap_ok)
return m