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
| OCCUPANT_CATEGORIES = { 'adult': { 'weight_range': (50, 120), 'height_range': (150, 200), 'airbag_mode': 'full' }, 'child': { 'weight_range': (15, 50), 'height_range': (100, 150), 'airbag_mode': 'reduced' }, 'infant': { 'weight_range': (0, 15), 'height_range': (0, 100), 'airbag_mode': 'disabled' }, 'empty': { 'weight_range': (0, 2), 'height_range': (0, 0), 'airbag_mode': 'disabled' } }
class OccupantClassifier: """乘员分类器""" def __init__(self): self.weight_sensor = WeightSensorMatrix() self.height_estimator = HeightEstimator() def classify(self) -> dict: """分类乘员""" weight = self.weight_sensor.read_total() height = self.height_estimator.estimate() for category, criteria in OCCUPANT_CATEGORIES.items(): w_min, w_max = criteria['weight_range'] h_min, h_max = criteria['height_range'] if w_min <= weight <= w_max and h_min <= height <= h_max: return { 'category': category, 'weight': weight, 'height': height, 'airbag_mode': criteria['airbag_mode'] } return {'category': 'unknown', 'airbag_mode': 'safe'}
|