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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| """ DMS 分心类型细分:恢复性走神 vs 危险分心
核心思路: - 恢复性走神:视线短暂偏离(<5s)+ 无手机操作 → 可能有益 - 危险分心:视线长期偏离(>5s)或手机操作 → 有害 """
from dataclasses import dataclass from typing import Optional from enum import Enum
class MindWanderType(Enum): RECOVERING = "recovering" DANGEROUS = "dangerous" NEUTRAL = "neutral"
@dataclass class MindWanderAssessment: wander_type: MindWanderType gaze_off_duration: float phone_in_hand: bool steering_stability: float recommendation: str
class AdaptiveDistractionDetector: """ 自适应分心检测器 区分"恢复性走神"和"危险分心": - 恢复性走神:短暂视线偏离 + 无手机操作 + 转向稳定 → 不警告 - 危险分心:长时间偏离 或 手机操作 → 警告 """ def __init__(self): self.recovery_wander_threshold = 5.0 self.phone_use_threshold = 3.5 self.stability_threshold = 0.7 def assess(self, gaze_off_duration: float, phone_in_hand: bool, steering_stability: float) -> MindWanderAssessment: if phone_in_hand and gaze_off_duration > self.phone_use_threshold: return MindWanderAssessment( wander_type=MindWanderType.DANGEROUS, gaze_off_duration=gaze_off_duration, phone_in_hand=phone_in_hand, steering_stability=steering_stability, recommendation="立即警告(手机操作+视线偏离)" ) if gaze_off_duration < self.recovery_wander_threshold and \ steering_stability > self.stability_threshold and \ not phone_in_hand: return MindWanderAssessment( wander_type=MindWanderType.RECOVERING, gaze_off_duration=gaze_off_duration, phone_in_hand=phone_in_hand, steering_stability=steering_stability, recommendation="不警告(可能是恢复性走神)" ) if gaze_off_duration > self.phone_use_threshold: return MindWanderAssessment( wander_type=MindWanderType.DANGEROUS, gaze_off_duration=gaze_off_duration, phone_in_hand=phone_in_hand, steering_stability=steering_stability, recommendation="一级警告" ) return MindWanderAssessment( wander_type=MindWanderType.NEUTRAL, gaze_off_duration=gaze_off_duration, phone_in_hand=phone_in_hand, steering_stability=steering_stability, recommendation="持续监测" )
if __name__ == "__main__": detector = AdaptiveDistractionDetector() r1 = detector.assess(3.0, False, 0.85) print(f"短暂走神: {r1.wander_type.name} → {r1.recommendation}") r2 = detector.assess(4.0, True, 0.6) print(f"手机操作: {r2.wander_type.name} → {r2.recommendation}") r3 = detector.assess(6.0, False, 0.75) print(f"长偏离: {r3.wander_type.name} → {r3.recommendation}")
|