Пример #1
0
def dict_to_construction(constr_dict, raise_exception=True):
    """Get a Python object of any Construction from a dictionary.

    Args:
        constr_dict: A dictionary of any Honeybee energy construction. 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 construction. Default: True.

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

    if constr_type == 'OpaqueConstruction':
        return OpaqueConstruction.from_dict(constr_dict)
    elif constr_type == 'WindowConstruction':
        return WindowConstruction.from_dict(constr_dict)
    elif constr_type == 'WindowConstructionShade':
        return WindowConstructionShade.from_dict(constr_dict)
    elif constr_type == 'ShadeConstruction':
        return ShadeConstruction.from_dict(constr_dict)
    elif constr_type == 'AirBoundaryConstruction':
        return AirBoundaryConstruction.from_dict(constr_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized energy Construction type'.format(
                constr_type))
Пример #2
0
def test_air_dict_methods():
    """Test the to/from dict methods."""
    night_flush = ScheduleRuleset.from_daily_values(
        'Night Flush', [1, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
                        0.5, 0.5, 0.5, 0.5, 0.5, 1, 1, 1])
    night_flush_constr = AirBoundaryConstruction('Night Flush Boundary', 0.4, night_flush)
    
    constr_dict = night_flush_constr.to_dict()
    new_constr = AirBoundaryConstruction.from_dict(constr_dict)
    assert night_flush_constr == new_constr
    assert constr_dict == new_constr.to_dict()
Пример #3
0
def dict_abridged_to_construction(constr_dict,
                                  materials,
                                  schedules,
                                  raise_exception=True):
    """Get a Python object of any Construction from an abridged dictionary.

    Args:
        constr_dict: An abridged dictionary of any Honeybee energy construction.
        materials: Dictionary of all material objects that might be used in the
            construction with the material identifiers as the keys.
        schedules: Dictionary of all schedule objects that might be used in the
            construction with the schedule identifiers as the keys.
        raise_exception: Boolean to note whether an excpetion should be raised
            if the object is not identified as a construction. Default: True.

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

    if constr_type == 'OpaqueConstructionAbridged':
        return OpaqueConstruction.from_dict_abridged(constr_dict, materials)
    elif constr_type == 'WindowConstructionAbridged':
        return WindowConstruction.from_dict_abridged(constr_dict, materials)
    elif constr_type == 'WindowConstructionShade':
        return WindowConstructionShade.from_dict_abridged(
            constr_dict, materials, schedules)
    elif constr_type == 'ShadeConstruction':
        return ShadeConstruction.from_dict(constr_dict)
    elif constr_type == 'AirBoundaryConstructionAbridged':
        return AirBoundaryConstruction.from_dict_abridged(
            constr_dict, schedules)
    elif constr_type == 'AirBoundaryConstruction':  # special case for ConstructionSet
        return AirBoundaryConstruction.from_dict(constr_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized energy Construction type'.format(
                constr_type))