def add_building(jwt): body = request.get_json() ownerID = body.get('ownerID') name = body.get('name') address = body.get('address') description = body.get('description') number_of_units = body.get('number_of_units') building_image = body.get('building_image') if not ('ownerID' in body and 'name' in body and 'address' in body and 'description' in body and 'number_of_units' in body): abort(422) try: new_building = Building(ownerID=ownerID, name=name, address=address, description=description, number_of_units=number_of_units, building_image=building_image) new_building.insert() return jsonify({ 'success': True, 'created': [new_building.show()], }) except Exception: abort(422)
def building(): conditioned_floor_area = 100 return Building(heat_mass_capacity=165000 * conditioned_floor_area, heat_transmission=200, maximum_cooling_power=float("-inf"), maximum_heating_power=float("inf"), initial_building_temperature=22, time_step_size=timedelta(hours=1), conditioned_floor_area=conditioned_floor_area)
def fully_damped_building(): conditioned_floor_area = 1 return Building(heat_mass_capacity=3600 * conditioned_floor_area, heat_transmission=0, maximum_cooling_power=-1, maximum_heating_power=1, initial_building_temperature=22, time_step_size=timedelta(hours=1), conditioned_floor_area=conditioned_floor_area)
def test_maximum_cooling_power_cannot_be_positive(): with pytest.raises(ValueError): conditioned_floor_area = 100 Building(heat_mass_capacity=165000 * conditioned_floor_area, heat_transmission=200, maximum_cooling_power=0.01, maximum_heating_power=float("inf"), initial_building_temperature=22, time_step_size=timedelta(hours=1), conditioned_floor_area=conditioned_floor_area)
def open_building(): building = Building(elevators=6, floors=20) # randomly add people into building for simulation people = 11 for person in range(0, people): location = randint(0, building.floor_count - 1) destination_options = [ x for x in range(0, building.floor_count) if x != location ] destination = choice(destination_options) building.add_person(location, destination) for person in building.people: building.deploy_elevator(person) time.sleep(.5)
def test_admin_delete_building(self): building = Building(address="Alyasmin", description="3 floors building", name="Tlal", number_of_units=9, ownerID=1234567890, building_image="https://dangerwordfilm.files.\ wordpress.com/2014/04/coming-soon.png") building.insert() building_id = building.id self.headers.update({'Authorization': 'Bearer ' + str(admin_token)}) res = self.client.delete(f'/buildings/\ {building_id}', headers=self.headers) data = json.loads(res.data) self.assertEqual(res.status_code, 200)
def add_building(): session_db = Session() flats = session_db.query(Flat).all() for flat in flats: query = session_db.query(Building)\ .filter(Building.address.in_([flat.street]))\ .filter(Building.latitude.in_([flat.latitude]))\ .filter(Building.longitude.in_([flat.longitude])) if not session_db.query(query.exists()).scalar(): try: building = Building( address=flat.street, longitude=flat.longitude, latitude=flat.latitude, count_floor=int(flat.floor[flat.floor.index('/')+1:]), year_build=flat.year_build ) session_db.add(building) except: print('ex') session_db.commit()
return "Social Sciences and Media Studies" elif (abbrev == "TD-E"): return "Theater/Dance East" elif (abbrev == "TD-W"): return "Theater/Dance West" elif (abbrev == "WEBB"): return "Webb Hall/Geological Sciences Building" else: return abbrev for building in scrape.getBuildingsOrdered(): name = building.getName().rstrip() if (len(Building.query.filter_by(name=name).all()) == 0): print("Adding:", building.name) b = Building(name=name, full_name=get_pretty_name(name).strip()) db.session.add(b) db.session.commit() for building in scrape.getBuildingsOrdered(): b = Building.query.filter_by(name=building.getName().rstrip()).first() for room in building.getRooms2(): if (not (room in b.rooms)): print("Adding:", room.number) r1 = Room(roomnumber=room.number.rstrip(), building_id=b.id) db.session.add(r1) db.session.commit()
def _create_building(sess, user_id, building_type): new_building = Building(user_id=user_id, building_type=building_type) sess.add(new_building) sess.flush() result = new_building.id return result
def get_building_with_specs(user_id, building_type, specs): return Building(user_id=user_id, building_type=building_type, storage_capacity=specs.get('initial_capacity', 0), production_capacity=specs.get('initial_production', 0))
def add_building(session, building_url): new_building = Building(url=building_url) session.add(new_building) return new_building
def construct_building(building_type, inventory): check_if_enough_inventory_for_buildings('construct', building_type, inventory) inventory['steel'] -= Building.TYPES_COST[building_type] return Building(building_type)
from filip.models.base import NgsiVersion header = InstanceHeader(cb_url=cb_url, iota_url=iota_url, ngsi_version=NgsiVersion.v2, service="example", service_path="/") my_floor = Floor(id="my-first-floor", header=header) # If we work with the often with the same header we can also set a # default header in the semantic_manager. If a class without a header # parameter is created it gets automatically assigned this default header. semantic_manager.set_default_header(header) my_building = Building(id="building1") # ## 2.2 Immutability # # These defining information of an instance are immutable and can not # be changed after the creation. # They are further bundled into an identifier object that is used as an # identity by the system: The InstanceIdentifier # We can have a look at this identifier, and see that the header was # correctly set: print("\u0332".join("Instance Identifier of my_building:")) print(my_building.get_identifier()) print("") # ## 2.3 Device Classes
def createBuilding(self, building): db.begin() try: Building(name=building.get("name")).save() if building.get("floors") is not None: for floor in building.get("floors"): Floor(level=floor.get("level"), buildingName=building.get("name")).save() if floor.get("waypoints") is not None: for waypoint in floor.get("waypoints"): if ("type" in waypoint): if (waypoint.get("type") == WAYPOINT_TYPES["ClassRoom"]): classRoom = ClassRoom( name=waypoint.get("name"), markerId=waypoint.get("markerId"), buildingName=building.get("name"), floorLevel=floor.get("level"), shapeType=waypoint.get("shapeType"), color=waypoint.get("color"), width=waypoint.get("width"), length=waypoint.get("length"), x=waypoint.get("x"), y=waypoint.get("y")).save() for schedule in waypoint["schedule"]: group = Group.nodes.get_or_none( name=schedule["group"], buildingName=building.get("name")) if group is None: group = Group( name=schedule["group"], buildingName=building.get( "name")).save() group.classes.connect( classRoom, { 'course': schedule["course"], 'dayOfWeek': schedule["dayOfWeek"], 'startTime': schedule["startTime"], 'finishTime': schedule["finishTime"] }) elif (waypoint.get("type") == WAYPOINT_TYPES["Office"]): office = Office( name=waypoint.get("name"), markerId=waypoint.get("markerId"), buildingName=building.get("name"), floorLevel=floor.get("level"), shapeType=waypoint.get("shapeType"), color=waypoint.get("color"), width=waypoint.get("width"), length=waypoint.get("length"), x=waypoint.get("x"), y=waypoint.get("y")).save() for prof in waypoint["professors"]: teacher = Teacher.nodes.get_or_none( name=prof, buildingName=building.get("name")) if teacher is None: teacher = Teacher( name=prof, buildingName=building.get( "name")).save() teacher.office.connect(office) elif (waypoint.get("type") == WAYPOINT_TYPES["Connector"]): Connector( name=waypoint.get("name"), markerId=waypoint.get("markerId"), buildingName=building.get("name"), floorLevel=floor.get("level"), shapeType=waypoint.get("shapeType"), color=waypoint.get("color"), width=waypoint.get("width"), length=waypoint.get("length"), x=waypoint.get("x"), y=waypoint.get("y")).save() else: Waypoint( name=waypoint.get("name"), markerId=waypoint.get("markerId"), buildingName=building.get("name"), floorLevel=floor.get("level"), shapeType=waypoint.get("shapeType"), color=waypoint.get("color"), width=waypoint.get("width"), length=waypoint.get("length"), x=waypoint.get("x"), y=waypoint.get("y")).save() else: Waypoint(name=waypoint.get("name"), markerId=waypoint.get("markerId"), buildingName=building.get("name"), floorLevel=floor.get("level"), shapeType=waypoint.get("shapeType"), color=waypoint.get("color"), width=waypoint.get("width"), length=waypoint.get("length"), x=waypoint.get("x"), y=waypoint.get("y")).save() if floor.get("hallways") is not None: for hallway in floor.get("hallways"): Hallway(name=hallway["name"], markerId=hallway["markerId"], buildingName=building.get("name"), floorLevel=floor.get("level"), shapeType=hallway["shapeType"], color=hallway["color"], width=hallway["width"], length=hallway["length"], x=hallway["x"], y=hallway["y"]).save() if building.get("floors") is not None: for floor in building.get("floors"): if floor.get("waypoints") is not None: for waypoint in floor.get("waypoints"): base = Waypoint.nodes.get( name=waypoint.get("name"), floorLevel=floor.get("level"), buildingName=building.get("name")) for neighbor in waypoint["neighbors"]: base.neighbors.connect( Waypoint.nodes.get( name=neighbor.get("name"), floorLevel=floor.get("level"), buildingName=building.get("name")), { 'direction': neighbor.get("direction") }) self.checkBuilding(building.get("name")) db.commit() return self.get(building.get("name")), 200 except Exception as e: db.rollback() return str(e), 500
async def addB(n, p): b = Building(name=n, parid=p) await b.save() return b
def generate(): buildings = [{ 'name': 'Unisinos', 'geom': 'POLYGON((-29.792974824703958 -51.158196330070496, -29.79401762517251 -51.15791738033295, -29.794669369947076 -51.1580353975296, -29.795432836998465 -51.1590975522995, -29.79611250398447 -51.15941941738129, -29.796624578801172 -51.1591511964798, -29.79744389305685 -51.157477498054504, -29.798402854629657 -51.156179308891296, -29.7985425084609 -51.15565359592438, -29.798346993042582 -51.15478456020355, -29.797350789502037 -51.153475642204285, -29.796959753625753 -51.152220368385315, -29.796820097585293 -51.15100800991058, -29.7963731969459 -51.15040719509125, -29.795814568339743 -51.150203347206116, -29.79454833195276 -51.15001022815704, -29.79401762517251 -51.15008533000946, -29.792686190511297 -51.1510294675827, -29.791550267216632 -51.15134060382843, -29.792974824703958 -51.158196330070496))', 'stroke_color': '000000', 'stroke_opacity': 0.8, 'stroke_weight': 1, 'fill_color': '000000', 'fill_opacity': 0.4, }, { 'name': 'Centro A', 'geom': 'POLYGON((-29.792974824703958 -51.158207058906555, -29.79248135283728 -51.15581452846527, -29.79398038248575 -51.155449748039246, -29.79402693584204 -51.154956221580505, -29.7943434980904 -51.15452706813812, -29.794883513732213 -51.154505610466, -29.795274557722546 -51.15480601787567, -29.795600426547136 -51.15540683269501, -29.795525942337928 -51.15628659725189, -29.795814568339743 -51.15741312503815, -29.796103193509005 -51.15764915943146, -29.797211134007373 -51.157456040382385, -29.797388030934346 -51.15757405757904, -29.796596647515113 -51.1591511964798, -29.796103193509005 -51.15940868854523, -29.79544214753631 -51.15910828113556, -29.794678680555958 -51.15802466869354, -29.79401762517251 -51.15790665149689, -29.792974824703958 -51.158207058906555))', 'stroke_color': '50514F', 'stroke_opacity': 0.8, 'stroke_weight': 1, 'fill_color': '50514F', 'fill_opacity': 0.4, }, { 'name': 'Centro B', 'geom': 'POLYGON((-29.792472042023952 -51.15577161312103, -29.792053054527678 -51.15361511707306, -29.795153520460268 -51.15261733531952, -29.79538628429624 -51.15381896495819, -29.795004551321096 -51.15452706813812, -29.794883513732213 -51.154441237449646, -29.79430625552492 -51.154462695121765, -29.793971071811892 -51.15492403507233, -29.793924518429623 -51.15539610385895, -29.792472042023952 -51.15577161312103))', 'stroke_color': 'F25F5C', 'stroke_opacity': 0.8, 'stroke_weight': 1, 'fill_color': 'F25F5C', 'fill_opacity': 0.4, }, { 'name': 'Centro C', 'geom': 'POLYGON((-29.792034432820458 -51.15358293056488, -29.795153520460268 -51.15256369113922, -29.794985930163108 -51.15159809589386, -29.794920756082853 -51.15005314350128, -29.79408279984098 -51.15006387233734, -29.793151729120222 -51.150729060173035, -29.792704812097245 -51.15100800991058, -29.79155957811571 -51.15134060382843, -29.792034432820458 -51.15358293056488))', 'color': '000000', 'stroke_color': 'FFE066', 'stroke_opacity': 0.8, 'stroke_weight': 1, 'fill_color': 'FFE066', 'fill_opacity': 0.4, }, { 'name': 'Centro D', 'geom': 'POLYGON((-29.795395594838418 -51.15364730358124, -29.797239065121897 -51.153250336647034, -29.79696906402153 -51.15226328372955, -29.796838718401958 -51.15110456943512, -29.796391817845727 -51.150439381599426, -29.79592629431048 -51.150246262550354, -29.794957998419612 -51.15006387233734, -29.79502317247561 -51.15157663822174, -29.795395594838418 -51.15364730358124))', 'stroke_color': '247BA0', 'stroke_opacity': 0.8, 'stroke_weight': 1, 'fill_color': '247BA0', 'fill_opacity': 0.4, }, { 'name': 'Centro E', 'geom': 'POLYGON((-29.795041793626687 -51.15453779697418, -29.795432836998465 -51.15382969379425, -29.795404905379733 -51.15367949008942, -29.79724837549168 -51.15329325199127, -29.79759285856436 -51.15385115146637, -29.798365613575065 -51.15483820438385, -29.7985425084609 -51.15565359592438, -29.79838423410409 -51.156200766563416, -29.797406651645325 -51.15750968456268, -29.797211134007373 -51.15740239620209, -29.79611250398447 -51.15760624408722, -29.795833189343526 -51.15737020969391, -29.79555387392288 -51.156232953071594, -29.79562835811129 -51.15539610385895, -29.79528386827512 -51.15475237369537, -29.795041793626687 -51.15453779697418))', 'stroke_color': '70C1B3', 'stroke_opacity': 0.8, 'stroke_weight': 1, 'fill_color': '70C1B3', 'fill_opacity': 0.4, }] for building in buildings: b = Building(building) db.session.add(b) db.session.commit()