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
| """ Euro NCAP DSM 检测时限验证代码 """
from dataclasses import dataclass from typing import List, Tuple
@dataclass class DSMTestScenario: """DSM 测试场景""" scenario_id: str description: str detection_limit_sec: float warning_level: str
DSM_SCENARIOS = [ DSMTestScenario("F-01", "轻度疲劳 KSS 6-7", 120.0, "L1"), DSMTestScenario("F-02", "中度疲劳 KSS 7-8", 60.0, "L2"), DSMTestScenario("F-03", "重度疲劳 KSS >8", 30.0, "Emergency"), DSMTestScenario("F-04", "微睡眠 1-2秒", 3.0, "L1"), DSMTestScenario("F-05", "持续闭眼 >2秒", 1.0, "Emergency"), DSMTestScenario("D-01", "手持通话", 3.0, "L1"), DSMTestScenario("D-02", "手机打字", 3.0, "L1"), DSMTestScenario("D-03", "手机浏览", 5.0, "L1"), DSMTestScenario("D-04", "调整中控", 5.0, "L1"), DSMTestScenario("D-05", "视线偏离 >3秒", 5.0, "L1"), DSMTestScenario("D-06", "低头捡东西", 5.0, "L1"), DSMTestScenario("D-07", "侧身看后座", 5.0, "L1"), DSMTestScenario("D-08", "喝水/吃东西", 10.0, "L1"), DSMTestScenario("CD-01", "心算任务", 10.0, "L1"), DSMTestScenario("CD-02", "白日梦", 15.0, "L1"), DSMTestScenario("CD-03", "通话认知负荷", 5.0, "L1"), ]
def validate_detection( scenario: DSMTestScenario, detection_time_sec: float ) -> Tuple[bool, str]: """ 验证检测结果是否符合 Euro NCAP 要求 Args: scenario: 测试场景 detection_time_sec: 实际检测时间(秒) Returns: passed: 是否通过 message: 验证消息 """ passed = detection_time_sec <= scenario.detection_limit_sec if passed: message = f"✅ {scenario.scenario_id}: 检测时间 {detection_time_sec:.1f}s ≤ {scenario.detection_limit_sec}s" else: message = f"❌ {scenario.scenario_id}: 检测时间 {detection_time_sec:.1f}s > {scenario.detection_limit_sec}s" return passed, message
def run_dsm_test_suite( detection_results: List[Tuple[str, float]] ) -> Tuple[int, int, float]: """ 运行 DSM 测试套件 Args: detection_results: [(scenario_id, detection_time), ...] Returns: passed: 通过数量 total: 总数量 score: 得分率 """ passed = 0 total = len(detection_results) for scenario_id, detection_time in detection_results: scenario = next((s for s in DSM_SCENARIOS if s.scenario_id == scenario_id), None) if scenario is None: print(f"⚠️ 未知场景: {scenario_id}") continue is_passed, message = validate_detection(scenario, detection_time) print(message) if is_passed: passed += 1 score = passed / total * 100 if total > 0 else 0 return passed, total, score
if __name__ == "__main__": test_results = [ ("F-01", 95.0), ("F-02", 55.0), ("F-03", 28.0), ("F-04", 2.8), ("F-05", 0.8), ("D-01", 2.5), ("D-02", 2.8), ("D-03", 4.2), ("D-04", 4.8), ("D-05", 4.5), ("D-06", 4.2), ("D-07", 5.5), ("D-08", 8.5), ("CD-01", 9.0), ("CD-02", 12.0), ("CD-03", 4.5), ] passed, total, score = run_dsm_test_suite(test_results) print(f"\n测试结果: {passed}/{total} 通过,得分率: {score:.1f}%")
|