import os import sys import numpy as np PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if PROJECT_ROOT not in sys.path: sys.path.insert(0, PROJECT_ROOT) from ui.pipeline import _clip_features from models.collect_features import FEATURE_NAMES def test_clip_features_clamps_ranges(): idx = {name: i for i, name in enumerate(FEATURE_NAMES)} vec = np.zeros(len(FEATURE_NAMES), dtype=np.float32) # set params vec[idx["yaw"]] = 90.0 vec[idx["pitch"]] = -90.0 vec[idx["roll"]] = 90.0 vec[idx["head_deviation"]] = 999.0 for name in ("ear_left", "ear_right", "ear_avg"): vec[idx[name]] = 2.0 vec[idx["mar"]] = 5.0 vec[idx["gaze_offset"]] = 1.0 vec[idx["perclos"]] = 2.0 vec[idx["blink_rate"]] = 100.0 vec[idx["closure_duration"]] = 50.0 vec[idx["yawn_duration"]] = 50.0 out = _clip_features(vec) assert -45.0 <= out[idx["yaw"]] <= 45.0 assert -30.0 <= out[idx["pitch"]] <= 30.0 assert -30.0 <= out[idx["roll"]] <= 30.0 for name in ("ear_left", "ear_right", "ear_avg"): assert 0.0 <= out[idx[name]] <= 0.85 assert 0.0 <= out[idx["mar"]] <= 1.0 assert 0.0 <= out[idx["gaze_offset"]] <= 0.5 assert 0.0 <= out[idx["perclos"]] <= 0.8 assert 0.0 <= out[idx["blink_rate"]] <= 30.0 assert 0.0 <= out[idx["closure_duration"]] <= 10.0 assert 0.0 <= out[idx["yawn_duration"]] <= 10.0