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 schedule_primary_school_occupancy(directory): weekday_school = ScheduleDay('Weekday School Year', [0, 1, 0.5, 0], [Time(0, 0), Time(8, 0), Time(15, 0), Time(18, 0)]) weekend_school = ScheduleDay('Weekend School Year', [0]) weekday_summer = ScheduleDay('Weekday Summer', [0, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_summer = ScheduleDay('Weekend Summer', [0]) summer_weekday_rule = ScheduleRule( weekday_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekday_rule.apply_weekday = True summer_weekend_rule = ScheduleRule( weekend_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekend_rule.apply_weekend = True school_weekend_rule = ScheduleRule(weekend_school) school_weekend_rule.apply_weekend = True summer_design = ScheduleDay('School Summer Design', [0, 1, 0.25], [Time(0, 0), Time(6, 0), Time(18, 0)]) winter_design = ScheduleDay('School Winter Design', [0]) schedule = ScheduleRuleset('School Occupancy', weekday_school, [summer_weekday_rule, summer_weekend_rule, school_weekend_rule], schedule_types.fractional, weekend_summer, summer_design, winter_design) dest_file = os.path.join(directory, 'schedule_primary_school_occupancy.json') with open(dest_file, 'w') as fp: json.dump(schedule.to_dict(True), fp, indent=4)
def test_schedule_ruleset_to_from_idf(): """Test the ScheduleRuleset to_idf and from_idf methods.""" 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]) week_rule = ScheduleRule(weekday_office) week_rule.apply_weekday = True sat_rule = ScheduleRule(saturday_office, apply_saturday=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', sunday_office, [week_rule, sat_rule], schedule_types.fractional, summer_office, winter_office) year_sched, week_scheds = schedule.to_idf() assert len(week_scheds) == 1 day_scheds = (weekday_office.to_idf(), saturday_office.to_idf(), sunday_office.to_idf(), summer_office.to_idf(), winter_office.to_idf()) sch_type = schedule_types.fractional.to_idf() rebuilt_schedule = ScheduleRuleset.from_idf(year_sched, week_scheds, day_scheds, sch_type) rebuilt_year_sched, rebuilt_week_scheds = rebuilt_schedule.to_idf() assert rebuilt_year_sched == year_sched assert rebuilt_week_scheds[0] == week_scheds[0]
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_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_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_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_schedule_ruleset_average_schedules_date_range(): """Test the ScheduleRuleset average_schedules method with schedules over a date range.""" weekday_school = ScheduleDay( 'Weekday School Year', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(17, 0)]) weekend_school = ScheduleDay('Weekend School Year', [0.1]) weekday_summer = ScheduleDay( 'Weekday Summer', [0, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_summer = ScheduleDay('Weekend Summer', [0]) summer_weekday_rule = ScheduleRule(weekday_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekday_rule.apply_weekday = True summer_weekend_rule = ScheduleRule(weekend_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekend_rule.apply_weekend = True summer_weekend_rule.apply_holiday = True school_weekend_rule = ScheduleRule(weekend_school) school_weekend_rule.apply_weekend = True school_weekend_rule.apply_holiday = True summer_design = ScheduleDay( 'School Summer Design', [0, 1, 0.25], [Time(0, 0), Time(6, 0), Time(18, 0)]) winter_design = ScheduleDay('School Winter Design', [0]) all_rules = [summer_weekday_rule, summer_weekend_rule, school_weekend_rule] school_schedule = ScheduleRuleset('School Occupancy', weekday_school, all_rules, schedule_types.fractional, summer_design, winter_design) lobby_schedule = ScheduleRuleset.from_constant_value( 'Lobby Occupancy', 0.1, schedule_types.fractional) school_avg = ScheduleRuleset.average_schedules( 'Office Average', [school_schedule, lobby_schedule]) week_vals = school_avg.values(end_date=Date(1, 7)) avg_vals = [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ] assert week_vals[:24] == [0.1] * 24 assert week_vals[24:48] == avg_vals week_vals = school_avg.values(start_date=Date(7, 1), end_date=Date(7, 7)) avg_vals = [ 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05 ] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals
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_rule_apply(): """Test the ScheduleRule apply properties.""" simple_office = ScheduleDay( 'Simple Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) sched_rule = ScheduleRule(simple_office) assert not sched_rule.apply_sunday sched_rule.apply_sunday = True assert sched_rule.apply_sunday assert not sched_rule.apply_monday sched_rule.apply_monday = True assert sched_rule.apply_monday assert not sched_rule.apply_tuesday sched_rule.apply_tuesday = True assert sched_rule.apply_tuesday assert not sched_rule.apply_wednesday sched_rule.apply_wednesday = True assert sched_rule.apply_wednesday assert not sched_rule.apply_thursday sched_rule.apply_thursday = True assert sched_rule.apply_thursday assert not sched_rule.apply_friday sched_rule.apply_friday = True assert sched_rule.apply_friday assert not sched_rule.apply_saturday sched_rule.apply_saturday = True assert sched_rule.apply_saturday assert sched_rule.apply_weekday assert sched_rule.apply_weekend assert sched_rule.apply_all
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_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_rule_apply_day_by_dow(): """Test the ScheduleRule apply_day_by_dow properties.""" simple_office = ScheduleDay( 'Simple Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) sched_rule = ScheduleRule(simple_office) assert not sched_rule.apply_sunday sched_rule.apply_day_by_dow(1) assert sched_rule.apply_sunday assert not sched_rule.apply_monday sched_rule.apply_day_by_dow(2) assert sched_rule.apply_monday assert not sched_rule.apply_tuesday sched_rule.apply_day_by_dow(3) assert sched_rule.apply_tuesday assert not sched_rule.apply_wednesday sched_rule.apply_day_by_dow(4) assert sched_rule.apply_wednesday assert not sched_rule.apply_thursday sched_rule.apply_day_by_dow(5) assert sched_rule.apply_thursday assert not sched_rule.apply_friday sched_rule.apply_day_by_dow(6) assert sched_rule.apply_friday assert not sched_rule.apply_saturday sched_rule.apply_day_by_dow(7) assert sched_rule.apply_saturday assert not sched_rule.apply_holiday sched_rule.apply_day_by_dow(8) assert sched_rule.apply_holiday assert sched_rule.apply_weekday assert sched_rule.apply_weekend assert sched_rule.apply_all
def test_schedule_rule_apply_day_by_name(): """Test the ScheduleRule apply_day_by_name properties.""" simple_office = ScheduleDay( 'Simple Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) sched_rule = ScheduleRule(simple_office) assert not sched_rule.apply_sunday sched_rule.apply_day_by_name('Sunday') assert sched_rule.apply_sunday assert not sched_rule.apply_monday sched_rule.apply_day_by_name('Monday') assert sched_rule.apply_monday assert not sched_rule.apply_tuesday sched_rule.apply_day_by_name('Tuesday') assert sched_rule.apply_tuesday assert not sched_rule.apply_wednesday sched_rule.apply_day_by_name('Wednesday') assert sched_rule.apply_wednesday assert not sched_rule.apply_thursday sched_rule.apply_day_by_name('Thursday') assert sched_rule.apply_thursday assert not sched_rule.apply_friday sched_rule.apply_day_by_name('Friday') assert sched_rule.apply_friday assert not sched_rule.apply_saturday sched_rule.apply_day_by_name('Saturday') assert sched_rule.apply_saturday assert not sched_rule.apply_holiday sched_rule.apply_day_by_name('Holiday') assert sched_rule.apply_holiday assert sched_rule.apply_weekday assert sched_rule.apply_weekend assert sched_rule.apply_all
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_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_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_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_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_people_average(): """Test the People.average 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) lobby_activity = ScheduleRuleset.from_constant_value( 'Lobby Activity Sched', 160, schedule_types.activity_level) office_people = People('Office People', 0.05, office_schedule) lobby_people = People('Lobby People', 0.1, lobby_schedule, lobby_activity, 0.4, 0.2) office_avg = People.average('Office Average People', [office_people, lobby_people]) assert office_avg.people_per_area == pytest.approx(0.075, rel=1e-3) assert office_avg.radiant_fraction == pytest.approx(0.35, rel=1e-3) assert office_avg.latent_fraction == autocalculate week_vals = office_avg.occupancy_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 act_vals = office_avg.activity_schedule.values(end_date=Date(1, 1)) assert act_vals == [140] * 24
def test_infiltration_average(): """Test the Infiltration.average method.""" weekday_office = ScheduleDay( 'Weekday Office Infiltration', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay( 'Weekday Lobby Infiltration', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Infiltration', [0]) weekend_lobby = ScheduleDay('Weekend Office Infiltration', [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 Infiltration', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Infiltration', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_inf = Infiltration('Office Infiltration', 0.0003, office_schedule, 1, 0, 0) lobby_inf = Infiltration('Lobby Infiltration', 0.0006, lobby_schedule, 0.6, 0.03, 0.1) office_avg = Infiltration.average('Average Infiltration', [office_inf, lobby_inf]) assert office_avg.flow_per_exterior_area == pytest.approx(0.00045, rel=1e-3) assert office_avg.constant_coefficient == pytest.approx(0.8, rel=1e-3) assert office_avg.temperature_coefficient == pytest.approx(0.015, rel=1e-3) assert office_avg.velocity_coefficient == pytest.approx(0.05, 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_equipment_average(): """Test the ElectricEquipment.average method.""" weekday_office = ScheduleDay( 'Weekday Office Equip', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay( 'Weekday Lobby Equip', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Equip', [0]) weekend_lobby = ScheduleDay('Weekend Office Equip', [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 Equip', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Equip', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_equip = ElectricEquipment('Office Equip', 10, office_schedule, 0.3, 0.3) lobby_equip = ElectricEquipment('Lobby Equip', 6, lobby_schedule, 0.4, 0.2, 0.1) office_avg = ElectricEquipment.average('Office Average Equip', [office_equip, lobby_equip]) assert office_avg.watts_per_area == pytest.approx(8, rel=1e-3) assert office_avg.radiant_fraction == pytest.approx(0.35, rel=1e-3) assert office_avg.latent_fraction == pytest.approx(0.25, rel=1e-3) assert office_avg.lost_fraction == pytest.approx(0.05, 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_schedule_rule_equality(): """Test the equality of ScheduleRule 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)]) weekday_rule = ScheduleRule(weekday_office) weekday_rule.apply_weekday = True weekday_rule_dup = weekday_rule.duplicate() sat_rule = ScheduleRule(saturday_office, apply_saturday=True) assert weekday_rule is weekday_rule assert weekday_rule is not weekday_rule_dup assert weekday_rule == weekday_rule_dup weekday_rule_dup.apply_friday = False assert weekday_rule != weekday_rule_dup assert weekday_rule != sat_rule
def test_schedule_ruleset_shift_by_step(): """Test the ScheduleRuleset shift_by_step 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) shift_schedule = schedule.shift_by_step(-1) default_vals = weekday_office.values_at_timestep() shift_vals = default_vals[1:] + [default_vals[0]] assert shift_schedule.default_day_schedule.values_at_timestep( ) == shift_vals
def test_schedule_ruleset_to_rules(): """Test the ScheduleRuleset to_rules 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) rules = schedule.to_rules(Date(6, 1), Date(8, 31)) assert len(rules) == 3 for rule in rules: assert rule.start_date == Date(6, 1) assert rule.end_date == Date(8, 31)
def test_schedule_ruleset_data_collection(): """Test the ScheduleRuleset data_collection 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) sch_data = schedule.data_collection() assert len(sch_data) == 8760 assert isinstance(sch_data.header.data_type, fraction.Fraction) assert sch_data.header.unit == 'fraction' assert sch_data.header.analysis_period == AnalysisPeriod()
def test_schedule_does_rule_apply(): """Test the ScheduleRule does_rule_apply properties.""" weekday_school = ScheduleDay( 'Weekday School Year', [0, 1, 0.5, 0], [Time(0, 0), Time(8, 0), Time(15, 0), Time(18, 0)]) weekend_school = ScheduleDay('Weekend School Year', [0]) weekday_summer = ScheduleDay( 'Weekday Summer', [0, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_summer = ScheduleDay('Weekend Summer', [0]) school_weekday_rule = ScheduleRule(weekday_school) school_weekday_rule.apply_weekday = True school_weekend_rule = ScheduleRule(weekend_school) school_weekend_rule.apply_weekend = True school_weekend_rule.apply_holiday = True summer_weekday_rule = ScheduleRule(weekday_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekday_rule.apply_weekday = True summer_weekend_rule = ScheduleRule(weekend_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekend_rule.apply_weekend = True summer_weekend_rule.apply_holiday = True assert school_weekday_rule.does_rule_apply(1, 4) assert not school_weekday_rule.does_rule_apply(1, 1) assert school_weekend_rule.does_rule_apply(1, 1) assert not school_weekend_rule.does_rule_apply(1, 4) assert summer_weekday_rule.does_rule_apply(Date(7, 15).doy, 4) assert not summer_weekday_rule.does_rule_apply(Date(7, 15).doy, 1) assert not summer_weekday_rule.does_rule_apply(1, 4) assert school_weekend_rule.does_rule_apply(Date(7, 15).doy, 1) assert not school_weekend_rule.does_rule_apply(Date(7, 15).doy, 4) assert not summer_weekday_rule.does_rule_apply(1, 1)
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)]) sched_rule = ScheduleRule(simple_office) sched_rule.apply_weekday = True rule_dict = sched_rule.to_dict() new_sched_rule = ScheduleRule.from_dict(rule_dict) assert new_sched_rule == sched_rule assert rule_dict == new_sched_rule.to_dict()
def test_schedule_ruleset_to_idf_date_range(): """Test the ScheduleRuleset to_idf and from_idf methods.""" weekday_school = ScheduleDay( 'Weekday School Year', [0, 1, 0.5, 0], [Time(0, 0), Time(8, 0), Time(15, 0), Time(18, 0)]) weekend_school = ScheduleDay('Weekend School Year', [0]) weekday_summer = ScheduleDay( 'Weekday Summer', [0, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_summer = ScheduleDay('Weekend Summer', [0]) summer_weekday_rule = ScheduleRule(weekday_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekday_rule.apply_weekday = True summer_weekend_rule = ScheduleRule(weekend_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekend_rule.apply_weekend = True summer_weekend_rule.apply_holiday = True school_weekend_rule = ScheduleRule(weekend_school) school_weekend_rule.apply_weekend = True school_weekend_rule.apply_holiday = True summer_design = ScheduleDay( 'School Summer Design', [0, 1, 0.25], [Time(0, 0), Time(6, 0), Time(18, 0)]) winter_design = ScheduleDay('School Winter Design', [0]) schedule = ScheduleRuleset( 'School Occupancy', weekday_school, [summer_weekday_rule, summer_weekend_rule, school_weekend_rule], schedule_types.fractional, summer_design, winter_design) year_sched, week_scheds = schedule.to_idf() assert len(year_sched.split(',')) > 6 assert len(week_scheds) == 2 """