def test_check_duplicate_schedule_type_limit_names(): """Test the check_duplicate_schedule_type_limit_names method.""" room = Room.from_box('Tiny House Zone', 5, 10, 3) room.properties.energy.program_type = office_program room.properties.energy.hvac = IdealAirSystem() south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.apertures[0].overhang(0.5, indoor=True) south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5)) fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.6, schedule_types.fractional) on_off = ScheduleTypeLimit('On-off', 0, 1, 'Discrete') full_occ = ScheduleRuleset.from_constant_value('Occupied', 1, on_off) south_face.apertures[0].outdoor_shades[0].properties.energy.transmittance_schedule = \ fritted_glass_trans room.properties.energy.people = People('Office Occ', 0.05, full_occ) model = Model('Tiny House', [room]) assert model.properties.energy.check_duplicate_schedule_type_limit_names( False) full_occ.unlock() new_sch_type = ScheduleTypeLimit('Fractional', 0, 1, 'Discrete') full_occ.schedule_type_limit = new_sch_type full_occ.lock() assert not model.properties.energy.check_duplicate_schedule_type_limit_names( False) with pytest.raises(ValueError): model.properties.energy.check_duplicate_schedule_type_limit_names(True)
def scheduletypelimit_temperature(directory): temperature = ScheduleTypeLimit('Temperature', -273.15, None, 'Continuous', 'Temperature') dest_file = os.path.join(directory, 'scheduletypelimit_temperature.json') with open(dest_file, 'w') as fp: json.dump(temperature.to_dict(), fp, indent=4)
def test_schedule_ruleset_dict_methods(): """Test the ScheduleRuleset to/from dict methods.""" temperature = ScheduleTypeLimit('Temperature', -273.15, None, 'Continuous', 'Temperature') temp_dict = temperature.to_dict() new_temperature = ScheduleTypeLimit.from_dict(temp_dict) assert new_temperature == temperature assert temp_dict == new_temperature.to_dict() """
def test_schedule_typelimit_equality(): """Test the equality of ScheduleTypeLimit objects.""" fractional = ScheduleTypeLimit('Fractional', 0, 1, 'Continuous', 'Dimensionless') fract_dup = fractional.duplicate() temperature = ScheduleTypeLimit('Temperature', -273.15, None, 'Continuous', 'Temperature') assert fractional == fract_dup assert fractional != temperature
def test_schedule_typelimit_to_from_idf(): """Test the ScheduleTypeLimit to_idf and from_idf methods.""" temperature = ScheduleTypeLimit('Temperature', -273.15, None, 'Continuous', 'Temperature') temp_string = temperature.to_idf() rebuilt_temperature = ScheduleTypeLimit.from_idf(temp_string) rebuilt_temp_string = rebuilt_temperature.to_idf() assert rebuilt_temperature == temperature assert rebuilt_temp_string == temp_string
def test_schedule_typelimit_init(): """Test the initialization of ScheduleTypeLimit and basic properties.""" fractional = ScheduleTypeLimit('Fractional', 0, 1, 'Continuous', 'Dimensionless') str(fractional) # test the string representation assert fractional.name == 'Fractional' assert fractional.lower_limit == 0 assert fractional.upper_limit == 1 assert fractional.numeric_type == 'Continuous' assert fractional.unit_type == 'Dimensionless' assert isinstance(fractional.data_type, fraction.Fraction) assert fractional.unit == 'fraction'
def validate_schedule_type_limit(schedule_type_limit_json): """Validate all properties of a ScheduleTypeLimit JSON against the Honeybee schema. \b Args: schedule_type_limit_json: Full path to a ScheduleTypeLimit JSON file. """ try: # first check the JSON against the OpenAPI specification click.echo('Validating ScheduleTypeLimit JSON ...') schema_schedule.ScheduleTypeLimit.parse_file(schedule_type_limit_json) click.echo('Pydantic validation passed.') # re-serialize to make sure no errors are found in re-serialization with open(schedule_type_limit_json) as json_file: data = json.load(json_file) ScheduleTypeLimit.from_dict(data) click.echo('Python re-serialization passed.') # if we made it to this point, report that the object is valid click.echo('Congratulations! Your ScheduleTypeLimit JSON is valid!') except Exception as e: _logger.exception('ScheduleTypeLimit validation failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def test_schedule_from_lib(): """Test the existence of schedule objects in the library.""" runner = CliRunner() result = runner.invoke(schedule_type_limit_by_id, ['Fractional']) assert result.exit_code == 0 sch_dict = json.loads(result.output) assert isinstance(ScheduleTypeLimit.from_dict(sch_dict), ScheduleTypeLimit) result = runner.invoke(schedule_by_id, ['Generic Office Occupancy']) assert result.exit_code == 0 sch_dict = json.loads(result.output) assert isinstance(ScheduleRuleset.from_dict(sch_dict), ScheduleRuleset) result = runner.invoke(program_type_by_id, ['Generic Office Program']) assert result.exit_code == 0 prog_dict = json.loads(result.output) assert isinstance(ProgramType.from_dict(prog_dict), ProgramType)
Returns: report: Reports, errors, warnings, etc. type_limit: A ScheduleTypeLimit object that can be assigned to any schedule object. """ ghenv.Component.Name = "HB Type Limit" ghenv.Component.NickName = 'TypeLimit' ghenv.Component.Message = '0.1.1' ghenv.Component.Category = 'HB-Energy' ghenv.Component.SubCategory = '2 :: Schedules' ghenv.Component.AdditionalHelpFromDocStrings = "0" try: # import the honeybee-energy dependencies from honeybee_energy.schedule.typelimit import ScheduleTypeLimit except ImportError as e: raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) try: # import ladybug_rhino dependencies from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # set default values numeric_type = 'Discrete' if discrete_ else 'Continuous' _unit_type_ = 'Dimensionless' if _unit_type_ is None else _unit_type_ # create the ScheduleTypeLimit type_limit = ScheduleTypeLimit(_name, low_limit_, up_limit_, numeric_type, _unit_type_)
'activity_level': ('Activity Level', 0, None, 'Continuous', 'ActivityLevel'), 'power': ('Power', None, None, 'Continuous', 'Power'), 'humidity': ('Humidity', 0, 100, 'Continuous', 'Percent'), 'angle': ('Angle', 0, 180, 'Continuous', 'Angle'), 'delta_temperature': ('Delta Temperature', None, None, 'Continuous', 'DeltaTemperature'), 'percent': ('Percent', 0, 100, 'Continuous', 'Percent') } # establish variables for the default schedule types used across the library # and auto-generate materials if they were not loaded from default.idf try: fractional = _idf_schedule_type_limits['Fractional'] except KeyError: fractional = ScheduleTypeLimit(*_default_prop['fractional']) _idf_schedule_type_limits['Fractional'] = fractional try: on_off = _idf_schedule_type_limits['On-Off'] except KeyError: on_off = ScheduleTypeLimit(*_default_prop['on_off']) _idf_schedule_type_limits['On-Off'] = on_off try: temperature = _idf_schedule_type_limits['Temperature'] except KeyError: temperature = ScheduleTypeLimit(*_default_prop['temperature']) _idf_schedule_type_limits['Temperature'] = temperature try:
"""Load all schedule type limits from the standards library.""" from honeybee_energy.config import folders from honeybee_energy.schedule.typelimit import ScheduleTypeLimit import os import json # empty dictionary to hold loaded schedule type limits _schedule_type_limits = {} # first load the honeybee defaults with open(folders.defaults_file) as json_file: default_data = json.load(json_file)['schedule_type_limits'] for stl_dict in default_data: stl_obj = ScheduleTypeLimit.from_dict(stl_dict) _schedule_type_limits[stl_dict['identifier']] = stl_obj _default_stls = set(list(_schedule_type_limits.keys())) # then load schedule types from the user-supplied files def check_and_add_schedule_type_limit(stl): """Check that a schedule type limit is not overwriting a default and add it.""" # we won't raise an error for this case as schedule types are fairly universal if stl.identifier not in _default_stls: _schedule_type_limits[stl.identifier] = stl for f in os.listdir(folders.schedule_lib): f_path = os.path.join(folders.schedule_lib, f) if os.path.isfile(f_path): if f_path.endswith('.idf'):
"""Load all schedule type limits from the IDF libraries.""" from honeybee_energy.schedule.typelimit import ScheduleTypeLimit import os # empty dictionaries to hold idf-loaded schedules and schedule types _idf_schedule_type_limits = {} # load schedule types from the default and user-supplied files cur_dir = os.path.dirname(__file__) schedule_lib = os.path.join(cur_dir, 'library', 'schedules') for f in os.listdir(schedule_lib): f_path = os.path.join(schedule_lib, f) if os.path.isfile(f_path) and f_path.endswith('.idf'): schedule_type_limits = ScheduleTypeLimit.extract_all_from_idf_file(f_path) for typ in schedule_type_limits: _idf_schedule_type_limits[typ.name] = typ