示例#1
0
    def test_create_from_building(self):
        b = self.building
        b_view = BuildingView.create_from_building(b)

        self.assertEqual(b_view.get_path("_id"), b.get_path("_id"))

        identic_keys = [
            "address", "building_number", "coordinates", "building_name",
            "l_b_id"
        ]
        for attr in identic_keys:
            self.assertEqual(b_view.get_path(attr),
                             b.get_path("merged." + attr))

        for i, floor in enumerate(b_view.get_path("floors")):
            self.assertIn("rooms", floor)
            self.assertIn("floor_name", floor)

            self.assertEqual(floor["floor_name"],
                             self.floor_dict[floor["f_id"]]["floor_name"])

            for room in floor["rooms"].values():
                self.assertTrue("polygon" not in room)
                self.assertTrue("capacity" in room)
                self.assertTrue("equipments" in room)
                self.assertTrue("room_name" in room)
                self.assertTrue("cat_name" in room)
                self.assertTrue("cat_id" not in room)

            self.assertIn("available_services", floor)

        available_services_1 = b_view["floors"][0]["available_services"]
        available_services_2 = b_view["floors"][1]["available_services"]

        self.assertIn("Bagno", available_services_1)
        self.assertIn("Ufficio", available_services_1)
        self.assertIn("Bagno", available_services_2)
        self.assertIn("Studio", available_services_2)
        self.assertIn("Ufficio", available_services_2)
   def test_create_from_building(self):
      b        = self.building
      b_view   = BuildingView.create_from_building(b)

      self.assertEqual(b_view.get_path("_id"), b.get_path("_id"))

      identic_keys = [
         "address", "building_number", "coordinates", "building_name", "l_b_id"
      ]
      for attr in identic_keys:
         self.assertEqual(b_view.get_path(attr), b.get_path("merged." + attr))

      for i, floor in enumerate(b_view.get_path("floors")):
         self.assertIn("rooms", floor)
         self.assertIn("floor_name", floor)

         self.assertEqual(
            floor["floor_name"],
            self.floor_dict[floor["f_id"]]["floor_name"]
         )

         for room in floor["rooms"].values():
            self.assertTrue("polygon" not in room)
            self.assertTrue("capacity" in room)
            self.assertTrue("equipments" in room)
            self.assertTrue("room_name" in room)
            self.assertTrue("cat_name" in room)
            self.assertTrue("cat_id" not in room)

         self.assertIn("available_services", floor)

      available_services_1 = b_view["floors"][0]["available_services"]
      available_services_2 = b_view["floors"][1]["available_services"]

      self.assertIn("Bagno", available_services_1)
      self.assertIn("Ufficio", available_services_1)
      self.assertIn("Bagno", available_services_2)
      self.assertIn("Studio", available_services_2)
      self.assertIn("Ufficio", available_services_2)
示例#3
0
   def perform_update(self):
      Logger.success("Delete old db")
      self._delete_old_db()

      Logger.success("Retrieving building view collection from persistence")
      buildings      = list(BuildingView.get_collection().find({'building_name':{'$exists':True}}))

      Logger.success("Creating new db")
      db_connection = sqlite3.connect( self.db_path() )

      sql_create = "CREATE TABLE lookup("
      sql_create += "id INTEGER PRIMARY KEY,"
      sql_create += "b_id VARCHAR(6),"
      sql_create += "building_name VARCHAR(100),"
      sql_create += "f_id VARCHAR(6),"
      sql_create += "floor_name VARCHAR(20),"
      sql_create += "r_id VARCHAR(10),"
      sql_create += "room_name VARCHAR(100))"
      db_connection.execute(sql_create)

      Logger.success("Begin transaction")

      index = 0
      for building in buildings:
         for f_id,floor in enumerate(building['floors']):
            for room_id in floor['rooms']:
               sql_insert = 'INSERT INTO lookup VALUES({},"{}","{}","{}","{}","{}","{}")'.format(
                  index,
                  building['_id'],
                  building['building_name'],
                  floor['f_id'],
                  floor['floor_name'],
                  room_id,
                  floor['rooms'][room_id]['room_name'])
               db_connection.execute(sql_insert)
               index +=1
      db_connection.commit()
      Logger.success("End transaction")
      Logger.success("{0} entries".format(index))
示例#4
0
    def perform_update(self):
        Logger.success("Delete old db")
        self._delete_old_db()

        Logger.success("Retrieving building view collection from persistence")
        buildings = list(BuildingView.get_collection().find(
            {'building_name': {
                '$exists': True
            }}))

        Logger.success("Creating new db")
        db_connection = sqlite3.connect(self.db_path())

        sql_create = "CREATE TABLE lookup("
        sql_create += "id INTEGER PRIMARY KEY,"
        sql_create += "b_id VARCHAR(6),"
        sql_create += "building_name VARCHAR(100),"
        sql_create += "f_id VARCHAR(6),"
        sql_create += "floor_name VARCHAR(20),"
        sql_create += "r_id VARCHAR(10),"
        sql_create += "room_name VARCHAR(100))"
        db_connection.execute(sql_create)

        Logger.success("Begin transaction")

        index = 0
        for building in buildings:
            for f_id, floor in enumerate(building['floors']):
                for room_id in floor['rooms']:
                    sql_insert = 'INSERT INTO lookup VALUES({},"{}","{}","{}","{}","{}","{}")'.format(
                        index, building['_id'], building['building_name'],
                        floor['f_id'], floor['floor_name'], room_id,
                        floor['rooms'][room_id]['room_name'])
                    db_connection.execute(sql_insert)
                    index += 1
        db_connection.commit()
        Logger.success("End transaction")
        Logger.success("{0} entries".format(index))
示例#5
0
def prepare_buildings_collection():
   app.buildings     = BuildingView.get_collection()
   app.protocol      = 'http'
   app.domain        = request.headers['Host']
示例#6
0
from model                 import RoomCategory,Building,BuildingView,AvailableService
from tasks                 import LookupTableTask
from model.odm             import ODMModel
from bson.json_util        import dumps
from flask                 import Flask, jsonify,abort,request,send_from_directory,render_template,Markup
from datetime              import datetime
from api.model             import RoomTimeTable


app                     = Flask(__name__,static_url_path='')
app.app_config          = ConfigManager('config/general.json')
app.persistence         = MongoDBPersistenceManager(app.app_config)
app.api_namespace       = '/api'
app.api_version         = 'v1.0'
ODMModel.set_pm( app.persistence )
BuildingView.setup_collection()
# radius used with GeoSpatial Query (meters)
app.radius              = 2000
app.maps_folder         = 'static-maps'
app.lookup_table_folder = 'static-table'

###########
# HELPERS #
###########

def url_for_endpoint(url_endpoint):
   return '/'.join( [app.api_namespace,app.api_version,url_endpoint] )+'/'

def filter_buildings_by_service(buildings,service,remove_floor_details=False):
  return [ b for b in buildings if len([ f for f in b['floors'] if service in f['available_services'] ])>0  ]
示例#7
0
 def __init__(self):
     self._config = ConfigManager("config/general.json")
     self._data_persistence = MongoDBPersistenceManager(self._config)
     ODMModel.set_pm(self._data_persistence)
     BuildingView.setup_collection()
示例#8
0
 def __init__(self):
    self._config            = ConfigManager("config/general.json")
    self._data_persistence  = MongoDBPersistenceManager(self._config)
    ODMModel.set_pm( self._data_persistence )
    BuildingView.setup_collection()