v0.23.0 - ZC freq in events store #31
@@ -270,6 +270,19 @@ def apply_report_to_event(event: Event, report: BwAsciiReport) -> None:
|
|||||||
if report.mic.pspl_dbl is not None and report.mic.pspl_dbl > 0:
|
if report.mic.pspl_dbl is not None and report.mic.pspl_dbl > 0:
|
||||||
pv.micl = _dbl_to_psi(report.mic.pspl_dbl)
|
pv.micl = _dbl_to_psi(report.mic.pspl_dbl)
|
||||||
|
|
||||||
|
if (t := ch.get("Tran")):
|
||||||
|
pv.tran_zc_freq = t.zc_freq_hz
|
||||||
|
pv.tran_zc_above_range = bool(getattr(t, "zc_freq_above_range", False))
|
||||||
|
if (v := ch.get("Vert")):
|
||||||
|
pv.vert_zc_freq = v.zc_freq_hz
|
||||||
|
pv.vert_zc_above_range = bool(getattr(v, "zc_freq_above_range", False))
|
||||||
|
if (l := ch.get("Long")):
|
||||||
|
pv.long_zc_freq = l.zc_freq_hz
|
||||||
|
pv.long_zc_above_range = bool(getattr(l, "zc_freq_above_range", False))
|
||||||
|
if report.mic is not None:
|
||||||
|
pv.mic_zc_freq = report.mic.zc_freq_hz
|
||||||
|
pv.mic_zc_above_range = bool(getattr(report.mic, "zc_freq_above_range", False))
|
||||||
|
|
||||||
if event.project_info is None:
|
if event.project_info is None:
|
||||||
event.project_info = ProjectInfo()
|
event.project_info = ProjectInfo()
|
||||||
pi = event.project_info
|
pi = event.project_info
|
||||||
@@ -329,6 +342,17 @@ def apply_bw_report_dict_to_event(event: Event, bw_report: dict) -> None:
|
|||||||
if pspl is not None and pspl > 0:
|
if pspl is not None and pspl > 0:
|
||||||
pv.micl = _dbl_to_psi(pspl)
|
pv.micl = _dbl_to_psi(pspl)
|
||||||
|
|
||||||
|
for axis, freq_attr, above_attr in (
|
||||||
|
("tran", "tran_zc_freq", "tran_zc_above_range"),
|
||||||
|
("vert", "vert_zc_freq", "vert_zc_above_range"),
|
||||||
|
("long", "long_zc_freq", "long_zc_above_range"),
|
||||||
|
):
|
||||||
|
chd = peaks.get(axis) or {}
|
||||||
|
setattr(pv, freq_attr, chd.get("zc_freq_hz"))
|
||||||
|
setattr(pv, above_attr, bool(chd.get("zc_freq_above_range", False)))
|
||||||
|
pv.mic_zc_freq = mic.get("zc_freq_hz")
|
||||||
|
pv.mic_zc_above_range = bool(mic.get("zc_freq_above_range", False))
|
||||||
|
|
||||||
rec = bw_report.get("recording") or {}
|
rec = bw_report.get("recording") or {}
|
||||||
sr = rec.get("sample_rate_sps")
|
sr = rec.get("sample_rate_sps")
|
||||||
if sr:
|
if sr:
|
||||||
|
|||||||
@@ -352,6 +352,14 @@ class PeakValues:
|
|||||||
long: Optional[float] = None # Longitudinal PPV (in/s) ✅
|
long: Optional[float] = None # Longitudinal PPV (in/s) ✅
|
||||||
micl: Optional[float] = None # Air overpressure (psi) 🔶 (units uncertain)
|
micl: Optional[float] = None # Air overpressure (psi) 🔶 (units uncertain)
|
||||||
peak_vector_sum: Optional[float] = None # Scalar geo PVS (in/s) ✅
|
peak_vector_sum: Optional[float] = None # Scalar geo PVS (in/s) ✅
|
||||||
|
tran_zc_freq: Optional[float] = None
|
||||||
|
vert_zc_freq: Optional[float] = None
|
||||||
|
long_zc_freq: Optional[float] = None
|
||||||
|
mic_zc_freq: Optional[float] = None
|
||||||
|
tran_zc_above_range: bool = False
|
||||||
|
vert_zc_above_range: bool = False
|
||||||
|
long_zc_above_range: bool = False
|
||||||
|
mic_zc_above_range: bool = False
|
||||||
|
|
||||||
|
|
||||||
# ── Project / operator metadata ───────────────────────────────────────────────
|
# ── Project / operator metadata ───────────────────────────────────────────────
|
||||||
|
|||||||
@@ -43,3 +43,45 @@ def test_migration_adds_zc_freq_columns_to_legacy_db(tmp_path: Path):
|
|||||||
for c in ZC_COLS:
|
for c in ZC_COLS:
|
||||||
assert c in rows[0] # present
|
assert c in rows[0] # present
|
||||||
assert rows[0][c] is None # NULL for the legacy row
|
assert rows[0][c] is None # NULL for the legacy row
|
||||||
|
|
||||||
|
|
||||||
|
from minimateplus.models import PeakValues, Event
|
||||||
|
from minimateplus import event_file_io
|
||||||
|
from minimateplus.bw_ascii_report import BwAsciiReport, ChannelStats, MicStats
|
||||||
|
|
||||||
|
|
||||||
|
def _report_with_freqs():
|
||||||
|
r = BwAsciiReport()
|
||||||
|
r.channels["Tran"] = ChannelStats(ppv_ips=0.075, zc_freq_hz=100.0, zc_freq_above_range=True)
|
||||||
|
r.channels["Vert"] = ChannelStats(ppv_ips=0.220, zc_freq_hz=85.0)
|
||||||
|
r.channels["Long"] = ChannelStats(ppv_ips=0.045, zc_freq_hz=73.0)
|
||||||
|
r.mic = MicStats(zc_freq_hz=51.0)
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def test_apply_report_copies_zc_freq_onto_peakvalues():
|
||||||
|
ev = Event(index=0)
|
||||||
|
event_file_io.apply_report_to_event(ev, _report_with_freqs())
|
||||||
|
pv = ev.peak_values
|
||||||
|
assert pv.vert_zc_freq == 85.0
|
||||||
|
assert pv.tran_zc_freq == 100.0
|
||||||
|
assert pv.tran_zc_above_range is True
|
||||||
|
assert pv.vert_zc_above_range is False
|
||||||
|
assert pv.mic_zc_freq == 51.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_apply_bw_report_dict_copies_zc_freq():
|
||||||
|
ev = Event(index=0)
|
||||||
|
bw = {
|
||||||
|
"peaks": {
|
||||||
|
"tran": {"ppv_ips": 0.075, "zc_freq_hz": 100.0, "zc_freq_above_range": True},
|
||||||
|
"vert": {"ppv_ips": 0.220, "zc_freq_hz": 85.0},
|
||||||
|
"long": {"ppv_ips": 0.045, "zc_freq_hz": 73.0},
|
||||||
|
},
|
||||||
|
"mic": {"zc_freq_hz": 51.0, "zc_freq_above_range": False},
|
||||||
|
}
|
||||||
|
event_file_io.apply_bw_report_dict_to_event(ev, bw)
|
||||||
|
pv = ev.peak_values
|
||||||
|
assert pv.vert_zc_freq == 85.0
|
||||||
|
assert pv.tran_zc_above_range is True
|
||||||
|
assert pv.mic_zc_freq == 51.0
|
||||||
|
|||||||
Reference in New Issue
Block a user