def test_range_transform_floats(): _from = (0.0, 1.0) to = (20.0, 40.0) tf = range_transform(_from, to) assert tf(0.0) == 20.0 assert tf(0.5) == 30.0 assert tf(1.0) == 40.0
def test_range_transform_ints(): _from = (0, 20) to = (20, 30) tf = range_transform(_from, to) assert tf(0) == 20 assert tf(20) == 30 assert tf(10) == 25
def door_position_input(people_waiting, bearing_condition): """ It should take from 2 to 30 seconds for the doors to almost close. Remaining error could be treated as sensor tolerance. """ # linear transformation (0,100) -> (2,30) time_constant = range_transform((0, 100), (2, 30))(float(bearing_condition)) gain = 10 if people_waiting: return gain, time_constant, 1 else: return gain, time_constant, 0
def test_range_tf_should_raise_when_from_not_a_range(): with pytest.raises(ValueError): range_transform((0, 0), (1, 2))
name='hot_coolant_temp', start=ambient_temp.start, fuse_inputs=hct_fi) & (BoundedBy(ambient_temp.min, ambient_temp.max + 15)) cold_coolant_temp = FirstOrder( human_name="""Temperature of fresh cooling fluid""", name='cold_coolant_temp', start=ambient_temp.start, fuse_inputs=cct_fi) & (BoundedBy(set_point.min - 1, ambient_temp.max)) box_temp = FirstOrder(human_name="""Temperature inside the fridge""", name='box_temp', start=ambient_temp.start, fuse_inputs=bt_fi) & (BoundedBy(cold_coolant_temp.min, ambient_temp.max)) temp_diff_min = hot_coolant_temp.min - cold_coolant_temp.max temp_diff_max = hot_coolant_temp.max - cold_coolant_temp.min gain_from_temp_diff = range_transform((temp_diff_min, temp_diff_max), (0, 0.5)) def ci_fi(cct, hct): tau = 1 return (1 + gain_from_temp_diff(hct - cct), tau, 1) current_in = FirstOrder(human_name="""Current drawn from mains""", name='current_in', start=0, fuse_inputs=ci_fi) & ( ResetBy(partial(eq, thermostat_disabled)), BoundedBy(0, 2), )