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
| class MultiStageAirbagController: """ 多级气囊控制器 """ def __init__(self): self.stages = { 'stage_1': {'power': 30, 'delay': 0}, 'stage_2': {'power': 50, 'delay': 10}, 'stage_3': {'power': 70, 'delay': 20}, 'stage_4': {'power': 100, 'delay': 30} } def deploy(self, occupant_class, crash_severity): """ 部署气囊 """ if occupant_class['type'] == 'small_adult': if crash_severity < 50: stages = ['stage_1', 'stage_2'] else: stages = ['stage_1', 'stage_2', 'stage_3'] elif occupant_class['type'] == 'adult': if crash_severity < 50: stages = ['stage_2', 'stage_3'] else: stages = ['stage_2', 'stage_3', 'stage_4'] else: stages = ['stage_3', 'stage_4'] for stage in stages: config = self.stages[stage] self.deploy_stage( config['power'], config['delay'] )
|