def test_to_from_dict_methods(): """Test the to/from dict methods.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) pts_3 = (Point3D(0, 10, 3), Point3D(0, 20, 3), Point3D(10, 20, 3), Point3D(10, 10, 3)) pts_4 = (Point3D(10, 10, 3), Point3D(10, 20, 3), Point3D(20, 20, 3), Point3D(20, 10, 3)) room2d_1 = Room2D('Office1', Face3D(pts_1), 3) room2d_2 = Room2D('Office2', Face3D(pts_2), 3) room2d_3 = Room2D('Office3', Face3D(pts_3), 3) room2d_4 = Room2D('Office4', Face3D(pts_4), 3) story = Story('OfficeFloor', [room2d_1, room2d_2, room2d_3, room2d_4]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story.multiplier = 4 building = Building('OfficeBuilding', [story]) 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]) model = Model('NewDevelopment', [building], [tree_canopy]) model_dict = model.to_dict() new_model = Model.from_dict(model_dict) assert model_dict == new_model.to_dict()
def test_dict_to_object(): """Test the dict_to_object method with all geometry objects.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) pts_3 = (Point3D(0, 10, 3), Point3D(0, 20, 3), Point3D(10, 20, 3), Point3D(10, 10, 3)) pts_4 = (Point3D(10, 10, 3), Point3D(10, 20, 3), Point3D(20, 20, 3), Point3D(20, 10, 3)) room2d_1 = Room2D('Office1', Face3D(pts_1), 3) room2d_2 = Room2D('Office2', Face3D(pts_2), 3) room2d_3 = Room2D('Office3', Face3D(pts_3), 3) room2d_4 = Room2D('Office4', Face3D(pts_4), 3) story = Story('Office_Floor', [room2d_1, room2d_2, room2d_3, room2d_4]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story.multiplier = 4 building = Building('Office_Building', [story]) 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]) model = Model('New_Development', [building], [tree_canopy]) model_dict = model.to_dict() room_dict = room2d_1.to_dict() story_dict = story.to_dict() building_dict = building.to_dict() assert isinstance(dict_to_object(model_dict), Model) assert isinstance(dict_to_object(room_dict), Room2D) assert isinstance(dict_to_object(story_dict), Story) assert isinstance(dict_to_object(building_dict), Building)
def test_to_dict(): """Test the Model to_dict method.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) pts_3 = (Point3D(0, 10, 3), Point3D(0, 20, 3), Point3D(10, 20, 3), Point3D(10, 10, 3)) pts_4 = (Point3D(10, 10, 3), Point3D(10, 20, 3), Point3D(20, 20, 3), Point3D(20, 10, 3)) room2d_1 = Room2D('Office1', Face3D(pts_1), 3) room2d_2 = Room2D('Office2', Face3D(pts_2), 3) room2d_3 = Room2D('Office3', Face3D(pts_3), 3) room2d_4 = Room2D('Office4', Face3D(pts_4), 3) story = Story('OfficeFloor', [room2d_1, room2d_2, room2d_3, room2d_4]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story.multiplier = 4 building = Building('OfficeBuilding', [story]) 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]) model = Model('NewDevelopment', [building], [tree_canopy]) model.tolerance = 0.01 model.angle_tolerance = 1 model_dict = model.to_dict() assert model_dict['type'] == 'Model' assert model_dict['identifier'] == 'NewDevelopment' assert model_dict['display_name'] == 'NewDevelopment' assert 'buildings' in model_dict assert len(model_dict['buildings']) == 1 assert 'context_shades' in model_dict assert len(model_dict['context_shades']) == 1 assert 'tolerance' in model_dict assert model_dict['tolerance'] == 0.01 assert 'angle_tolerance' in model_dict assert model_dict['angle_tolerance'] == 1 assert 'properties' in model_dict assert model_dict['properties']['type'] == 'ModelProperties'
def model_complete_simple(directory): """Generate simple Model sample.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) room2d_1 = Room2D('Office 1', Face3D(pts_1), 3) room2d_2 = Room2D('Office 2', Face3D(pts_2), 3) story = Story('Office Floor', [room2d_1, room2d_2]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story.multiplier = 4 for room in story.room_2ds: room.properties.energy.program_type = office_program room.properties.energy.add_default_ideal_air() building = Building('Office Building', [story]) building.separate_top_bottom_floors() attic_program_type = plenum_program.duplicate() attic_program_type.name = 'Attic Space' schedule = ScheduleRuleset.from_constant_value('Always Dim', 1, schedule_types.fractional) lighting = Lighting('Attic Lighting', 3, schedule) attic_program_type.lighting = lighting building.unique_room_2ds[ -1].properties.energy.program_type = attic_program_type building.unique_room_2ds[ -2].properties.energy.program_type = attic_program_type constr_set = ConstructionSet('Attic Construction Set') polyiso = EnergyMaterial('PolyIso', 0.2, 0.03, 43, 1210, 'MediumRough') roof_constr = OpaqueConstruction('Attic Roof Construction', [roof_membrane, polyiso, wood]) floor_constr = OpaqueConstruction('Attic Floor Construction', [wood, insulation, wood]) constr_set.floor_set.interior_construction = floor_constr constr_set.roof_ceiling_set.exterior_construction = roof_constr building.unique_room_2ds[ -1].properties.energy.construction_set = constr_set building.unique_room_2ds[ -2].properties.energy.construction_set = constr_set 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_canopy.properties.energy.construction = bright_leaves tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5, schedule_types.fractional) tree_canopy.properties.energy.transmittance_schedule = tree_trans model = Model('New Development', [building], [tree_canopy]) model.north_angle = 15 dest_file = os.path.join(directory, 'model_complete_simple.json') with open(dest_file, 'w') as fp: json.dump(model.to_dict(), fp, indent=4)
def test_to_from_dict(): """Test the Model to_dict and from_dict method.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) room2d_1 = Room2D('Office1', Face3D(pts_1), 3) room2d_2 = Room2D('Office2', Face3D(pts_2), 3) story = Story('OfficeFloor', [room2d_1, room2d_2]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story.multiplier = 4 for room in story.room_2ds: room.properties.energy.program_type = office_program room.properties.energy.add_default_ideal_air() building = Building('OfficeBuilding', [story]) building.separate_top_bottom_floors() attic_program_type = plenum_program.duplicate() attic_program_type.identifier = 'Attic Space' schedule = ScheduleRuleset.from_constant_value('Always Dim', 1, schedule_types.fractional) lighting = Lighting('Attic Lighting', 3, schedule) attic_program_type.lighting = lighting building.unique_room_2ds[ -1].properties.energy.program_type = attic_program_type building.unique_room_2ds[ -2].properties.energy.program_type = attic_program_type constr_set = ConstructionSet('Attic Construction Set') polyiso = EnergyMaterial('PolyIso', 0.2, 0.03, 43, 1210, 'MediumRough') roof_constr = OpaqueConstruction('Attic Roof Construction', [roof_membrane, polyiso, wood]) floor_constr = OpaqueConstruction('Attic Floor Construction', [wood, insulation, wood]) constr_set.floor_set.interior_construction = floor_constr constr_set.roof_ceiling_set.exterior_construction = roof_constr building.unique_room_2ds[ -1].properties.energy.construction_set = constr_set building.unique_room_2ds[ -2].properties.energy.construction_set = constr_set 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_canopy.properties.energy.construction = bright_leaves tree_trans = ScheduleRuleset.from_constant_value('Tree Transmittance', 0.5, schedule_types.fractional) tree_canopy.properties.energy.transmittance_schedule = tree_trans model = Model('NewDevelopment', [building], [tree_canopy]) model_dict = model.to_dict() new_model = Model.from_dict(model_dict) assert model_dict == new_model.to_dict() assert polyiso in new_model.properties.energy.materials assert roof_constr in new_model.properties.energy.constructions assert floor_constr in new_model.properties.energy.constructions assert constr_set in new_model.properties.energy.construction_sets assert new_model.buildings[0].unique_room_2ds[ -1].properties.energy.construction_set == constr_set assert schedule in new_model.properties.energy.schedules assert attic_program_type in new_model.properties.energy.program_types assert new_model.buildings[0].unique_room_2ds[ -1].properties.energy.program_type == attic_program_type assert bright_leaves in new_model.properties.energy.constructions assert tree_trans in new_model.properties.energy.schedules assert new_model.context_shades[ 0].properties.energy.construction == bright_leaves assert new_model.context_shades[ 0].properties.energy.transmittance_schedule == tree_trans