def test_setpoint_equality(): """Test the equality of Setpoint objects.""" simple_heat = ScheduleDay( 'Simple Weekday HtgSetp', [18, 21, 18], [Time(0, 0), Time(9, 0), Time(17, 0)]) simple_cool = ScheduleDay( 'Simple Weekday ClgSetp', [28, 24, 28], [Time(0, 0), Time(9, 0), Time(17, 0)]) heat_setpt = ScheduleRuleset('Office Heating', simple_heat, None, schedule_types.temperature) cool_setpt = ScheduleRuleset('Office Cooling', simple_cool, None, schedule_types.temperature) heat_setpt_2 = ScheduleRuleset.from_constant_value( 'Office Heating', 21, schedule_types.temperature) cool_setpt_2 = ScheduleRuleset.from_constant_value( 'Office Cooling', 24, schedule_types.temperature) setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt) setpoint_dup = setpoint.duplicate() setpoint_alt = Setpoint('Office Setpoint', heat_setpt_2, cool_setpt_2) assert setpoint is setpoint assert setpoint is not setpoint_dup assert setpoint == setpoint_dup setpoint_dup.humidifying_setpoint = 30 assert setpoint != setpoint_dup assert setpoint != setpoint_alt
def test_schedule_day_values_at_timestep_interpolate(): """Test the ScheduleDay values_at_timestep method.""" simple_office = ScheduleDay( 'Simple Office Occupancy', [1, 2, 1, 2, 1], [Time(0, 0), Time(6, 0), Time(12, 0), Time(16, 0), Time(20, 0)]) simple_office.interpolate = True hourly_vals = simple_office.values_at_timestep() half_hour_vals = simple_office.values_at_timestep(2) hourly_vals_from_ep = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.166667, 1.333333, 1.5, 1.666667, 1.833333, 2.0, 1.75, 1.5, 1.25, 1.0, 1.25, 1.5, 1.75, 2.0, 1.75, 1.5, 1.25, 1.0 ] vals_from_ep = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.083333, 1.166667, 1.25, 1.333333, 1.416667, 1.5, 1.583333, 1.666667, 1.75, 1.833333, 1.916667, 2.0, 1.875, 1.75, 1.625, 1.5, 1.375, 1.25, 1.125, 1.0, 1.125, 1.25, 1.375, 1.5, 1.625, 1.75, 1.875, 2.0, 1.875, 1.75, 1.625, 1.5, 1.375, 1.25, 1.125, 1.0 ] for hb_val, ep_val in zip(hourly_vals, hourly_vals_from_ep): assert hb_val == pytest.approx(ep_val, rel=1e-3) for hb_val, ep_val in zip(half_hour_vals, vals_from_ep): assert hb_val == pytest.approx(ep_val, rel=1e-3)
def test_schedule_day_data_collection(): """Test the ScheduleDay data_collection method.""" simple_office = ScheduleDay( 'Simple Office Occupancy', [1, 2, 1, 2, 1], [Time(0, 0), Time(6, 0), Time(12, 0), Time(16, 0), Time(20, 0)]) office_data = simple_office.data_collection(Date(6, 21), schedule_types.fractional) hour_vals_from_ep = (1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1) assert isinstance(office_data, HourlyContinuousCollection) assert office_data.values == hour_vals_from_ep assert office_data.header.analysis_period == AnalysisPeriod( 6, 21, 0, 6, 21, 23) assert office_data.header.data_type == schedule_types.fractional.data_type assert office_data.header.unit == schedule_types.fractional.unit # test without type limits or a start date office_data2 = simple_office.data_collection() assert office_data2.header.analysis_period == AnalysisPeriod( 1, 1, 0, 1, 1, 23) assert isinstance(office_data2.header.data_type, GenericType)
def test_equipment_equality(): """Test the equality of ElectricEquipment objects.""" weekday_office = ScheduleDay( 'Weekday Office Equip', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Equip', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Equip', weekday_office, [weekend_rule], schedule_types.fractional) equipment = ElectricEquipment('Open Office Zone Equip', 10, schedule) equipment_dup = equipment.duplicate() equipment_alt = ElectricEquipment( 'Open Office Zone Equip', 10, ScheduleRuleset.from_constant_value('Constant', 1, schedule_types.fractional)) assert equipment is equipment assert equipment is not equipment_dup assert equipment == equipment_dup equipment_dup.watts_per_area = 6 assert equipment != equipment_dup assert equipment != equipment_alt
def test_equipment_lockability(): """Test the lockability of ElectricEquipment objects.""" weekday_office = ScheduleDay( 'Weekday Office Equip', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Equip', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Equip', weekday_office, [weekend_rule], schedule_types.fractional) equipment = ElectricEquipment('Open Office Zone Equip', 10, schedule) equipment.watts_per_area = 6 equipment.lock() with pytest.raises(AttributeError): equipment.watts_per_area = 8 with pytest.raises(AttributeError): equipment.schedule.default_day_schedule.remove_value_by_time( Time(17, 0)) equipment.unlock() equipment.watts_per_area = 8 with pytest.raises(AttributeError): equipment.schedule.default_day_schedule.remove_value_by_time( Time(17, 0))
def test_people_lockability(): """Test the lockability of People objects.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True occ_schedule = ScheduleRuleset('Office Occupancy', weekday_office, [weekend_rule], schedule_types.fractional) people = People('Open Office Zone People', 0.05, occ_schedule) people.people_per_area = 0.1 people.lock() with pytest.raises(AttributeError): people.people_per_area = 0.1 with pytest.raises(AttributeError): people.occupancy_schedule.default_day_schedule.remove_value_by_time( Time(17, 0)) people.unlock() people.people_per_area = 0.05 with pytest.raises(AttributeError): people.occupancy_schedule.default_day_schedule.remove_value_by_time( Time(17, 0))
def test_setpoint_init_from_idf_humidity(): """Test the initialization of Setpoint from_idf with humidity setpoints.""" simple_heat = ScheduleDay( 'Simple Weekday HtgSetp', [18, 21, 18], [Time(0, 0), Time(9, 0), Time(17, 0)]) simple_cool = ScheduleDay( 'Simple Weekday ClgSetp', [28, 24, 28], [Time(0, 0), Time(9, 0), Time(17, 0)]) heat_setpt = ScheduleRuleset('Office Heating', simple_heat, None, schedule_types.temperature) cool_setpt = ScheduleRuleset('Office Cooling', simple_cool, None, schedule_types.temperature) humid_setpt = ScheduleRuleset.from_constant_value('Office Humid', 30, schedule_types.humidity) dehumid_setpt = ScheduleRuleset.from_constant_value( 'Office Dehumid', 60, schedule_types.humidity) setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt, humid_setpt, dehumid_setpt) sched_dict = { heat_setpt.identifier: heat_setpt, cool_setpt.identifier: cool_setpt, humid_setpt.identifier: humid_setpt, dehumid_setpt.identifier: dehumid_setpt } zone_id = 'Test Zone' idf_str = setpoint.to_idf(zone_id) humid_idf_str = setpoint.to_idf_humidistat(zone_id) rebuilt_setpoint = Setpoint.from_idf(idf_str, sched_dict) rebuilt_setpoint.add_humidity_from_idf(humid_idf_str, sched_dict) assert setpoint == rebuilt_setpoint
def test_schedule_ruleset_equality(): """Test the equality of ScheduleRuleset objects.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Occupancy', weekday_office, [weekend_rule], schedule_types.fractional) schedule_dup = schedule.duplicate() residential_schedule = ScheduleRuleset.from_daily_values( 'Residence Occupancy', [ 1, 1, 1, 1, 1, 1, 1, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.5, 0.5, 0.5, 0.5, 1, 1, 1 ]) assert schedule is schedule assert schedule is not schedule_dup assert schedule == schedule_dup schedule_dup.schedule_rules[0].apply_friday = True assert schedule != schedule_dup assert schedule != residential_schedule
def test_lighting_average(): """Test the Lighting.average method.""" weekday_office = ScheduleDay('Weekday Office Lighting', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay('Weekday Lobby Lighting', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Lighting', [0]) weekend_lobby = ScheduleDay('Weekend Office Lighting', [0.1]) wknd_office_rule = ScheduleRule(weekend_office, apply_saturday=True, apply_sunday=True) wknd_lobby_rule = ScheduleRule(weekend_lobby, apply_saturday=True, apply_sunday=True) office_schedule = ScheduleRuleset('Office Lighting', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Lighting', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_lights = Lighting('Office Lighting', 10, office_schedule, 0, 0.3, 0.3) lobby_lights = Lighting('Lobby Lighting', 6, lobby_schedule, 0.1, 0.4, 0.2) office_avg = Lighting.average('Office Average Lighting', [office_lights, lobby_lights]) assert office_avg.watts_per_area == pytest.approx(8, rel=1e-3) assert office_avg.return_air_fraction == pytest.approx(0.05, rel=1e-3) assert office_avg.radiant_fraction == pytest.approx(0.35, rel=1e-3) assert office_avg.visible_fraction == pytest.approx(0.25, rel=1e-3) week_vals = office_avg.schedule.values(end_date=Date(1, 7)) avg_vals = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals
def test_lighting_lockability(): """Test the lockability of Lighting objects.""" weekday_office = ScheduleDay( 'Weekday Office Lighting', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Lighting', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Lighting', weekday_office, [weekend_rule], schedule_types.fractional) lighting = Lighting('Open Office Zone Lighting', 10, schedule) lighting.watts_per_area = 6 lighting.lock() with pytest.raises(AttributeError): lighting.watts_per_area = 8 with pytest.raises(AttributeError): lighting.schedule.default_day_schedule.remove_value_by_time(Time( 17, 0)) lighting.unlock() lighting.watts_per_area = 8 with pytest.raises(AttributeError): lighting.schedule.default_day_schedule.remove_value_by_time(Time( 17, 0))
def test_service_hot_water_init_from_idf(): """Test the initialization of Lighting from_idf.""" weekday_office = ScheduleDay('Weekday Office Water Use', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay('Saturday Office Water Use', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Water Use', weekday_office, [weekend_rule], schedule_types.fractional) shw = ServiceHotWater('Open Office Zone Hot Water', 0.1, schedule) sched_dict = {schedule.identifier: schedule} room = Room.from_box('Test_Zone', 10, 10, 3) idf_str, sch_strs = shw.to_idf(room) for sch in sch_strs: sch_obj = ScheduleRuleset.from_idf_constant(sch) sched_dict[sch_obj.identifier] = sch_obj rebuilt_shw, room_id, flow = ServiceHotWater.from_idf( idf_str, room.floor_area, sched_dict) if (sys.version_info >= (3, 0)): assert shw == rebuilt_shw assert room_id == room.identifier assert flow == shw.flow_per_area * room.floor_area
def test_set_program_type(): """Test the setting of a ProgramType on a Room.""" lab_equip_day = ScheduleDay('Daily Lab Equipment', [0.25, 0.5, 0.25], [Time(0, 0), Time(9, 0), Time(20, 0)]) lab_equipment = ScheduleRuleset('Lab Equipment', lab_equip_day, None, schedule_types.fractional) lab_vent_day = ScheduleDay('Daily Lab Ventilation', [0.5, 1, 0.5], [Time(0, 0), Time(9, 0), Time(20, 0)]) lab_ventilation = ScheduleRuleset('Lab Ventilation', lab_vent_day, None, schedule_types.fractional) lab_program = office_program.duplicate() lab_program.identifier = 'Bio Laboratory' lab_program.electric_equipment.watts_per_area = 50 lab_program.electric_equipment.schedule = lab_equipment lab_program.ventilation.flow_per_person = 0 lab_program.ventilation.flow_per_area = 0 lab_program.ventilation.air_changes_per_hour = 6 lab_program.ventilation.schedule = lab_ventilation room = Room.from_box('ShoeBox', 5, 10, 3) room.properties.energy.program_type = lab_program assert room.properties.energy.program_type.identifier == 'Bio Laboratory' assert room.properties.energy.program_type == lab_program assert room.properties.energy.electric_equipment.watts_per_area == 50 assert room.properties.energy.electric_equipment.schedule == lab_equipment assert room.properties.energy.ventilation.flow_per_person == 0 assert room.properties.energy.ventilation.flow_per_area == 0 assert room.properties.energy.ventilation.air_changes_per_hour == 6 assert room.properties.energy.ventilation.schedule == lab_ventilation
def test_schedule_ruleset_init(): """Test the ScheduleRuleset initialization and basic properties.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) sunday_office = ScheduleDay('Sunday Office Occupancy', [0]) sat_rule = ScheduleRule(saturday_office, apply_saturday=True) sun_rule = ScheduleRule(sunday_office, apply_sunday=True) summer_office = ScheduleDay( 'Summer Office Occupancy', [0, 1, 0.25], [Time(0, 0), Time(6, 0), Time(22, 0)]) winter_office = ScheduleDay('Winter Office Occupancy', [0]) schedule = ScheduleRuleset('Office Occupancy', weekday_office, [sat_rule, sun_rule], schedule_types.fractional, summer_office, winter_office) str(schedule) # test the string representation assert schedule.name == 'Office Occupancy' assert schedule.default_day_schedule == weekday_office assert schedule.summer_designday_schedule == summer_office assert schedule.winter_designday_schedule == winter_office assert schedule.schedule_type_limit == schedule_types.fractional assert len(schedule.schedule_rules) == 2 schedule.remove_rule(1) assert len(schedule.schedule_rules) == 1 schedule.add_rule(sun_rule) assert len(schedule.schedule_rules) == 2 with pytest.raises(ValueError): schedule = ScheduleRuleset('Office Occupancy', weekday_office)
def test_schedule_ruleset_from_week_day_schedules(): """Test the initialization of ScheduleRuleset from_week_day_schedules.""" weekday_vals = [ 0, 0, 0, 0, 0, 0, 0, 0.1, 0.25, 1, 1, 1, 0.5, 1, 1, 1, 1, 0.5, 0.5, 0.25, 0, 0, 0, 0 ] sat_vals = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0 ] sun_vals = [0 for i in range(24)] weekday = ScheduleDay.from_values_at_timestep('Weekday Office Occ', weekday_vals) sat = ScheduleDay.from_values_at_timestep('Saturday Office Occ', sat_vals) sun = ScheduleDay.from_values_at_timestep('Sunday Office Occ', sun_vals) schedule = ScheduleRuleset.from_week_day_schedules( 'Office Occ', sun, weekday, weekday, weekday, weekday, weekday, sat, sun, weekday, sun, schedule_types.fractional) assert schedule.identifier == 'Office Occ' assert len(schedule.schedule_rules) == 2 assert schedule.summer_designday_schedule.values_at_timestep( ) == weekday_vals assert schedule.winter_designday_schedule.values_at_timestep() == sun_vals sch_week_vals = schedule.values(end_date=Date(1, 7)) assert sch_week_vals == sun_vals + weekday_vals + weekday_vals + weekday_vals + \ weekday_vals + weekday_vals + sat_vals
def test_set_loads(): """Test the setting of a load objects on a Room.""" lab_equip_day = ScheduleDay('Daily Lab Equipment', [0.25, 0.5, 0.25], [Time(0, 0), Time(9, 0), Time(20, 0)]) lab_equipment = ScheduleRuleset('Lab Equipment', lab_equip_day, None, schedule_types.fractional) lab_vent_day = ScheduleDay('Daily Lab Ventilation', [0.5, 1, 0.5], [Time(0, 0), Time(9, 0), Time(20, 0)]) lab_ventilation = ScheduleRuleset('Lab Ventilation', lab_vent_day, None, schedule_types.fractional) room = Room.from_box('BioLaboratoryZone', 5, 10, 3) room.properties.energy.program_type = office_program lab_equip = ElectricEquipment('Lab Equipment', 50, lab_equipment) lav_vent = Ventilation('Lab Ventilation', 0, 0, 0, 6, lab_ventilation) lab_setpt = room.properties.energy.setpoint.duplicate() lab_setpt.heating_setpoint = 22 lab_setpt.cooling_setpoint = 24 room.properties.energy.electric_equipment = lab_equip room.properties.energy.ventilation = lav_vent room.properties.energy.setpoint = lab_setpt assert room.properties.energy.program_type == office_program assert room.properties.energy.electric_equipment.watts_per_area == 50 assert room.properties.energy.electric_equipment.schedule == lab_equipment assert room.properties.energy.ventilation.flow_per_person == 0 assert room.properties.energy.ventilation.flow_per_area == 0 assert room.properties.energy.ventilation.air_changes_per_hour == 6 assert room.properties.energy.ventilation.schedule == lab_ventilation assert room.properties.energy.setpoint.heating_setpoint == 22 assert room.properties.energy.setpoint.heating_setback == 22 assert room.properties.energy.setpoint.cooling_setpoint == 24 assert room.properties.energy.setpoint.cooling_setback == 24
def test_schedule_day_from_standards_dict(): """Test the ScheduleDay from_standards_dict method.""" test_dict_1 = { "name": "Large Office Bldg Light", "category": "Lighting", "units": None, "day_types": "Sun", "start_date": "2014-01-01T00:00:00+00:00", "end_date": "2014-12-31T00:00:00+00:00", "type": "Constant", "notes": "From DOE Reference Buildings ", "values": [0.0]} test_dict_2 = { "name": "Large Office Bldg Occ", "category": "Occupancy", "units": None, "day_types": "Default", "start_date": "2014-01-01T00:00:00+00:00", "end_date": "2014-12-31T00:00:00+00:00", "type": "Hourly", "notes": "From DOE Reference Buildings ", "values": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.2, 0.95, 0.95, 0.95, 0.95, 0.5, 0.95, 0.95, 0.95, 0.95, 0.7, 0.4, 0.4, 0.1, 0.1, 0.05, 0.05]} schedule_1 = ScheduleDay.from_standards_dict(test_dict_1) schedule_2 = ScheduleDay.from_standards_dict(test_dict_2) assert schedule_1.name == "Large Office Bldg Light_Sun" assert schedule_1.is_constant assert schedule_1[0] == 0 assert schedule_2.name == "Large Office Bldg Occ_Default" assert not schedule_2.is_constant assert len(schedule_2) == 10 assert schedule_2.values == (0, 0.1, 0.2, 0.95, 0.5, 0.95, 0.7, 0.4, 0.1, 0.05)
def test_people_equality(): """Test the equality of People objects.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True occ_schedule = ScheduleRuleset('Office Occupancy', weekday_office, [weekend_rule], schedule_types.fractional) people = People('Open Office Zone People', 0.05, occ_schedule) people_dup = people.duplicate() people_alt = People( 'Open Office Zone People', 0.05, ScheduleRuleset.from_constant_value('Constant', 1, schedule_types.fractional)) assert people is people assert people is not people_dup assert people == people_dup people_dup.people_per_area = 0.06 assert people != people_dup assert people != people_alt
def test_schedule_ruleset_average_schedules(): """Test the average_schedules method.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay( 'Weekday Lobby Occupancy', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Occupancy', [0]) weekend_lobby = ScheduleDay('Weekend Office Occupancy', [0.1]) wknd_office_rule = ScheduleRule(weekend_office, apply_saturday=True, apply_sunday=True) wknd_lobby_rule = ScheduleRule(weekend_lobby, apply_saturday=True, apply_sunday=True) office_schedule = ScheduleRuleset('Office Occupancy', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Occupancy', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_avg = ScheduleRuleset.average_schedules( 'Office Average', [office_schedule, lobby_schedule]) week_vals = office_avg.values(end_date=Date(1, 7)) avg_vals = [ 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05 ] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals assert (len(office_avg.schedule_rules)) == 1
def test_schedule_day_init_from_idf_hourly(): """Test the initialization of ScheduleDay from_idf Schedule:Day:Hourly.""" sched_str = """Schedule:Day:Hourly, Simple Office Occupancy, !- Name , !- Schedule Type Limits Name 0, !- Hour 1 0, !- Hour 2 0, !- Hour 3 0, !- Hour 4 0, !- Hour 5 0, !- Hour 6 0, !- Hour 7 0, !- Hour 8 0, !- Hour 9 1, !- Hour 10 1, !- Hour 11 1, !- Hour 12 1, !- Hour 13 1, !- Hour 14 1, !- Hour 15 1, !- Hour 16 1, !- Hour 17 0, !- Hour 18 0, !- Hour 19 0, !- Hour 20 0, !- Hour 21 0, !- Hour 22 0, !- Hour 23 0; !- Hour 24 """ test_sched = ScheduleDay.from_idf(sched_str) simple_office = ScheduleDay('Simple Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) assert test_sched == simple_office
def test_schedule_day_init_from_idf(): """Test the initialization of ScheduleDay from_idf.""" sched_str = """Schedule:Day:Interval,\n Medium Office Bldg Occ Default Schedule, !- Name\n Schedule Type Limits 1, !- Schedule Type Limits Name\n No, !- Interpolate to Timestep\n 06:00, !- Time 1 {hh:mm}\n 0, !- Value Until Time 1\n 07:00, !- Time 2 {hh:mm}\n 0.1, !- Value Until Time 2\n 08:00, !- Time 3 {hh:mm}\n 0.2, !- Value Until Time 3\n 12:00, !- Time 4 {hh:mm}\n 0.95, !- Value Until Time 4\n 13:00, !- Time 5 {hh:mm}\n 0.5, !- Value Until Time 5\n 17:00, !- Time 6 {hh:mm}\n 0.95, !- Value Until Time 6\n 18:00, !- Time 7 {hh:mm}\n 0.7, !- Value Until Time 7\n 20:00, !- Time 8 {hh:mm}\n 0.4, !- Value Until Time 8\n 22:00, !- Time 9 {hh:mm}\n 0.1, !- Value Until Time 9\n 24:00, !- Time 10 {hh:mm}\n 0.05; !- Value Until Time 10 """ test_sched = ScheduleDay.from_idf(sched_str) rebuilt_sched = ScheduleDay.from_idf(test_sched.to_idf()) assert test_sched == rebuilt_sched
def test_service_hot_water_average(): """Test the ServiceHotWater.average method.""" weekday_office = ScheduleDay('Weekday Office Water Use', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay('Weekday Lobby Water Use', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Water Use', [0]) weekend_lobby = ScheduleDay('Weekend Office Water Use', [0.1]) wknd_office_rule = ScheduleRule(weekend_office, apply_saturday=True, apply_sunday=True) wknd_lobby_rule = ScheduleRule(weekend_lobby, apply_saturday=True, apply_sunday=True) office_schedule = ScheduleRuleset('Office Water Use', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Water Use', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_shws = ServiceHotWater( 'Office Hot Water', 0.05, office_schedule, 60, 0.3, 0.05) br_shws = ServiceHotWater( 'Bathroom Hot Water', 0.1, lobby_schedule, 50, 0.4, 0.1) office_avg = ServiceHotWater.average( 'Office Average Hot Water', [office_shws, br_shws]) assert office_avg.flow_per_area == pytest.approx(0.075, rel=1e-3) assert office_avg.target_temperature == pytest.approx(55.0, rel=1e-3) assert office_avg.sensible_fraction == pytest.approx(0.35, rel=1e-3) assert office_avg.latent_fraction == pytest.approx(0.075, rel=1e-3) week_vals = office_avg.schedule.values(end_date=Date(1, 7)) avg_vals = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals
def test_lighting_equality(): """Test the equality of Lighting objects.""" weekday_office = ScheduleDay( 'Weekday Office Lighting', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Lighting', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Lighting', weekday_office, [weekend_rule], schedule_types.fractional) lighting = Lighting('Open Office Zone Lighting', 10, schedule) lighting_dup = lighting.duplicate() lighting_alt = Lighting( 'Open Office Zone Lighting', 10, ScheduleRuleset.from_constant_value('Constant', 1, schedule_types.fractional)) assert lighting is lighting assert lighting is not lighting_dup assert lighting == lighting_dup lighting_dup.watts_per_area = 6 assert lighting != lighting_dup assert lighting != lighting_alt
def test_schedule_day_dict_methods(): """Test the to/from dict methods.""" simple_office = ScheduleDay('Simple Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) sch_dict = simple_office.to_dict() new_simple_office = ScheduleDay.from_dict(sch_dict) assert new_simple_office == simple_office assert sch_dict == new_simple_office.to_dict()
def test_schedule_day_init_from_values_at_timestep(): """Test the initialization of ScheduleDay from_values_at_timestep.""" simple_office = ScheduleDay('Simple Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) half_hour_vals = simple_office.values_at_timestep(2) test_sched = ScheduleDay.from_values_at_timestep('Simple Office Occupancy', half_hour_vals, 2) assert test_sched == simple_office
def test_schedule_ruleset_values(): """Test the ScheduleRuleset values method.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) sunday_office = ScheduleDay('Sunday Office Occupancy', [0]) sat_rule = ScheduleRule(saturday_office, apply_saturday=True) sun_rule = ScheduleRule(sunday_office, apply_sunday=True) schedule = ScheduleRuleset('Office Occupancy', weekday_office, [sat_rule, sun_rule], schedule_types.fractional) assert len(schedule.values()) == 8760 assert len(schedule.values(leap_year=True)) == 8784 sch_week_vals = schedule.values(end_date=Date(1, 7)) assert len(sch_week_vals) == 24 * 7 assert sch_week_vals[:24] == sunday_office.values_at_timestep() assert sch_week_vals[24:48] == weekday_office.values_at_timestep() assert sch_week_vals[144:] == saturday_office.values_at_timestep() sch_week_vals_10_min = schedule.values(6, end_date=Date(1, 7)) assert len(sch_week_vals_10_min) == 24 * 7 * 6
def test_schedule_day_equality(): """Test the equality of ScheduleDay objects.""" simple_office = ScheduleDay('Simple Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) office_dup = simple_office.duplicate() sunday_office = ScheduleDay('Sunday Office Occupancy', [0]) assert simple_office is simple_office assert simple_office is not office_dup assert simple_office == office_dup assert simple_office != sunday_office
def test_schedule_day_average_schedules(): """Test the average_schedules method.""" open_office = ScheduleDay('Open Office Occupancy', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) office_lobby = ScheduleDay('Office Lobby Occupancy', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) office_avg = ScheduleDay.average_schedules( 'Office Average', [open_office, office_lobby]) avg_vals = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05] assert office_avg.values_at_timestep() == avg_vals
def test_schedule_day_add_remove_value_by_time(): """Test the ScheduleDay remove_value_by_time method.""" simple_office = ScheduleDay('Simple Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) simple_office.add_value(0, Time(19, 0)) simple_office.replace_value_by_time(Time(17, 0), 0.5) assert simple_office.values == (0, 1, 0.5, 0) assert simple_office.times == (Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)) simple_office.remove_value_by_time(Time(19, 0)) simple_office.replace_value_by_time(Time(17, 0), 0) assert simple_office.values == (0, 1, 0) assert simple_office.times == (Time(0, 0), Time(9, 0), Time(17, 0))
def test_ventilation_average(): """Test the Ventilation.average method.""" weekday_office = ScheduleDay( 'Weekday Office Ventilation', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay( 'Weekday Lobby Ventilation', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Ventilation', [0]) weekend_lobby = ScheduleDay('Weekend Office Ventilation', [0.1]) wknd_office_rule = ScheduleRule(weekend_office, apply_saturday=True, apply_sunday=True) wknd_lobby_rule = ScheduleRule(weekend_lobby, apply_saturday=True, apply_sunday=True) office_schedule = ScheduleRuleset('Office Ventilation', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Ventilation', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_vent = Ventilation('Office Ventilation', 0.01, 0.0006, 0, 0, office_schedule) lobby_vent = Ventilation('Lobby Ventilation', 0, 0, 0, 1, lobby_schedule) office_avg = Ventilation.average('Average Ventilation', [office_vent, lobby_vent]) assert office_avg.flow_per_person == pytest.approx(0.005, rel=1e-3) assert office_avg.flow_per_area == pytest.approx(0.0003, rel=1e-3) assert office_avg.flow_per_zone == pytest.approx(0, rel=1e-3) assert office_avg.air_changes_per_hour == pytest.approx(0.5, rel=1e-3) week_vals = office_avg.schedule.values(end_date=Date(1, 7)) avg_vals = [ 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05 ] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals office_vent.schedule = None lobby_vent.schedule = None office_avg = Ventilation.average('Average Ventilation', [office_vent, lobby_vent]) assert office_avg.schedule is None
def test_schedule_day_init_from_values(): """Test the initialization of ScheduleDay from_values_at_timestep.""" test_vals = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5] test_sched = ScheduleDay.from_values_at_timestep('Test Schedule', test_vals) assert test_sched.values == (0.5, 1.0, 0.5, 1.0, 0.5) assert test_sched.times == (Time(0, 0), Time(6, 0), Time(12, 0), Time(16, 0), Time(20, 0)) test_sched_2 = ScheduleDay.from_values_at_timestep('Test Schedule', test_vals, remove_repeated=False) assert test_sched_2.values == tuple(test_vals) assert test_sched_2.values_at_timestep() == test_vals assert len(test_sched_2.times) == 24