Пример #1
0
 def setUp(self):
     self._pm = MongoDBPersistenceManager({
         "db": {
             "url": "localhost",
             "port": 27017,
             "db_name": "campus_unimi_test"
         }
     })
     ODMModel.set_pm(self._pm)
     self._pm.clean_collection("building")
class ODMBuildingModelTest(unittest.TestCase):

   def setUp(self):
      self._pm = MongoDBPersistenceManager({
         "db": {
               "url"    : "localhost",
               "port"   : 27017,
               "db_name" : "campus_unimi_test"
            }
      })
      ODMModel.set_pm(self._pm)
      self._pm.clean_collection("building")


   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")

   def test_building_find(self):
      b = Building.find(12)
      self.assertEqual(b, None)

      self._pm.save("building", { "_id" : "123", "pluto" : 333 } )

      b = Building.find(123)
      self.assertEqual(b.attr("pluto"), 333)

      self.assertEqual( b.is_changed() , False )

   def test_find_if_building_not_exists(self):
      b = Building.find(12)
      self.assertEqual(b, None)

      b = Building.find_or_create_by_id(12)
      self.assertEqual(b.is_changed(), True )
      self.assertEqual(b.attr("_id"), "12" )
      self.assertEqual(b.attr("b_id"), "12" )

   def test_find_and_update(self):
      b1 = Building.find_or_create_by_id(12)
      b1.attr("pippo", "paperino")
      b1.save()

      b2 = Building.find_or_create_by_id(12)

      self.assertEqual(b1, b2)
Пример #3
0
class ODMBuildingModelTest(unittest.TestCase):
    def setUp(self):
        self._pm = MongoDBPersistenceManager({
            "db": {
                "url": "localhost",
                "port": 27017,
                "db_name": "campus_unimi_test"
            }
        })
        ODMModel.set_pm(self._pm)
        self._pm.clean_collection("building")

    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")

    def test_building_find(self):
        b = Building.find(12)
        self.assertEqual(b, None)

        self._pm.save("building", {"_id": "123", "pluto": 333})

        b = Building.find(123)
        self.assertEqual(b.attr("pluto"), 333)

        self.assertEqual(b.is_changed(), False)

    def test_find_if_building_not_exists(self):
        b = Building.find(12)
        self.assertEqual(b, None)

        b = Building.find_or_create_by_id(12)
        self.assertEqual(b.is_changed(), True)
        self.assertEqual(b.attr("_id"), "12")
        self.assertEqual(b.attr("b_id"), "12")

    def test_find_and_update(self):
        b1 = Building.find_or_create_by_id(12)
        b1.attr("pippo", "paperino")
        b1.save()

        b2 = Building.find_or_create_by_id(12)

        self.assertEqual(b1, b2)
 def setUp(self):
    self._pm = MongoDBPersistenceManager({
       "db": {
             "url"    : "localhost",
             "port"   : 27017,
             "db_name" : "campus_unimi_test"
          }
    })
    ODMModel.set_pm(self._pm)
    self._pm.clean_collection("building")
   def setUp(self):
      pm = MongoDBPersistenceManager({
         "db": {
               "url"     : "localhost",
               "port"    : 27017,
               "db_name" : "campus_unimi_test"
            }
      })
      self.old_pm = getattr(ODMModel, "_pm", None)
      ODMModel.set_pm(pm)

      self.db_building  = {
          "_id" : "21030",
          "dxf" : {
            "l_b_id" : "5703",
            "floors" : [
               { "f_id" : "-05", "rooms": {}, "unidentified_rooms": [] },
            ]
          },
          "edilizia" : {
              "l_b_id"     : "5703",
              "b_id"       : "21030",
              "lat"        : "",
              "lon"        : "",
              "address"    : ""
          },
          "easyroom" : {
              "b_id"       : "21030",
              "address"    : "Via Celoria"
          }
      }

      pm.clean_collection("building")
      self.edil_up      = EdiliziaDataUpdater()
      self.easy_up      = EasyroomDataUpdater()
      self.dxf_updater  = DXFDataUpdater()
Пример #6
0
 def test_clean(self):
     pm = MongoDBPersistenceManager({
         "db": {
             "url": "localhost",
             "port": 27017,
             "db_name": "campus_unimi_test"
         }
     })
     ODMModel.set_pm(pm)
     dic = {"_id": "2323", "pippo": "pluto"}
     odm = ODMModel(dic)
     odm.save()
     self.assertEqual(
         ODMModel._pm.get_collection("odmmodel").find_one({"_id": "2323"}),
         dic)
     odm.clean()
     self.assertEqual(
         ODMModel._pm.get_collection("odmmodel").find_one({"_id": "2323"}),
         None)
Пример #7
0
from utils.config_manager import ConfigManager
from persistence.db import MongoDBPersistenceManager
from model.odm      import ODMModel
from model          import Building
from utils.logger   import Logger
from analysis       import DXFAnalysis
from analysis       import FloorMergeAnalysis
from analysis       import BuildingIdAnalysis

persistence = MongoDBPersistenceManager(ConfigManager("config/general.json"))
ODMModel.set_pm( persistence )


def data_and_percent(value, total, num_padding = 3,):
   if(total > 0):
      return ("{:0>"+str(num_padding)+"} ({:>0.1f}%)").format(value, value/total*100.0)
   else:
      return ("{:0>"+str(num_padding)+"} ").format(value)

class GeneralReport:

   merge_tuples = [
            ("edilizia", "dxf"),
            ("edilizia", "easyroom"),
            ("easyroom", "dxf"),
            ("easyroom", "edilizia")
         ]

   @classmethod
   def report_building(klass, building):
      BuildingIdAnalysis.analyse_building_id(building)
Пример #8
0
   def setUp(self):
      pm = MongoDBPersistenceManager({
         "db": {
               "url"     : "localhost",
               "port"    : 27017,
               "db_name" : "campus_unimi_test"
            }
      })

      ODMModel.set_pm(pm)

      self.edil_rooms = [
         {
            'room_name' : 'Aula Seminari',
            'cat_name'  : 'Aula',
            'r_id'      : 'T-065',
            'b_id'      : '21030',
            'capacity'  : '52',
            'l_floor'   : 'T'
         },
         {
            'room_name' : 'Aula Pippo',
            'cat_name'  : 'Aula',
            'r_id'      : 'T066',
            'b_id'      : '21030',
            'capacity'  : '52',
            'l_floor'   : 'T'
         },
         {
            'room_name' : 'Aula Pippo Sdentato',
            'cat_name'  : 'Aula',
            'r_id'      : '1066',
            'b_id'      : '21030',
            'capacity'  : '52',
            'l_floor'   : '1'
         }
      ]

      self.easy_rooms = [
         {
            'room_name' : 'Aula Seminari',
            'cat_name'  : 'Aula',
            'r_id'      : '21030#T-065',
            'b_id'      : '21030',
            'capacity'  : '52',
            'l_floor'   : '0'
         },
         {
            'room_name' : 'Aula Pippo',
            'cat_name'  : 'Aula',
            'r_id'      : '21030#T066',
            'b_id'      : '21030',
            'capacity'  : '52',
            'l_floor'   : '0'
         },
         {
            'room_name' : 'Aula Pippo Sdentato',
            'cat_name'  : 'Aula',
            'r_id'      : '21030#1066',
            'b_id'      : '21030',
            'capacity'  : '52',
            'l_floor'   : '10'
         }
      ]

      pm.clean_collection("building")
      self.edil_up      = EdiliziaDataUpdater()
      self.easy_up      = EasyroomDataUpdater()
      Building.__str__  = lambda x: ""