Пример #1
0
def test_to_dict():
    """Test the Building to_dict method with energy properties."""
    tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6,
                                                   Plane(o=Point3D(5, -10, 6)))
    tree_canopy_geo2 = Face3D.from_regular_polygon(
        6, 2, Plane(o=Point3D(-5, -10, 3)))
    tree_canopy = ContextShade('TreeCanopy',
                               [tree_canopy_geo1, tree_canopy_geo2])

    sd = tree_canopy.to_dict()
    assert 'properties' in sd
    assert sd['properties']['type'] == 'ContextShadeProperties'
    assert 'energy' in sd['properties']
    assert sd['properties']['energy']['type'] == 'ContextShadeEnergyProperties'
    assert 'construction' not in sd['properties']['energy'] or \
        sd['properties']['energy']['construction'] is None

    bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True)
    tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5,
                                                     schedule_types.fractional)
    tree_canopy.properties.energy.construction = bright_leaves
    tree_canopy.properties.energy.transmittance_schedule = tree_trans

    sd = tree_canopy.to_dict()
    assert sd['properties']['energy']['construction'] is not None
    assert sd['properties']['energy']['transmittance_schedule'] is not None
Пример #2
0
def test_to_from_dict():
    """Test the to/from dict of ContextShade objects."""
    tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6)))
    tree_canopy_geo2 = Face3D.from_regular_polygon(6, 2, Plane(o=Point3D(-5, -10, 3)))
    tree_canopy = ContextShade('Tree_Canopy', [tree_canopy_geo1, tree_canopy_geo2])

    context_dict = tree_canopy.to_dict()
    new_context = ContextShade.from_dict(context_dict)
    assert isinstance(new_context, ContextShade)
    assert new_context.to_dict() == context_dict
Пример #3
0
def test_to_dict():
    """Test the ContextShade to_dict method."""
    tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6)))
    tree_canopy_geo2 = Face3D.from_regular_polygon(6, 2, Plane(o=Point3D(-5, -10, 3)))
    tree_canopy = ContextShade('Tree_Canopy', [tree_canopy_geo1, tree_canopy_geo2])

    sd = tree_canopy.to_dict()
    assert sd['type'] == 'ContextShade'
    assert sd['identifier'] == 'Tree_Canopy'
    assert sd['display_name'] == 'Tree_Canopy'
    assert len(sd['geometry']) == 2
Пример #4
0
def context_shade_two_tree_canopy(directory):
    """Generate the context_shade_two_tree_canopy sample."""
    tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6,
                                                   Plane(o=Point3D(5, -10, 6)))
    tree_canopy_geo2 = Face3D.from_regular_polygon(
        6, 2, Plane(o=Point3D(-5, -10, 3)))
    tree_canopy = ContextShade('Tree Canopy',
                               [tree_canopy_geo1, tree_canopy_geo2])

    bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True)
    tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5,
                                                     schedule_types.fractional)

    tree_canopy.properties.energy.construction = bright_leaves
    tree_canopy.properties.energy.transmittance_schedule = tree_trans

    dest_file = os.path.join(directory, 'context_shade_two_tree_canopy.json')
    with open(dest_file, 'w') as fp:
        json.dump(tree_canopy.to_dict(True), fp, indent=4)
Пример #5
0
def test_from_dict():
    """Test the Story from_dict method with energy properties."""
    tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6,
                                                   Plane(o=Point3D(5, -10, 6)))
    tree_canopy_geo2 = Face3D.from_regular_polygon(
        6, 2, Plane(o=Point3D(-5, -10, 3)))
    tree_canopy = ContextShade('TreeCanopy',
                               [tree_canopy_geo1, tree_canopy_geo2])

    bright_leaves = ShadeConstruction('Bright Light Leaves', 0.5, 0.5, True)
    tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5,
                                                     schedule_types.fractional)
    tree_canopy.properties.energy.construction = bright_leaves
    tree_canopy.properties.energy.transmittance_schedule = tree_trans

    sd = tree_canopy.to_dict()
    new_shd = ContextShade.from_dict(sd)
    assert new_shd.properties.energy.construction == bright_leaves
    assert new_shd.properties.energy.transmittance_schedule == tree_trans
    assert new_shd.to_dict() == sd