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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
| """ Euro NCAP 2026 分心检测评分 10分评分标准实现
评分逻辑: - D-01 长分心(3-4秒):3分 - D-02 手机使用(耳旁):2分 - D-03 手机使用(打字):2分 - D-04 短分心(10秒累积):1分 - D-05 短分心(30秒累积):1分 - D-06 VATS:1分
满分条件: - 所有6个场景均通过 - 总分 = 3+2+2+1+1+1 = 10分 """
from typing import Dict, Tuple from dataclasses import dataclass
@dataclass class DistractionTestResult: """分心检测测试结果""" scenario_id: str scenario_name: str max_score: int achieved_score: int passed: bool detection_latency_sec: float warning_latency_sec: float criteria_met: str
class DistractionScoringEngine: """ 分心检测评分引擎 Euro NCAP 2026分心检测评分标准: D-01 长分心(3-4秒): - 检测条件:注视偏离道路3-4秒 - 通过标准:≤3秒触发一级警告 - 分值:3分 D-02 手机使用(耳旁): - 检测条件:手持手机至耳边 - 通过标准:≤3秒触发一级警告 - 分值:2分 D-03 手机使用(打字): - 检测条件:低头打字操作 - 通过标准:≤3秒触发一级警告 - 分值:2分 D-04 短分心(10秒累积): - 检测条件:多次短分心累积10秒 - 通过标准:累积判定触发警告 - 分值:1分 D-05 短分心(30秒累积): - 检测条件:多次短分心累积30秒 - 通过标准:累积判定触发二级警告 - 分值:1分 D-06 VATS视觉注意力时间: - 检测条件:注视道路时间占比 - 通过标准:VATS≥70% - 分值:1分 """ def __init__(self): self.long_distraction_sec = 3.0 self.short_distraction_10_sec = 10.0 self.short_distraction_30_sec = 30.0 self.vats_threshold = 0.70 self.warning_latency_threshold_sec = 3.0 def score_d01_long_distraction(self, detection_latency_sec: float, warning_latency_sec: float) -> DistractionTestResult: """ D-01 长分心(3-4秒)评分 通过条件: - 检测到注视偏离道路3-4秒 - ≤3秒触发一级警告 - 警告内容:视觉+听觉 Args: detection_latency_sec: 检测时延 warning_latency_sec: 警告时延 Returns: DistractionTestResult: 测试结果 """ passed = warning_latency_sec <= self.warning_latency_threshold_sec achieved_score = 3 if passed else 0 return DistractionTestResult( scenario_id='D-01', scenario_name='长分心(3-4秒)', max_score=3, achieved_score=achieved_score, passed=passed, detection_latency_sec=detection_latency_sec, warning_latency_sec=warning_latency_sec, criteria_met=f"警告时延{warning_latency_sec:.1f}s {'≤' if passed else '>'}3s" ) def score_d02_phone_ear(self, detection_latency_sec: float, warning_latency_sec: float) -> DistractionTestResult: """ D-02 手机使用(耳旁)评分 通过条件:≤3秒触发一级警告 分值:2分 """ passed = warning_latency_sec <= self.warning_latency_threshold_sec achieved_score = 2 if passed else 0 return DistractionTestResult( scenario_id='D-02', scenario_name='手机使用(耳旁)', max_score=2, achieved_score=achieved_score, passed=passed, detection_latency_sec=detection_latency_sec, warning_latency_sec=warning_latency_sec, criteria_met=f"警告时延{warning_latency_sec:.1f}s {'≤' if passed else '>'}3s" ) def score_d03_phone_texting(self, detection_latency_sec: float, warning_latency_sec: float) -> DistractionTestResult: """ D-03 手机使用(打字)评分 通过条件:≤3秒触发一级警告 分值:2分 """ passed = warning_latency_sec <= self.warning_latency_threshold_sec achieved_score = 2 if passed else 0 return DistractionTestResult( scenario_id='D-03', scenario_name='手机使用(打字)', max_score=2, achieved_score=achieved_score, passed=passed, detection_latency_sec=detection_latency_sec, warning_latency_sec=warning_latency_sec, criteria_met=f"警告时延{warning_latency_sec:.1f}s {'≤' if passed else '>'}3s" ) def score_d04_short_distraction_10s(self, cumulative_distraction_sec: float, warning_triggered: bool) -> DistractionTestResult: """ D-04 短分心(10秒累积)评分 通过条件:多次短分心累积10秒触发警告 分值:1分 """ passed = warning_triggered and cumulative_distraction_sec >= self.short_distraction_10_sec achieved_score = 1 if passed else 0 return DistractionTestResult( scenario_id='D-04', scenario_name='短分心(10秒累积)', max_score=1, achieved_score=achieved_score, passed=passed, detection_latency_sec=cumulative_distraction_sec, warning_latency_sec=0, criteria_met=f"累积分心{cumulative_distraction_sec:.1f}s {'≥' if passed else '<'}10s" ) def score_d05_short_distraction_30s(self, cumulative_distraction_sec: float, warning_triggered: bool) -> DistractionTestResult: """ D-05 短分心(30秒累积)评分 通过条件:多次短分心累积30秒触发二级警告 分值:1分 """ passed = warning_triggered and cumulative_distraction_sec >= self.short_distraction_30_sec achieved_score = 1 if passed else 0 return DistractionTestResult( scenario_id='D-05', scenario_name='短分心(30秒累积)', max_score=1, achieved_score=achieved_score, passed=passed, detection_latency_sec=cumulative_distraction_sec, warning_latency_sec=0, criteria_met=f"累积分心{cumulative_distraction_sec:.1f}s {'≥' if passed else '<'}30s" ) def score_d06_vats(self, gaze_road_ratio: float) -> DistractionTestResult: """ D-06 VATS视觉注意力时间评分 通过条件:注视道路时间占比≥70% 分值:1分 """ passed = gaze_road_ratio >= self.vats_threshold achieved_score = 1 if passed else 0 return DistractionTestResult( scenario_id='D-06', scenario_name='VATS视觉注意力时间', max_score=1, achieved_score=achieved_score, passed=passed, detection_latency_sec=0, warning_latency_sec=0, criteria_met=f"VATS {gaze_road_ratio:.1%} {'≥' if passed else '<'}70%" ) def compute_total_distraction_score(self, results: list) -> Dict: """ 计算分心检测总分 Args: results: 所有场景测试结果列表 Returns: total_score: 总分结果 """ total_achieved = sum(r.achieved_score for r in results) total_max = sum(r.max_score for r in results) return { 'total_achieved': total_achieved, 'total_max': total_max, 'percentage': total_achieved / total_max * 100 if total_max > 0 else 0, 'scenario_results': results, 'full_score_possible': total_achieved == total_max }
if __name__ == "__main__": engine = DistractionScoringEngine() print("=== Euro NCAP 2026 分心检测评分测试 ===") results = [] r1 = engine.score_d01_long_distraction(2.5, 2.8) results.append(r1) print(f"\n{r1.scenario_id} {r1.scenario_name}:") print(f" 得分:{r1.achieved_score}/{r1.max_score}") print(f" 判定:{r1.criteria_met}") r2 = engine.score_d02_phone_ear(2.0, 2.5) results.append(r2) print(f"\n{r2.scenario_id} {r2.scenario_name}:") print(f" 得分:{r2.achieved_score}/{r2.max_score}") print(f" 判定:{r2.criteria_met}") r3 = engine.score_d03_phone_texting(2.8, 3.2) results.append(r3) print(f"\n{r3.scenario_id} {r3.scenario_name}:") print(f" 得分:{r3.achieved_score}/{r3.max_score}") print(f" 判定:{r3.criteria_met}") r4 = engine.score_d04_short_distraction_10s(12.0, True) results.append(r4) print(f"\n{r4.scenario_id} {r4.scenario_name}:") print(f" 得分:{r4.achieved_score}/{r4.max_score}") print(f" 判定:{r4.criteria_met}") r5 = engine.score_d05_short_distraction_30s(25.0, False) results.append(r5) print(f"\n{r5.scenario_id} {r5.scenario_name}:") print(f" 得分:{r5.achieved_score}/{r5.max_score}") print(f" 判定:{r5.criteria_met}") r6 = engine.score_d06_vats(0.75) results.append(r6) print(f"\n{r6.scenario_id} {r6.scenario_name}:") print(f" 得分:{r6.achieved_score}/{r6.max_score}") print(f" 判定:{r6.criteria_met}") total = engine.compute_total_distraction_score(results) print(f"\n=== 分心检测总分 ===") print(f" 得分:{total['total_achieved']}/{total['total_max']}") print(f" 百分比:{total['percentage']:.1f}%") print(f" 满分可能:{total['full_score_possible']}")
|