Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from pygui.backend.frame import Frame
|
||||
from pygui.backend.threshold_classifier import ThresholdConfig, BAND_HIGH, BAND_IN, BAND_LOW
|
||||
from pygui.backend.session_model import SessionModel, SessionUpdate
|
||||
|
||||
|
||||
|
||||
def test_manual_banding_and_stats():
|
||||
model = SessionModel(ThresholdConfig(set_point=149.0, margin=1.0, auto=False))
|
||||
update = model.process(Frame(seq=7, time=1.0, values=[151.0, 149.0, 147.0]))
|
||||
assert update.seq == 7
|
||||
assert update.bands == [BAND_HIGH, BAND_IN, BAND_LOW]
|
||||
assert update.stats.avg == 149.0
|
||||
assert (update.target, update.margin) == (149.0, 1.0)
|
||||
assert update.state in ("idle", "ramp", "set")
|
||||
|
||||
def test_auto_banding_uses_mean_and_sigma():
|
||||
model = SessionModel(ThresholdConfig(auto=True))
|
||||
# Tight cluster around 149 -> small σ -> the 200.0 outlier reads HIGH
|
||||
update = model.process(Frame(seq=0, time=0.0, values=[149.0, 149.0, 149.0, 200.0]))
|
||||
assert update.bands[3] == BAND_HIGH
|
||||
assert update.target == update.stats.avg
|
||||
|
||||
def test_set_thresholds_reband_on_next_frame():
|
||||
m = SessionModel(ThresholdConfig(set_point=149.0, margin=1.0, auto=False))
|
||||
m.set_thresholds(ThresholdConfig(set_point=149.0, margin=5.0, auto=False))
|
||||
upd = m.process(Frame(seq=0, time=0.0, values=[151.0]))
|
||||
assert upd.bands == [BAND_IN]
|
||||
|
||||
Reference in New Issue
Block a user