def _resolve_category_for_room(klass, a_room, cats):
        """
      Looks for texts in a_room that looks like a category identifier and
      assigns the cat_name attribute to a_room. If no category ID is found,
      the algorithm tries categories by their human names.

      Arguments:
      - a_room: a room dictionary with a "texts" key containing the list of
      texts to be analyzed.
      - cats: a dictionary indexed by category ID. Values represents the
      category human name.
      Example: { "AUL01" : "Aula" }

      Return value: True if a match is found, False otherwise.
      """
        all_texts = [t["text"].strip().upper() for t in a_room["texts"]]

        # 1 - Look for exact category ids
        match_id = next((t for t in all_texts if t in cats), None)
        if match_id:
            a_room["cat_id"] = match_id
            return True

        # 2 - look for category name match
        match_name = next((t for t in all_texts if RoomCategory.get_cat_id_by_name(t)), None)
        if match_name:
            a_room["cat_id"] = RoomCategory.get_cat_id_by_name(match_name)
            return True

        return False
   def _resolve_category_for_room(klass, a_room, cats):
      """
      Looks for texts in a_room that looks like a category identifier and
      assigns the cat_name attribute to a_room. If no category ID is found,
      the algorithm tries categories by their human names.

      Arguments:
      - a_room: a room dictionary with a "texts" key containing the list of
      texts to be analyzed.
      - cats: a dictionary indexed by category ID. Values represents the
      category human name.
      Example: { "AUL01" : "Aula" }

      Return value: True if a match is found, False otherwise.
      """
      all_texts = [ t["text"].strip().upper() for t in a_room["texts"] ]

      # 1 - Look for exact category ids
      match_id  = next((t for t in all_texts if t in cats), None)
      if match_id:
         a_room["cat_id"] = match_id
         return True

      # 2 - look for category name match
      match_name  = next((t for t in all_texts if RoomCategory.get_cat_id_by_name(t)), None)
      if match_name:
         a_room["cat_id"] = RoomCategory.get_cat_id_by_name(match_name)
         return True

      return False
Esempio n. 3
0
        def map_category(room):
            cat_id = room[1].get("cat_id", "")
            scope = RoomCategory.get_scope_by_id(cat_id)
            cat_name = RoomCategory.get_group_name_by_id(cat_id)

            valid_scopes = {
                "didactic", "didactic support", "laboratory", "WC",
                "personnel", "accessibility"
            }

            if scope not in valid_scopes:
                cat_name = "Sconosciuto"

            return cat_name
Esempio n. 4
0
   def prepare_rooms(self, floor_id, rooms):
      """
      Transform a list of rooms in a dictionary indexed by room id.
      Arguments:
      - floor_id: a string representing the floor identifier,
      - rooms: a list of rooms.
      Returns: a dictionary of rooms.
      Validate the r_id using Building.is_valid_rid function and discard rooms
      with invalid id. Create and return a dictionary of validated rooms.
      """
      result = {}
      discarded_rooms = set()

      for r in map(self.sanitize_room, rooms):
         if not Building.is_valid_rid(r["r_id"]):
            discarded_rooms.add(r["r_id"])
            continue

         if "cat_id" in r:
            r["cat_id"] = RoomCategory.get_cat_id_by_name(r.get("cat_name", ""))
            del r["cat_name"]
         r_id = r["r_id"]
         del r["r_id"]
         result[r_id] = r

      if discarded_rooms:
         Logger.warning(
            "Rooms discarded from floor", floor_id,
            "for having an invalid room id:",
            ", ".join(discarded_rooms)
            )
      return result
Esempio n. 5
0
    def prepare_rooms(self, floor_id, rooms):
        """
      Transform a list of rooms in a dictionary indexed by room id.
      Arguments:
      - floor_id: a string representing the floor identifier,
      - rooms: a list of rooms.
      Returns: a dictionary of rooms.
      Validate the r_id using Building.is_valid_rid function and discard rooms
      with invalid id. Create and return a dictionary of validated rooms.
      """
        result = {}
        discarded_rooms = set()

        for r in map(self.sanitize_room, rooms):
            if not Building.is_valid_rid(r["r_id"]):
                discarded_rooms.add(r["r_id"])
                continue

            if "cat_id" in r:
                r["cat_id"] = RoomCategory.get_cat_id_by_name(
                    r.get("cat_name", ""))
                del r["cat_name"]
            r_id = r["r_id"]
            del r["r_id"]
            result[r_id] = r

        if discarded_rooms:
            Logger.warning("Rooms discarded from floor", floor_id,
                           "for having an invalid room id:",
                           ", ".join(discarded_rooms))
        return result
    def get_room_categories_dict(klass):
        """
      Get room categories and converst them into a dictionary where keys are
      category ids and values are category names
      """

        return {k: v["description"] for k, v in RoomCategory.get_cat_dict().items() if k != "VNS02"}
Esempio n. 7
0
      def map_category(room):
         cat_id    = room[1].get("cat_id", "")
         scope     = RoomCategory.get_scope_by_id(cat_id)
         cat_name  = RoomCategory.get_group_name_by_id(cat_id)

         valid_scopes = {
            "didactic",
            "didactic support",
            "laboratory",
            "WC",
            "personnel",
            "accessibility"
            }

         if scope not in valid_scopes:
            cat_name = "Sconosciuto"

         return cat_name
   def get_room_categories_dict(klass):
      """
      Get room categories and converst them into a dictionary where keys are
      category ids and values are category names
      """

      return  {
         k: v["description"]
         for k, v in RoomCategory.get_cat_dict().items()
         if k != "VNS02"
      }