#!/usr/bin/env python3 """Apply current ripple limits to retained L35 wall-rib and L36 washboard logs.""" from __future__ import annotations import argparse from pathlib import Path import re def records(path: Path) -> list[dict[str, float | str]]: result = [] for line in path.read_text(encoding="utf-8", errors="replace").splitlines(): if "[PassageRippleAudit]" not in line: continue values = dict(re.findall(r"(?:^| )([a-z_]+)=([-0-9.]+)", line)) def ratio(key: str) -> str: match = re.search(rf"(?:^| ){key}=([0-9]+)/([0-9]+)", line) return (str(int(match.group(1)) / max(1, int(match.group(2)))) if match else "nan") try: item: dict[str, float | str] = { "local_peak_amplitude_m": float(values.get( "local_peak_amplitude_m", values.get("amplitude_m", "nan"))), "floor_amplitude_m": float(values.get("floor_amplitude_m", "nan")), "wall_coverage": float(ratio("coverage")), "floor_coverage": float(ratio("floor_coverage")), "status": "FAIL" if "status=FAIL" in line else "PASS", } except ValueError: continue result.append(item) return result def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("kind", choices=("wall-ribs", "floor-washboard")) parser.add_argument("log", type=Path) args = parser.parse_args() entries = records(args.log) if args.kind == "wall-ribs": candidates = [entry for entry in entries if float(entry["local_peak_amplitude_m"]) > 0.035 or float(entry["wall_coverage"]) < 0.75] metric = max((float(entry["local_peak_amplitude_m"]) for entry in candidates), default=0.0) detail = f"max_wall_amplitude_m={metric:.4f} threshold_m=0.035" else: candidates = [entry for entry in entries if float(entry["floor_amplitude_m"]) > 0.015 or float(entry["floor_coverage"]) < 0.75] metric = max((float(entry["floor_amplitude_m"]) for entry in candidates), default=0.0) detail = f"max_floor_amplitude_m={metric:.4f} threshold_m=0.015" detected = bool(candidates) print(f"[HistoricalRippleControl] kind={args.kind} log={args.log} " f"records={len(entries)} {detail} detected={str(detected).lower()} " f"status={'PASS' if detected else 'FAIL'}") return 0 if detected else 1 if __name__ == "__main__": raise SystemExit(main())