Ejemplo n.º 1
0
def validate_construction_set(construction_set_json):
    """Validate all properties of a ConstructionSet or ConstructionSetAbridged JSON.

    \b
    Args:
        construction_set_json: Full path to a ConstructionSet or ConstructionSetAbridged
            JSON file.
    """
    try:
        # first check the JSON against the OpenAPI specification
        with open(construction_set_json) as json_file:
            data = json.load(json_file)
        if data['type'] == 'ConstructionSet':
            click.echo('Validating ConstructionSet JSON ...')
            schema_constructionset.ConstructionSet.parse_file(construction_set_json)
            click.echo('Pydantic validation passed.')
            ConstructionSet.from_dict(data)
            click.echo('Python re-serialization passed.')
        else:  # assume it's a ConstructionSetAbridged schema
            click.echo('Validating ConstructionSetAbridged JSON ...')
            schema_constructionset.ConstructionSetAbridged.parse_file(
                construction_set_json)
            click.echo('Pydantic validation passed.')
        # if we made it to this point, report that the object is valid
        click.echo('Congratulations! Your Program JSON is valid!')
    except Exception as e:
        _logger.exception('ConstructionSet validation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Ejemplo n.º 2
0
    def from_dict(cls, data, host):
        """Create Room2DEnergyProperties from a dictionary.

        Note that the dictionary must be a non-abridged version for this
        classmethod to work.

        Args:
            data: A dictionary representation of Room2DEnergyProperties.
            host: A Room2D object that hosts these properties.
        """
        assert data['type'] == 'Room2DEnergyProperties', \
            'Expected Room2DEnergyProperties. Got {}.'.format(data['type'])

        new_prop = cls(host)
        if 'construction_set' in data and data['construction_set'] is not None:
            new_prop.construction_set = \
                ConstructionSet.from_dict(data['construction_set'])
        if 'program_type' in data and data['program_type'] is not None:
            new_prop.program_type = ProgramType.from_dict(data['program_type'])
        if 'hvac' in data and data['hvac'] is not None:
            hvac_class = HVAC_TYPES_DICT[data['hvac']['type']]
            new_prop.hvac = hvac_class.from_dict(data['hvac'])
        cls._deserialize_window_vent(new_prop, data)

        return new_prop
Ejemplo n.º 3
0
def test_constructionset_dict_methods():
    """Test the to/from dict methods."""
    insulated_set = ConstructionSet('Insulated Set')
    clear_glass = EnergyWindowMaterialGlazing(
        'Clear Glass', 0.005715, 0.770675, 0.07, 0.8836, 0.0804,
        0, 0.84, 0.84, 1.0)
    gap = EnergyWindowMaterialGas('air gap', thickness=0.0127)
    triple_clear = WindowConstruction(
        'Triple Clear Window', [clear_glass, gap, clear_glass, gap, clear_glass])

    insulated_set.aperture_set.window_construction = triple_clear
    constr_dict = insulated_set.to_dict()

    assert constr_dict['wall_set']['exterior_construction'] is None
    assert constr_dict['wall_set']['interior_construction'] is None
    assert constr_dict['wall_set']['ground_construction'] is None
    assert constr_dict['floor_set']['exterior_construction'] is None
    assert constr_dict['floor_set']['interior_construction'] is None
    assert constr_dict['floor_set']['ground_construction'] is None
    assert constr_dict['roof_ceiling_set']['exterior_construction'] is None
    assert constr_dict['roof_ceiling_set']['interior_construction'] is None
    assert constr_dict['roof_ceiling_set']['ground_construction'] is None
    assert constr_dict['aperture_set']['window_construction'] is not None
    assert constr_dict['aperture_set']['interior_construction'] is None
    assert constr_dict['aperture_set']['skylight_construction'] is None
    assert constr_dict['aperture_set']['operable_construction'] is None
    assert constr_dict['door_set']['exterior_construction'] is None
    assert constr_dict['door_set']['interior_construction'] is None
    assert constr_dict['door_set']['exterior_glass_construction'] is None
    assert constr_dict['door_set']['interior_glass_construction'] is None
    assert constr_dict['door_set']['overhead_construction'] is None
    assert constr_dict['shade_construction'] is None

    new_constr = ConstructionSet.from_dict(constr_dict)
    assert constr_dict == new_constr.to_dict()
Ejemplo n.º 4
0
def load_construction_set_object(cset_dict):
    """Load a construction set object from a dictionary and add it to the lib dict."""
    try:
        if cset_dict['type'] == 'ConstructionSetAbridged':
            cset = ConstructionSet.from_dict_abridged(cset_dict, _all_constructions)
        else:
            cset = ConstructionSet.from_dict(cset_dict)
        cset.lock()
        assert cset_dict['identifier'] not in _default_sets, 'Cannot overwrite ' \
            'default construction set "{}".'.format(cset_dict['identifier'])
        _construction_sets[cset_dict['identifier']] = cset
    except (TypeError, KeyError, ValueError):
        pass  # not a Honeybee ConstructionSet JSON; possibly a comment
Ejemplo n.º 5
0
    def from_dict(cls, data, host):
        """Create BuildingEnergyProperties from a dictionary.

        Note that the dictionary must be a non-abridged version for this
        classmethod to work.

        Args:
            data: A dictionary representation of BuildingEnergyProperties.
            host: A Building object that hosts these properties.
        """
        assert data['type'] == 'BuildingEnergyProperties', \
            'Expected BuildingEnergyProperties. Got {}.'.format(data['type'])

        new_prop = cls(host)
        if 'construction_set' in data and data['construction_set'] is not None:
            new_prop.construction_set = \
                ConstructionSet.from_dict(data['construction_set'])

        return new_prop
Ejemplo n.º 6
0
def dict_to_object(honeybee_energy_dict, raise_exception=True):
    """Re-serialize a dictionary of almost any object within honeybee_energy.

    This includes any Material, Construction, ConstructionSet, Schedule, Load,
    ProgramType, or Simulation object.

    Args:
        honeybee_energy_dict: A dictionary of any Honeybee energy object. Note
            that this should be a non-abridged dictionary to be valid.
        raise_exception: Boolean to note whether an excpetion should be raised
            if the object is not identified as a part of honeybee_energy.
            Default: True.

    Returns:
        A Python object derived from the input honeybee_energy_dict.
    """
    try:  # get the type key from the dictionary
        obj_type = honeybee_energy_dict['type']
    except KeyError:
        raise ValueError(
            'Honeybee_energy dictionary lacks required "type" key.')

    if obj_type == 'ProgramType':
        return ProgramType.from_dict(honeybee_energy_dict)
    elif obj_type == 'ConstructionSet':
        return ConstructionSet.from_dict(honeybee_energy_dict)
    elif obj_type in SCHEDULE_TYPES:
        return dict_to_schedule(honeybee_energy_dict)
    elif obj_type in CONSTRUCTION_TYPES:
        return dict_to_construction(honeybee_energy_dict)
    elif obj_type in MATERIAL_TYPES:
        return dict_to_material(honeybee_energy_dict)
    elif obj_type in LOAD_TYPES:
        return dict_to_load(honeybee_energy_dict)
    elif obj_type in SIMULATION_TYPES:
        return dict_to_simulation(honeybee_energy_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized honeybee energy object'.format(obj_type))
Ejemplo n.º 7
0
def test_construction_from_lib():
    """Test the existence of construction objects in the library."""
    runner = CliRunner()

    result = runner.invoke(opaque_material_by_id, ['Generic Gypsum Board'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(EnergyMaterial.from_dict(mat_dict), EnergyMaterial)

    result = runner.invoke(window_material_by_id, ['Generic Low-e Glass'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(EnergyWindowMaterialGlazing.from_dict(mat_dict),
                      EnergyWindowMaterialGlazing)

    result = runner.invoke(opaque_construction_by_id,
                           ['Generic Exterior Wall'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(OpaqueConstruction.from_dict(con_dict),
                      OpaqueConstruction)

    result = runner.invoke(window_construction_by_id, ['Generic Double Pane'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(WindowConstruction.from_dict(con_dict),
                      WindowConstruction)

    result = runner.invoke(shade_construction_by_id, ['Generic Context'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(ShadeConstruction.from_dict(mat_dict), ShadeConstruction)

    result = runner.invoke(construction_set_by_id,
                           ['Default Generic Construction Set'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(ConstructionSet.from_dict(con_dict), ConstructionSet)
Ejemplo n.º 8
0
def test_constructions_from_lib():
    """Test the existence of construction objects in the library."""
    runner = CliRunner()

    result = runner.invoke(materials_by_id,
                           ['Generic Gypsum Board', 'Generic Low-e Glass'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(EnergyMaterial.from_dict(mat_dict[0]), EnergyMaterial)

    result = runner.invoke(
        constructions_by_id,
        ['Generic Exterior Wall', 'Generic Double Pane', 'Generic Context'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(OpaqueConstruction.from_dict(con_dict[0]),
                      OpaqueConstruction)

    result = runner.invoke(construction_sets_by_id,
                           ['Default Generic Construction Set'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(ConstructionSet.from_dict(con_dict[0]), ConstructionSet)