Пример #1
0
 def before_callback(b):
    DXFRoomIdsResolver.resolve_rooms_id(b, None, "edilizia")
    # Ensure floor merging is performed AFTER DXF Room_id resolution
    merged            = b.attributes_for_source("merged")
    merged["floors"]  = DataMerger.merge_floors(
       b.get("edilizia"),
       b.get("easyroom"),
       b.get("dxf")
    )
Пример #2
0
            def before_callback(b):
                DXFRoomIdsResolver.resolve_rooms_id(b,
                                                    new_floor,
                                                    source_name=None)

                DXFRoomCatsResolver.resolve_room_categories(b, new_floor)

                # Ensure floor merging is performed AFTER DXF Room_id resolution
                merged = b.attributes_for_source("merged")
                merged["floors"] = DataMerger.merge_floors(
                    b.get("edilizia"), b.get("easyroom"), b.get("dxf"))
Пример #3
0
    def test_resolve_rooms_id_floor_by_floor_easyroom(self):
        """Test r_id resolving with easyroom data, one floor at a time"""

        floor = self.db_building["dxf"]["floors"][0]
        DXFRoomIdsResolver.resolve_rooms_id(self.building, floor, "easyroom")

        self.assertEqual(floor["rooms"]["R003"], self.final_rooms["R003"])

        floor = self.db_building["dxf"]["floors"][1]
        DXFRoomIdsResolver.resolve_rooms_id(self.building, floor, "easyroom")

        self.assertEqual(floor["rooms"]["R023"], self.final_rooms["R023"])
        self.assertTrue("R022" not in floor["rooms"])
        self.assertTrue("R002" not in floor["rooms"])
    def test_resolve_rooms_id_floor_by_floor_easyroom(self):
        """Test r_id resolving with easyroom data, one floor at a time"""

        floor = self.db_building["dxf"]["floors"][0]
        DXFRoomIdsResolver.resolve_rooms_id(self.building, floor, "easyroom")

        self.assertEqual(floor["rooms"]["R003"], self.final_rooms["R003"])

        floor = self.db_building["dxf"]["floors"][1]
        DXFRoomIdsResolver.resolve_rooms_id(self.building, floor, "easyroom")

        self.assertEqual(floor["rooms"]["R023"], self.final_rooms["R023"])
        self.assertTrue("R022" not in floor["rooms"])
        self.assertTrue("R002" not in floor["rooms"])
Пример #5
0
    def test_resolve_rooms_id_all_at_once(self):
        """Test r_id resolving with all sources and for all floors"""

        floor_0 = self.db_building["dxf"]["floors"][0]
        floor_1 = self.db_building["dxf"]["floors"][1]
        room_00 = floor_0["unidentified_rooms"][0]
        room_02 = floor_0["unidentified_rooms"][2]
        room_10 = floor_1["unidentified_rooms"][0]
        room_12 = floor_1["unidentified_rooms"][2]

        DXFRoomIdsResolver.resolve_rooms_id(self.building, None, None)

        self.assertEqual(floor_1["rooms"]["R023"], self.final_rooms["R023"])
        self.assertEqual(floor_1["rooms"]["R022"], self.final_rooms["R022"])
        self.assertEqual(floor_0["rooms"]["R002"], self.final_rooms["R002"])
        self.assertEqual(floor_0["rooms"]["R003"], self.final_rooms["R003"])
        self.assertTrue(room_00 not in floor_0["unidentified_rooms"])
        self.assertTrue(room_02 not in floor_0["unidentified_rooms"])
        self.assertTrue(room_10 not in floor_1["unidentified_rooms"])
        self.assertTrue(room_12 not in floor_1["unidentified_rooms"])
    def test_resolve_rooms_id_all_at_once(self):
        """Test r_id resolving with all sources and for all floors"""

        floor_0 = self.db_building["dxf"]["floors"][0]
        floor_1 = self.db_building["dxf"]["floors"][1]
        room_00 = floor_0["unidentified_rooms"][0]
        room_02 = floor_0["unidentified_rooms"][2]
        room_10 = floor_1["unidentified_rooms"][0]
        room_12 = floor_1["unidentified_rooms"][2]

        DXFRoomIdsResolver.resolve_rooms_id(self.building, None, None)

        self.assertEqual(floor_1["rooms"]["R023"], self.final_rooms["R023"])
        self.assertEqual(floor_1["rooms"]["R022"], self.final_rooms["R022"])
        self.assertEqual(floor_0["rooms"]["R002"], self.final_rooms["R002"])
        self.assertEqual(floor_0["rooms"]["R003"], self.final_rooms["R003"])
        self.assertTrue(room_00 not in floor_0["unidentified_rooms"])
        self.assertTrue(room_02 not in floor_0["unidentified_rooms"])
        self.assertTrue(room_10 not in floor_1["unidentified_rooms"])
        self.assertTrue(room_12 not in floor_1["unidentified_rooms"])
Пример #7
0
   def update_rooms(self,rooms):
      """
      Perform an update of room data on Database.

      Arguments:
      - rooms: a list of dictionaries representing a room data.

      Does not return (None).

      Example of a room retrieved from an Edilizia csv file:
      {
         'room_name' : 'Aula Seminari',
         'cat_name' : 'Aula',
         'r_id'      : 'T065',
         'b_id'      : '11010',
         'capacity'  : '52',
         'l_floor'   : 'T'
      }

      The b_id field will be used to locate the associated building on the
      database. If it is found, it will be updated with the information,
      otherwise a new building will be created.

      Note that for each building that gets updated, it's floors will be emptied
      before adding the rooms information. Hence no partial updates are possible:
      everytime this method is called, it must receive the final list of rooms
      for each updated floor.
      """
      # salviamo una data di aggiornamento comune a tutti i palazzi
      self.batch_date = datetime.now()

      # ordiniamo le stanze per edificio e per piano in modo da velocizzare l'algoritmo
      rooms.sort(key = lambda s: (s["b_id"], s["l_floor"]))

      # raggruppiamo le stanze per building_id
      rooms = groupby(rooms, key = lambda s: s["b_id"])

      # Analizziamo un building alla volta
      for (b_id, rooms) in rooms:

         # Non procedo se il b_id non è valido
         if not Building.is_valid_bid(b_id):
            Logger.error(
               "Invalid building id: \"{}\".".format(b_id),
               "Rooms discarded:",
               ", ".join(r["r_id"] for r in rooms)
            )
            continue

         building = Building.find_or_create_by_id(b_id)

         # Lavoro principale di aggiornamento
         self.replace_building_rooms(building, rooms)

         # Non sarebbe questa gia' una politica di merge? Si tratta di usare
         # info di piu' sorgenti per risolvere qualcosa di DXF, ma usiamo più
         # sorgenti! È un tipo di merge, non un DXFDataUpdater. Mi sembra nel
         # posto sbagliato questo metodo. Mi sembra che le funzionalità di
         # merge sono compito del building model.
         DXFRoomIdsResolver.resolve_rooms_id(building, None, self.get_namespace())

         # Ensure floor merging is performed AFTER DXF Room_id resolution
         merged            = building.attributes_for_source("merged")
         merged["floors"]  = DataMerger.merge_floors(
            building.get("edilizia"),
            building.get("easyroom"),
            building.get("dxf")
         )

         building.save()
Пример #8
0
    def update_rooms(self, rooms):
        """
      Perform an update of room data on Database.

      Arguments:
      - rooms: a list of dictionaries representing a room data.

      Does not return (None).

      Example of a room retrieved from an Edilizia csv file:
      {
         'room_name' : 'Aula Seminari',
         'cat_name' : 'Aula',
         'r_id'      : 'T065',
         'b_id'      : '11010',
         'capacity'  : '52',
         'l_floor'   : 'T'
      }

      The b_id field will be used to locate the associated building on the
      database. If it is found, it will be updated with the information,
      otherwise a new building will be created.

      Note that for each building that gets updated, it's floors will be emptied
      before adding the rooms information. Hence no partial updates are possible:
      everytime this method is called, it must receive the final list of rooms
      for each updated floor.
      """
        # salviamo una data di aggiornamento comune a tutti i palazzi
        self.batch_date = datetime.now()

        # ordiniamo le stanze per edificio e per piano in modo da velocizzare l'algoritmo
        rooms.sort(key=lambda s: (s["b_id"], s["l_floor"]))

        # raggruppiamo le stanze per building_id
        rooms = groupby(rooms, key=lambda s: s["b_id"])

        # Analizziamo un building alla volta
        for (b_id, rooms) in rooms:

            # Non procedo se il b_id non è valido
            if not Building.is_valid_bid(b_id):
                Logger.error("Invalid building id: \"{}\".".format(b_id),
                             "Rooms discarded:",
                             ", ".join(r["r_id"] for r in rooms))
                continue

            building = Building.find_or_create_by_id(b_id)

            # Lavoro principale di aggiornamento
            self.replace_building_rooms(building, rooms)

            # Non sarebbe questa gia' una politica di merge? Si tratta di usare
            # info di piu' sorgenti per risolvere qualcosa di DXF, ma usiamo più
            # sorgenti! È un tipo di merge, non un DXFDataUpdater. Mi sembra nel
            # posto sbagliato questo metodo. Mi sembra che le funzionalità di
            # merge sono compito del building model.
            DXFRoomIdsResolver.resolve_rooms_id(building, None,
                                                self.get_namespace())

            # Ensure floor merging is performed AFTER DXF Room_id resolution
            merged = building.attributes_for_source("merged")
            merged["floors"] = DataMerger.merge_floors(
                building.get("edilizia"), building.get("easyroom"),
                building.get("dxf"))

            building.save()