"""S4: the replay names the field-weighted experiment a result came from. The field model is an experiment, and its numbers are estimates: the result records its model fingerprint, the declared unloaded reference and the mean extrapolated fraction. The replay has to say so — and say "unknown" for a result that predates the diagnostics, never 0. """ from __future__ import annotations from types import SimpleNamespace from orisys_app_shared.analysis.model import FIELD_PROFILE from orisys_app_shared.i18n import set_locale, t from orisys_studio.replay_controller import field_experiment_note def _session(field: dict) -> SimpleNamespace: return SimpleNamespace( reader=SimpleNamespace(provenance=SimpleNamespace(field=field)) ) FIELD = { "profile": FIELD_PROFILE, "strategy": "field-weighted-baseline-1", "model_fingerprint": "abcdef0123456789" * 4, "reference_id": "video-unloaded-36", "baseline_N": 0.25, "frames": 35, "extrapolated_mean": 0.3, "extrapolated_max": 0.4, "coverage_mean": 0.95, "hhd": {"downsample": 2, "grid_shape": [150, 140]}, } def teardown_function(): set_locale("zh_CN") def test_a_field_result_names_its_baseline_and_extrapolation(): set_locale("zh_CN") note, tip = field_experiment_note(_session(dict(FIELD))) assert note == t( "chart.field_experiment", baseline="0.250", frames=35, extrapolated="30.0", ) assert "field-weighted-baseline-1" in tip assert "abcdef0123456789" in tip assert "150x140" in tip or "150 × 140" in tip set_locale("en_US") english, _ = field_experiment_note(_session(dict(FIELD))) assert english and english != note assert "30.0" in english def test_a_field_result_without_diagnostics_says_unknown(): set_locale("zh_CN") note, tip = field_experiment_note(_session({"profile": FIELD_PROFILE})) assert note == t("chart.field_unknown") assert tip == t("chart.field_unknown_tip") def test_a_scalar_or_missing_result_has_no_field_note(): assert field_experiment_note(_session({})) == ("", "") assert field_experiment_note(None) == ("", "") assert field_experiment_note(SimpleNamespace(reader=None)) == ("", "")