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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
| """ 航空级疲劳告警策略
策略特点: 1. 三级告警(预警、警告、紧急) 2. 渐进式提示 3. 冗余告警(视觉+听觉+触觉) """
from enum import Enum from dataclasses import dataclass from typing import Dict, List import numpy as np
class AlertLevel(Enum): """告警等级""" NORMAL = 0 CAUTION = 1 WARNING = 2 EMERGENCY = 3
@dataclass class FatigueMetrics: """疲劳指标""" saccade_velocity: float blink_rate: float blink_duration: float gaze_distribution: float pupil_variability: float saccade_amplitude: float
class AviationFatigueAlert: """ 航空级疲劳告警系统 策略: 1. 多指标加权融合 2. 时间积分(避免瞬时噪声) 3. 渐进式告警 """ WEIGHTS = { 'saccade_velocity': 0.20, 'blink_rate': 0.15, 'blink_duration': 0.25, 'gaze_distribution': 0.20, 'pupil_variability': 0.10, 'saccade_amplitude': 0.10 } THRESHOLDS = { 'caution': 0.3, 'warning': 0.5, 'emergency': 0.7 } def __init__(self, history_window: int = 60): """ 初始化 Args: history_window: 历史积分窗口(秒) """ self.history = [] self.history_window = history_window self.current_level = AlertLevel.NORMAL def assess_fatigue(self, metrics: FatigueMetrics) -> AlertLevel: """ 评估疲劳等级 Args: metrics: 疲劳指标 Returns: level: 告警等级 """ scores = {} if metrics.saccade_velocity < 400: scores['saccade_velocity'] = (400 - metrics.saccade_velocity) / 400 else: scores['saccade_velocity'] = 0 if metrics.blink_rate > 20: scores['blink_rate'] = (metrics.blink_rate - 20) / 20 else: scores['blink_rate'] = 0 if metrics.blink_duration > 0.15: scores['blink_duration'] = (metrics.blink_duration - 0.15) / 0.15 else: scores['blink_duration'] = 0 if metrics.gaze_distribution < 30: scores['gaze_distribution'] = (30 - metrics.gaze_distribution) / 30 else: scores['gaze_distribution'] = 0 if metrics.pupil_variability < 0.3: scores['pupil_variability'] = (0.3 - metrics.pupil_variability) / 0.3 else: scores['pupil_variability'] = 0 if metrics.saccade_amplitude < 15: scores['saccade_amplitude'] = (15 - metrics.saccade_amplitude) / 15 else: scores['saccade_amplitude'] = 0 fatigue_score = sum( self.WEIGHTS[key] * scores[key] for key in self.WEIGHTS ) self.history.append(fatigue_score) if len(self.history) > self.history_window: self.history.pop(0) smooth_score = np.mean(self.history) if smooth_score > self.THRESHOLDS['emergency']: level = AlertLevel.EMERGENCY elif smooth_score > self.THRESHOLDS['warning']: level = AlertLevel.WARNING elif smooth_score > self.THRESHOLDS['caution']: level = AlertLevel.CAUTION else: level = AlertLevel.NORMAL if level != self.current_level: self._trigger_alert(level) self.current_level = level return level def _trigger_alert(self, level: AlertLevel): """触发告警""" if level == AlertLevel.CAUTION: print("[CAUTION] 飞行员疲劳预警,建议监控") elif level == AlertLevel.WARNING: print("[WARNING] 飞行员疲劳警告,建议休息") elif level == AlertLevel.EMERGENCY: print("[EMERGENCY] 飞行员严重疲劳,立即干预!")
if __name__ == "__main__": alert_system = AviationFatigueAlert() normal_metrics = FatigueMetrics( saccade_velocity=450, blink_rate=15, blink_duration=0.12, gaze_distribution=40, pupil_variability=0.4, saccade_amplitude=18 ) level = alert_system.assess_fatigue(normal_metrics) print(f"正常飞行: {level.name}") fatigue_metrics = FatigueMetrics( saccade_velocity=350, blink_rate=25, blink_duration=0.20, gaze_distribution=25, pupil_variability=0.2, saccade_amplitude=12 ) level = alert_system.assess_fatigue(fatigue_metrics) print(f"疲劳飞行: {level.name}")
|