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
| class HMIEvaluator: """ Euro NCAP HMI评估器 """ def __init__(self): self.scoring_rules = { 'horn': {'physical_button': 2, 'touchscreen': 0, 'voice': 1}, 'windshield_wipers': {'physical_button': 2, 'touchscreen': 0, 'voice': 1}, 'indicators': {'physical_lever': 2, 'touchscreen': 0, 'voice': 0}, 'hazard_lights': {'physical_button': 2, 'touchscreen': 1, 'voice': 1}, 'lights': {'physical_switch': 2, 'touchscreen': 0, 'auto': 2}, 'defogger': {'physical_button': 2, 'touchscreen': 0, 'voice': 1} } self.position_requirements = { 'horn': {'min_distance': 0, 'max_distance': 0.3}, 'windshield_wipers': {'min_distance': 0, 'max_distance': 0.4}, 'indicators': {'min_distance': 0, 'max_distance': 0.3}, 'hazard_lights': {'min_distance': 0, 'max_distance': 0.5} } def evaluate_vehicle(self, vehicle_config): """ 评估车辆HMI配置 Args: vehicle_config: { 'horn': {'type': 'physical_button', 'position': [0.1, 0.0, 0.3]}, ... } Returns: { 'total_score': int, 'max_score': int, 'details': dict } """ total_score = 0 max_score = len(self.scoring_rules) * 2 details = {} for function, config in vehicle_config.items(): if function in self.scoring_rules: interaction_type = config['type'] score = self.scoring_rules[function].get(interaction_type, 0) if 'position' in config: position_score = self.check_position(function, config['position']) score = min(score, position_score) total_score += score details[function] = { 'type': interaction_type, 'score': score, 'max_score': 2 } return { 'total_score': total_score, 'max_score': max_score, 'details': details, 'percentage': total_score / max_score * 100 } def check_position(self, function, position): """ 检查位置是否满足要求 """ if function in self.position_requirements: req = self.position_requirements[function] distance = np.linalg.norm(position) if req['min_distance'] <= distance <= req['max_distance']: return 2 else: return 1 return 2
if __name__ == "__main__": traditional_config = { 'horn': {'type': 'physical_button', 'position': [0.1, 0.0, 0.3]}, 'windshield_wipers': {'type': 'physical_button', 'position': [0.2, 0.0, 0.35]}, 'indicators': {'type': 'physical_lever', 'position': [0.15, 0.1, 0.3]}, 'hazard_lights': {'type': 'physical_button', 'position': [0.3, 0.0, 0.4]}, 'lights': {'type': 'physical_switch', 'position': [0.25, 0.0, 0.4]}, 'defogger': {'type': 'physical_button', 'position': [0.35, 0.0, 0.45]} } touchscreen_config = { 'horn': {'type': 'touchscreen', 'position': [0.5, 0.2, 0.4]}, 'windshield_wipers': {'type': 'touchscreen', 'position': [0.5, 0.2, 0.4]}, 'indicators': {'type': 'touchscreen', 'position': [0.5, 0.2, 0.4]}, 'hazard_lights': {'type': 'touchscreen', 'position': [0.5, 0.2, 0.4]}, 'lights': {'type': 'touchscreen', 'position': [0.5, 0.2, 0.4]}, 'defogger': {'type': 'touchscreen', 'position': [0.5, 0.2, 0.4]} } evaluator = HMIEvaluator() trad_result = evaluator.evaluate_vehicle(traditional_config) touch_result = evaluator.evaluate_vehicle(touchscreen_config) print(f"传统配置得分: {trad_result['total_score']}/{trad_result['max_score']} ({trad_result['percentage']:.0f}%)") print(f"触摸屏配置得分: {touch_result['total_score']}/{touch_result['max_score']} ({touch_result['percentage']:.0f}%)") print(f"得分差距: {trad_result['total_score'] - touch_result['total_score']}分")
|