fixed commetn from songxiao
This commit is contained in:
@@ -12,8 +12,10 @@ from orisys_studio.display_prefs import DisplayPrefsController
|
||||
|
||||
PLOT_DEFAULTS = {
|
||||
"window_sec": 10.0,
|
||||
"fn_min": 0.0,
|
||||
"fn_max": 5.0,
|
||||
"shear_max": 5.0,
|
||||
"fn_raw_min": 0.0,
|
||||
"fn_raw_max": 1e5,
|
||||
"shear_raw_max": 1e5,
|
||||
}
|
||||
@@ -46,7 +48,10 @@ class _Charts:
|
||||
self.fixed_newton: list[bool] = []
|
||||
self.units: list[str] = []
|
||||
self.window_sec: list[float] = []
|
||||
self.limits: list[tuple] = []
|
||||
self.limits: list[dict] = []
|
||||
self.deadband_floors: list[dict] = []
|
||||
self.presentation_enabled: list[bool] = []
|
||||
self.presentation: list[dict] = []
|
||||
|
||||
def unit(self) -> str:
|
||||
return self._unit
|
||||
@@ -61,8 +66,17 @@ class _Charts:
|
||||
def set_window_sec(self, value: float) -> None: # noqa: N802
|
||||
self.window_sec.append(float(value))
|
||||
|
||||
def set_axis_limits(self, *values) -> None: # noqa: N802
|
||||
self.limits.append(tuple(float(v) for v in values))
|
||||
def set_axis_limits(self, **values) -> None: # noqa: N802
|
||||
self.limits.append({key: float(value) for key, value in values.items()})
|
||||
|
||||
def set_deadband_floors(self, *, newton: float, raw: float) -> None: # noqa: N802
|
||||
self.deadband_floors.append({"newton": float(newton), "raw": float(raw)})
|
||||
|
||||
def configure_presentation(self, **values) -> None: # noqa: N802
|
||||
self.presentation.append(dict(values))
|
||||
|
||||
def set_presentation_enabled(self, enabled: bool) -> None: # noqa: N802
|
||||
self.presentation_enabled.append(bool(enabled))
|
||||
|
||||
|
||||
class _ArrowPanel:
|
||||
@@ -197,27 +211,88 @@ def test_the_plot_dialog_values_come_from_the_preferences_with_defaults():
|
||||
settings = controller.plot_settings()
|
||||
assert settings["window_sec"] == 3.0
|
||||
assert settings["fn_max"] == PLOT_DEFAULTS["fn_max"], "a missing range used no default"
|
||||
assert settings["fn_min"] == 0.0, "FN has no lower bound by default"
|
||||
assert settings["deadband_n"] == 0.0, "the deadband default is 'auto'"
|
||||
assert settings["units"] == "newton"
|
||||
|
||||
|
||||
def test_a_stored_zero_is_a_value_and_not_a_missing_preference():
|
||||
"""0 means "auto" on the raw bounds and the deadband, so it must survive."""
|
||||
controller, parts = _controller(prefs={"plot_fn_raw_max": 0.0})
|
||||
|
||||
settings = controller.plot_settings()
|
||||
assert settings["fn_raw_max"] == 0.0, "a stored 0 became the default"
|
||||
|
||||
|
||||
def test_applying_plot_settings_writes_the_preferences_and_the_panel():
|
||||
controller, parts = _controller(prefs={})
|
||||
controller.apply_plot_settings(
|
||||
{
|
||||
"window_sec": 20.0,
|
||||
"fn_min": -2.0,
|
||||
"fn_max": 8.0,
|
||||
"shear_max": 9.0,
|
||||
"fn_raw_min": -1000.0,
|
||||
"fn_raw_max": 2e5,
|
||||
"shear_raw_max": 3e5,
|
||||
"deadband_n": 0.25,
|
||||
"deadband_raw": 0.0,
|
||||
}
|
||||
)
|
||||
assert parts["host"].prefs["plot_window_sec"] == 20.0
|
||||
assert parts["host"].prefs["plot_fn_min"] == -2.0
|
||||
assert parts["host"].prefs["plot_shear_raw_max"] == 3e5
|
||||
assert parts["host"].prefs["plot_deadband_n"] == 0.25
|
||||
assert parts["charts"].window_sec == [20.0]
|
||||
assert parts["charts"].limits == [(8.0, 9.0, 2e5, 3e5)]
|
||||
assert parts["charts"].limits[-1] == {
|
||||
"fn_min": -2.0,
|
||||
"fn_max": 8.0,
|
||||
"shear_max": 9.0,
|
||||
"fn_raw_min": -1000.0,
|
||||
"fn_raw_max": 2e5,
|
||||
"shear_raw_max": 3e5,
|
||||
}
|
||||
# 0 on a deadband floor means "auto", and the charts are told exactly that.
|
||||
assert parts["charts"].deadband_floors[-1] == {"newton": 0.25, "raw": 0.0}
|
||||
assert parts["host"].persisted == 1
|
||||
|
||||
|
||||
def test_a_partial_plot_settings_mapping_leaves_the_rest_as_stored():
|
||||
"""The older five-value shape must not silently reset a range."""
|
||||
controller, parts = _controller(prefs={"plot_fn_min": -5.0, "plot_deadband_raw": 900.0})
|
||||
controller.apply_plot_settings(
|
||||
{"window_sec": 6.0, "fn_max": 12.0, "shear_max": 3.0,
|
||||
"fn_raw_max": 4e5, "shear_raw_max": 5e5}
|
||||
)
|
||||
assert parts["host"].prefs["plot_fn_min"] == -5.0
|
||||
assert parts["charts"].limits[-1]["fn_min"] == -5.0
|
||||
assert parts["charts"].deadband_floors[-1]["raw"] == 900.0
|
||||
|
||||
|
||||
def test_the_display_baseline_is_not_a_finger_only_setting():
|
||||
"""Every sensor type and both units: an idle newton offset is the same problem."""
|
||||
for sensor, units in (("box", "newton"), ("box", "raw"),
|
||||
("finger", "newton"), ("finger", "raw")):
|
||||
controller, parts = _controller(prefs={"raw_auto_zero": True},
|
||||
sensor_type=sensor, units=units)
|
||||
assert parts["charts"].presentation_enabled[-1] is True, (sensor, units)
|
||||
assert parts["charts"].presentation[-1]["unit"] == (
|
||||
"N" if units == "newton" else "raw"
|
||||
)
|
||||
|
||||
controller, parts = _controller(prefs={"raw_auto_zero": False}, sensor_type="box",
|
||||
units="newton")
|
||||
assert parts["charts"].presentation_enabled[-1] is False
|
||||
|
||||
|
||||
def test_the_deadband_floors_reach_the_charts_from_the_preferences():
|
||||
controller, parts = _controller(prefs={"plot_deadband_n": 0.5, "plot_deadband_raw": 2000.0})
|
||||
assert parts["charts"].deadband_floors[-1] == {"newton": 0.5, "raw": 2000.0}
|
||||
|
||||
controller.set_raw_auto_zero(True) # re-applies the whole policy
|
||||
assert parts["charts"].deadband_floors[-1] == {"newton": 0.5, "raw": 2000.0}
|
||||
|
||||
|
||||
def test_the_sample_rate_prefers_the_measured_rate_over_the_stored_one():
|
||||
controller, parts = _controller(prefs={"measured_fps": 12.0}, latest_fps=48.5)
|
||||
assert controller.device_sample_rate() == 48.5
|
||||
|
||||
Reference in New Issue
Block a user