예제 #1
0
def dict_to_simulation(sim_dict, raise_exception=True):
    """Get a Python object of any Simulation object from a dictionary.

    Args:
        sim_dict: A dictionary of any Honeybee energy simulation 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 simulation object. Default: True.

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

    if sim_type == 'SimulationControl':
        return SimulationControl.from_dict(sim_dict)
    elif sim_type == 'RunPeriod':
        return RunPeriod.from_dict(sim_dict)
    elif sim_type == 'DaylightSavingTime':
        return DaylightSavingTime.from_dict(sim_dict)
    elif sim_type == 'ShadowCalculation':
        return ShadowCalculation.from_dict(sim_dict)
    elif sim_type == 'SizingParameter':
        return SizingParameter.from_dict(sim_dict)
    elif sim_type == 'SimulationOutput':
        return SimulationOutput.from_dict(sim_dict)
    elif sim_type == 'SimulationParameter':
        return SimulationParameter.from_dict(sim_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized energy Simulation type'.format(sim_type))
예제 #2
0
def test_simulation_control_dict_methods():
    """Test the to/from dict methods."""
    daylight_save = DaylightSavingTime(Date(3, 10), Date(11, 3))

    ds_dict = daylight_save.to_dict()
    new_daylight_save = DaylightSavingTime.from_dict(ds_dict)
    assert new_daylight_save == daylight_save
    assert ds_dict == new_daylight_save.to_dict()