Example #1
0
   def _floor_copy(klass, floor):
      """
      Given a floor, perform a pseudo-deep copy, filtering unnecessary keys
      for floor merging.

      For pseudo-deep we mean that fields in the dictionary are copied on a
      per-case basis. In particular, rooms are merged together into a new
      room object, so that further processing algorithms won't change the
      original ones.

      Arguments:
      - floor: a dictionary containing a floor information

      Return Value: a new foor object that copies information from the original
      floor, ignoring however unused keys.
      """
      result                        = {}
      result["f_id"]                = floor["f_id"]
      result["walls"]               = floor.get("walls", [])
      result["windows"]             = floor.get("windows", [])
      result["rooms"]               = {}
      result["unidentified_rooms"]  = []

      # 1 - copia lista di stanze, creando copie e lasciando soltanto le
      #     chiavi necessarie per il merging.
      final_room_keys   = [
            "polygon",
            "cat_id",
            "room_name",
            "equipments",
            "accessibility",
            "capacity"
         ]

      for room_id, room in floor.get("rooms", {}).items():
         result["rooms"][room_id] = filter_keys(room, final_room_keys)

      # 2- copia lista di stanze non identificate, creando copie e lasciando
      #    soltanto le chiavi necessarie per il merging.
      for room in floor.get("unidentified_rooms", []):
         new_room = filter_keys(room, final_room_keys)
         result["unidentified_rooms"].append(new_room)

      return result
Example #2
0
    def _apply_columns_filter(self, possible_headers):
        """Ensure headers contains no leading or trailing spaces, and apply the
      necessary column filters, according to inferred csv type"""

        # If we have been able to infer csv type, we must also apply the filter
        if self.service and self.entities_type:

            valid_headers = possible_headers[self.service][self.entities_type]
            self.header = [s for s in self.header if s in valid_headers]
            self.content = [filter_keys(c, self.header) for c in self.content]
Example #3
0
    def _apply_columns_filter(self, possible_headers):
        """Ensure headers contains no leading or trailing spaces, and apply the
      necessary column filters, according to inferred csv type"""

        # If we have been able to infer csv type, we must also apply the filter
        if self.service and self.entities_type:

            valid_headers = possible_headers[self.service][self.entities_type]
            self.header = [s for s in self.header if s in valid_headers]
            self.content = [filter_keys(c, self.header) for c in self.content]
Example #4
0
   def create_from_building(building):
      identic_keys      = [
         "address", "building_number", "building_name", "l_b_id", "coordinates"
      ]
      merged_key        = building.get("merged", {})
      bv_attrs          = myfunctools.filter_keys(merged_key, identic_keys)
      bv_attrs["_id"]   = building["_id"]

      bv_attrs["floors"] = [
         BuildingView._prepare_floor_obj(f)
         for f in building.get_path("merged.floors", [])
      ]

      return BuildingView(bv_attrs)