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
| """ Euro NCAP CPD测试标准
通过条件: 1. 检测时间 ≤ 90秒 2. 报警触发(声光/手机推送) 3. 无误报(空车厢场景) """
from dataclasses import dataclass from typing import List from enum import Enum
class AlertLevel(Enum): """报警等级""" LEVEL_1 = "visual_audio" LEVEL_2 = "external_alert"
@dataclass class CPDTestResult: """CPD测试结果""" scenario_id: str detection_time_sec: float alert_triggered: bool alert_level: AlertLevel false_positive: bool def passed(self) -> bool: """是否通过""" return ( self.detection_time_sec <= 90.0 and self.alert_triggered and not self.false_positive )
class CPDProtocolValidator: """ Euro NCAP CPD Protocol v1.3 验证器 """ def __init__(self): self.max_detection_time = 90.0 self.min_confidence = 0.95 self.max_false_positive_rate = 0.001 def validate_scenario( self, scenario_id: str, detection_time: float, confidence: float, is_empty_vehicle: bool ) -> CPDTestResult: """ 验证单个测试场景 Args: scenario_id: 场景ID (CPD-01 ~ CPD-06) detection_time: 检测时间(秒) confidence: 检测置信度 is_empty_vehicle: 是否为空车厢测试 Returns: 测试结果 """ if is_empty_vehicle: return CPDTestResult( scenario_id=scenario_id, detection_time_sec=0.0, alert_triggered=False, alert_level=AlertLevel.LEVEL_1, false_positive=confidence > 0.5 ) alert_triggered = confidence > self.min_confidence alert_level = AlertLevel.LEVEL_2 if detection_time > 60 else AlertLevel.LEVEL_1 return CPDTestResult( scenario_id=scenario_id, detection_time_sec=detection_time, alert_triggered=alert_triggered, alert_level=alert_level, false_positive=False ) def calculate_rating( self, results: List[CPDTestResult] ) -> dict: """ 计算Euro NCAP评分 Returns: { 'points': 得分(满分25), 'max_points': 25, 'percentage': 百分比, 'star_rating': 星级预测 } """ passed_count = sum(1 for r in results if r.passed()) total_count = len(results) points = (passed_count / total_count) * 25 if total_count > 0 else 0 return { 'points': points, 'max_points': 25, 'percentage': (passed_count / total_count) * 100 if total_count > 0 else 0, 'star_rating': '★★★★★' if points >= 22.5 else '★★★★' if points >= 18.75 else '★★★' }
if __name__ == "__main__": validator = CPDProtocolValidator() test_results = [ validator.validate_scenario("CPD-01", 45.2, 0.97, False), validator.validate_scenario("CPD-02", 52.1, 0.95, False), validator.validate_scenario("CPD-03", 68.5, 0.93, False), validator.validate_scenario("CPD-04", 75.3, 0.91, False), validator.validate_scenario("CPD-05", 55.0, 0.96, False), validator.validate_scenario("CPD-06", 60.0, 0.94, False), validator.validate_scenario("CPD-EMPTY", 0.0, 0.15, True), ] rating = validator.calculate_rating(test_results) print("=" * 60) print("Euro NCAP CPD Protocol v1.3 测试报告") print("=" * 60) for result in test_results: status = "✓ PASS" if result.passed() else "✗ FAIL" print(f"{result.scenario_id}: {result.detection_time_sec:.1f}s, {status}") print("\n评分结果:") print(f" 得分: {rating['points']:.1f}/{rating['max_points']}") print(f" 通过率: {rating['percentage']:.1f}%") print(f" 星级预测: {rating['star_rating']}")
|