File size: 2,201 Bytes
7a87926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
from pathlib import Path
import pytest

from ylff.services.audit.audit_runner import load_measurements_json, run_audit
from ylff.services.audit.models import ExternalReferenceMeasurement, OperatingRegime

pytestmark = pytest.mark.spec


def test_load_measurements_json_list(tmp_path: Path):
    p = tmp_path / "m.json"
    p.write_text(
        json.dumps(
            [
                {
                    "regime": "indoor_constrained",
                    "measurement_type": "tag_to_tag",
                    "d_pred": 2.0,
                    "d_star": 2.0,
                    "sigma_d": 0.1,
                }
            ]
        )
    )
    ms = load_measurements_json(p)
    assert len(ms) == 1
    assert ms[0].regime == OperatingRegime.INDOOR_CONSTRAINED


def test_load_measurements_json_wrapped(tmp_path: Path):
    p = tmp_path / "m.json"
    p.write_text(
        json.dumps(
            {
                "measurements": [
                    {
                        "regime": "indoor_constrained",
                        "measurement_type": "tag_to_tag",
                        "d_pred": 2.0,
                        "d_star": 2.0,
                        "sigma_d": 0.1,
                    }
                ]
            }
        )
    )
    ms = load_measurements_json(p)
    assert len(ms) == 1


def test_run_audit_with_calibration_sets_summary_fields():
    # Add slight variation so correlation computations don't produce NaNs.
    ms = []
    for i in range(20):
        ms.append(
            ExternalReferenceMeasurement(
                capture_id=None,
                regime=OperatingRegime.INDOOR_CONSTRAINED,
                measurement_type="tag_to_tag",
                d_pred=2.0 + 0.02 + 0.001 * i,
                d_star=2.0,
                sigma_d=0.05 + 0.001 * i,
            )
        )
    res = run_audit(ms, calibrate=True, calibration_split_fraction=0.5)
    assert "calibrated" in res.summary
    assert res.summary["calibrated"] in (True, False)
    assert "hard_fail_passed" in res.summary
    if res.summary.get("calibrated"):
        assert "calibration_table" in res.summary
        assert "calibration_version" in res.summary