Exemplo n.º 1
0
def load_soft_story_status(soft_filename):
    """Load buildings from soft story csv into database."""

    print("Soft-Story Buildings")

    with open(soft_filename) as csvfile:
        data = csv.reader(csvfile)

        for row in data:
            address, status, latitude, longitude, liquefaction = row

            soft_story = SoftStory(status=status, liquefaction=liquefaction)
            building = Building(address=address,
                                latitude=float(latitude),
                                longitude=float(longitude))
            soft_story.building = building

            liquefaction = liquefaction == "yes"
            print(address)
            print(liquefaction)

            # We need to add to the session or it won't ever be stored
            db.session.add(soft_story)
            print(soft_story)

    # Once we're done, we should commit our work
    db.session.commit()
Exemplo n.º 2
0
def load_buildings():
    """Create fake buildings and load into database."""

    # Delete all rows in table to avoid adding duplicates
    Building.query.delete()

    for i in range(0, 50):
        # Question, if I only want 5 buildings, how do I do that when I'm creating addresses? Random number between 1 and 5?
        building = Building(name=fake.company())

        # Add the building to the database
        db.session.add(building)

        # Commit all additions to database
        db.session.commit()
Exemplo n.º 3
0
def create_buildings(TIME_QUANT):
    r = lambda: 0.8 + random.random() * 0.4
    buildings = [
        Building(size=(8 * r() * (max_power / 20000),
                       10 * r() * (max_power / 20000), 2.5 * r()),
                 beta=15 * r(),
                 R_st=0.5 * r(),
                 sigma=0.03 * r(),
                 max_power=max_power,
                 description='wooden house',
                 time_quant=TIME_QUANT) for max_power in [6000, 12000, 18000]
    ]

    print('sum of nominal heaters powers (losses at -30C), kW: ',
          sum([b.get_loss_P() * (20 - (-30)) for b in buildings]) / 1000)
    return buildings
Exemplo n.º 4
0
def load_buildings():
    """Load buildings from u.buildings into database."""

    # Delete all rows in table to avoid adding duplicates
    Building.query.delete()

    for row in open("data/u.buildings"):
        row = row.rstrip()

        building_id, name = row.split("|")

        building = Building(building_id=building_id,
                            name=name)

        # Add the building to the database
        db.session.add(building)

        # Commit all additions to database
        db.session.commit()
Exemplo n.º 5
0
    def new_building(self, e):
        self.glwindow.buildings.append(Building())
        self.glwindow.update()

        index = self.stackedBuilding.count()
        new = BuildingControl(index, self.glwindow, self)
        self.stackedBuilding.addWidget(new)
        self.building_selector.addItem('build_' + str(self.building_count))
        self.building_count += 1

        self.building_selector.setCurrentIndex(index)
        self.stackedBuilding.setCurrentIndex(index)

        self.stackedBuilding.widget(index).building_delete.connect(
            self.on_building_delete)
        self.stackedBuilding.widget(index).building_modified.connect(
            self.on_modified)
        self.glwindow.active_building = index
        self.glwindow.active_source = -1
Exemplo n.º 6
0
    def find_building_to_update(self, building_dict):
        """
      Finds on database or create a Buiding object to be updated with information
      contained by building_dict

      Arguments:
      - building_dict: a dictionary containing the new values to be inserted
      on the building.

      Returns a Building object.

      Finds a building on database using b_id as identifier, otherwise looks for a
      building using l_b_id. If none of the above succeeds, creates a new building
      object to be inserted on database.
      """
        b_id = building_dict.get("b_id", "")

        return (Building.find(b_id)
                or Building.find_by_field("merged.l_b_id", b_id)
                or Building({"_id": b_id}))
Exemplo n.º 7
0
def load_Building():
    """Load building names into database."""

    print "Buildings"

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    Building.query.delete()

    # Read building file and insert data
    for row in open("seed_data/building"):
        row = row.rstrip()
        bldg_id, bldg_name = row.split(",")

        building = Building(bldg_id=bldg_id, bldg_name=bldg_name)

        # We need to add to the session or it won't ever be stored
        db.session.add(building)

    # Once we're done, we should commit our work
    db.session.commit()
Exemplo n.º 8
0
def load_tall_building(tall_filename):
    """Load buildings from tall buildings csv into database."""

    print("Tall Buildings")

    with open(tall_filename) as csvfile:
        data = csv.reader(csvfile)

    for i, row in enumerate(open(tall_filename)):
        row = row.rstrip()
        name, address, at_risk, liquefaction = row.split(",")

        at_risk = at_risk == "yes"

        geolocator = GoogleV3(
            api_key='AIzaSyDeNiHduiEBvQI2CnzC1dis32FDktKV4eA')
        location = geolocator.geocode(address, timeout=180)
        if location == None:
            continue

        latitude = float(location.latitude)
        longitude = float(location.longitude)

        tall_building = TallBuilding(name=name,
                                     at_risk=at_risk,
                                     liquefaction=liquefaction)
        building = Building(address=address,
                            latitude=latitude,
                            longitude=longitude)
        tall_building.building = building

        # We need to add to the session or it won't ever be stored
        db.session.add(tall_building)
        print(tall_building)

    # Once we're done, we should commit our work
    db.session.commit()
Exemplo n.º 9
0
 def post(self):
     building = Building(**request.json)
     session.add(building)
     session.commit()
     return building.id
Exemplo n.º 10
0
    def setUp(self):
        # Usato come parametro nelle chiamate
        self.db_building = {
            "dxf": {
                "floors": [
                    {
                        "f_id":
                        "-0.5",
                        "rooms": {},
                        "unidentified_rooms": [
                            {  # Room 1, matcha con easyroom
                                "texts": [{
                                    "text": "StanzaMatchata"
                                }, {
                                    "text": "R003"
                                }, {
                                    "text": "AUL01"
                                }]
                            },
                            {  # Room 2
                                "texts": [{
                                    "text": "StanzaNonMatchata"
                                }, {
                                    "text": "R00p3"
                                }, {
                                    "text": "WC01"
                                }]
                            },
                            {  # Room 3, matcha con edilizia
                                "texts": [{
                                    "text": "AUL03"
                                }, {
                                    "text": "StanzaMatchata"
                                }, {
                                    "text": "R002"
                                }]
                            }
                        ]
                    },
                    {
                        "f_id":
                        "0.5",
                        "rooms": {},
                        "unidentified_rooms": [
                            {  # Room 1, matcha con easyroom
                                "texts": [{
                                    "text": "StanzaMatchata"
                                }, {
                                    "text": "R023"
                                }, {
                                    "text": "AUL01"
                                }]
                            },
                            {  # Room 2
                                "texts": [{
                                    "text": "StanzaNonMatchata"
                                }, {
                                    "text": "R00p3"
                                }, {
                                    "text": "WC01"
                                }]
                            },
                            {  # Room 3, matcha con edilizia
                                "texts": [{
                                    "text": "AUL03"
                                }, {
                                    "text": "StanzaMatchata"
                                }, {
                                    "text": "R022"
                                }]
                            }
                        ]
                    },
                ]
            },
            "edilizia": {
                "floors": [{
                    "f_id": "0",
                    "rooms": {
                        "PippoPelato": {},
                        "R002": {},
                        "PippoPelato2": {}
                    }
                }, {
                    "f_id": "0.5",
                    "rooms": {
                        "PippoPelato": {},
                        "PippoPelato2": {},
                        "R022": {}
                    }
                }]
            },
            "easyroom": {
                "floors": [{
                    "f_id": "0",
                    "rooms": {
                        "PippoSdentato": {},
                        "PippoSdentato2": {},
                        "R003": {}
                    }
                }, {
                    "f_id": "1",
                    "rooms": {
                        "PippoSdentato": {},
                        "PippoSdentato2": {},
                        "R023": {}
                    }
                }]
            }
        }

        # usato come parametro di comparazione per il successo dell'esecuzione
        # rappresenta ciò che ce ne aspettiamo alla fine dell'update su entrambe
        # sorgenti dati: edilizia e easyroom
        self.final_rooms = {
            # Room 1, matcha con easyroom
            "R003": {
                "texts": [{
                    "text": "StanzaMatchata"
                }, {
                    "text": "R003"
                }, {
                    "text": "AUL01"
                }]
            },
            # Room 3, matcha con edilizia
            "R002": {
                "texts": [{
                    "text": "AUL03"
                }, {
                    "text": "StanzaMatchata"
                }, {
                    "text": "R002"
                }]
            },
            # Room 1, matcha con easyroom
            "R023": {
                "texts": [{
                    "text": "StanzaMatchata"
                }, {
                    "text": "R023"
                }, {
                    "text": "AUL01"
                }]
            },
            # Room 3, matcha con edilizia
            "R022": {
                "texts": [{
                    "text": "AUL03"
                }, {
                    "text": "StanzaMatchata"
                }, {
                    "text": "R022"
                }]
            }
        }
        self.building = Building(self.db_building)
Exemplo n.º 11
0
    def setUp(self):
        config_file = "config/floor_inference.json"
        with open(config_file) as cf:
            self.floor_dict = json.load(cf)

        self.db_building = {
            "_id": "33110",
            "merged": {
                "floors": [
                    {
                        "rooms": {
                            "S015": {
                                "capacity": "20",
                                "equipments": [],
                                "polygon": {},
                                "room_name": "Aula Gamma",
                                "accessibility": "",
                                "cat_id": "AUL03"
                            }
                        },
                        "f_id":
                        "-05",
                        "walls": [],
                        "windows": [],
                        "unidentified_rooms": [{
                            "cat_id": "WC01",
                            "polygon": {}
                        }, {
                            "cat_id": "WC01",
                            "polygon": {}
                        }, {
                            "cat_id": "UFF01",
                            "polygon": {}
                        }]
                    },
                    {
                        "rooms": {
                            "R057": {
                                "capacity": "128",
                                "equipments": [],
                                "polygon": {},
                                "room_name": "Aula Alfa",
                                "accessibility": "",
                                "cat_id": "AUL01"
                            },
                            "R107": {
                                "capacity": "12",
                                "equipments": [],
                                "polygon": {},
                                "room_name": "Aula 6",
                                "accessibility": "",
                                "cat_id": "AUL01"
                            },
                            "R013": {
                                "capacity": "26",
                                "equipments": [],
                                "polygon": {},
                                "room_name": "Aula Delta",
                                "accessibility": "",
                                "cat_id": "AUL03"
                            },
                        },
                        "f_id":
                        "03",
                        "walls": [],
                        "windows": [],
                        "unidentified_rooms": [{
                            "cat_id": "WC01",
                            "polygon": {}
                        }, {
                            "cat_id": "STD01",
                            "polygon": {}
                        }, {
                            "cat_id": "UFF01",
                            "polygon": {}
                        }]
                    },
                ],
                "building_name":
                "",
                "coordinates": {
                    "coordinates": [9.214915, 45.454309],
                    "type": "Point"
                },
                "l_b_id":
                "5830",
                "address":
                "Via Comelico, 39, Milano",
                "building_number":
                "1"
            },
            "edilizia": {
                "lat":
                "45.454309",
                "lon":
                "9.214915",
                "updated_at":
                "",
                "floors": [{
                    "rooms": {
                        "S015": {
                            "capacity": "20",
                            "room_name": "Aula Gamma",
                            "l_floor": "S",
                            "cat_id": "AUL03"
                        }
                    },
                    "f_id": "-05"
                }, {
                    "rooms": {
                        "R057": {
                            "capacity": "128",
                            "room_name": "Aula Alfa",
                            "l_floor": "R",
                            "cat_id": "AUL01"
                        },
                        "R008": {
                            "capacity": "208",
                            "room_name": "Aula Sigma e Omega",
                            "l_floor": "R",
                            "cat_id": "AUL03"
                        },
                        "R013": {
                            "capacity": "26",
                            "room_name": "Aula Delta",
                            "l_floor": "R",
                            "cat_id": "AUL03"
                        },
                        "R100": {
                            "capacity": "12",
                            "room_name": "Aula 4",
                            "l_floor": "R",
                            "cat_id": "AUL01"
                        },
                        "R048": {
                            "capacity": "192",
                            "room_name": "Aula Beta",
                            "l_floor": "R",
                            "cat_id": "AUL01"
                        },
                        "R099": {
                            "capacity": "16",
                            "room_name": "Aula 5",
                            "l_floor": "R",
                            "cat_id": "AUL01"
                        },
                        "R107": {
                            "capacity": "12",
                            "room_name": "Aula 6",
                            "l_floor": "R",
                            "cat_id": "AUL01"
                        }
                    },
                    "f_id": "03"
                }],
                "b_id":
                "33110",
                "l_b_id":
                "5830",
                "address":
                "Milano - Via Comelico 39_Ed 1"
            }
        }

        self.building = Building(self.db_building)
Exemplo n.º 12
0
                        self.buildings[active].move('forward')
                        self.building_z_changed.emit(self.buildings[active].position[2])
                    elif key == Qt.Key_Down:
                        self.buildings[active].move('back')
                        self.building_z_changed.emit(self.buildings[active].position[2])
                    elif key == Qt.Key_Left:
                        self.buildings[active].move('left')
                        self.building_x_changed.emit(self.buildings[active].position[0])
                    elif key == Qt.Key_Right:
                        self.buildings[active].move('right')
                        self.building_x_changed.emit(self.buildings[active].position[0])


if __name__ == '__main__':
    glutInit()
    displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
    glutInitDisplayMode(displayMode)

    app = QApplication(sys.argv)

    building = Building(floors=5, rooms=5, floor_thickness=1, room_length=12, room_width=6, room_height=5, wall_thickness=0.2)
    glwindow = GLWindow()
    source = Source()
    glwindow.sources.append(source)
    # source2 = Source(pos_x=10)
    # glwindow.sources.append(source2)

    glwindow.setGeometry(200, 200, 960, 680)
    glwindow.show()
    sys.exit(app.exec_())
Exemplo n.º 13
0
    def test_building_creation(self):
        b = Building({"_id": 123, "height": "everest"})

        self.assertEqual(b.attr("b_id"), "123")
        self.assertEqual(b.attr("_id"), "123")
        self.assertEqual(b.attr("height"), "everest")
Exemplo n.º 14
0
def create_building(name, descr):
    building = Building(name, descr)
    session.add(building)
    session.commit()