Exemplo n.º 1
0
    def check_and_update_mapper_level(user_id: int):
        """ Check users mapping level and update if they have crossed threshold """
        user = UserService.get_user_by_id(user_id)
        user_level = MappingLevel(user.mapping_level)

        if user_level == MappingLevel.ADVANCED:
            return  # User has achieved highest level, so no need to do further checking

        intermediate_level = current_app.config["MAPPER_LEVEL_INTERMEDIATE"]
        advanced_level = current_app.config["MAPPER_LEVEL_ADVANCED"]

        try:
            osm_details = OSMService.get_osm_details_for_user(user_id)
            if (osm_details.changeset_count > advanced_level
                    and user.mapping_level != MappingLevel.ADVANCED.value):
                user.mapping_level = MappingLevel.ADVANCED.value
                UserService.notify_level_upgrade(user_id, user.username,
                                                 "ADVANCED")
            elif (intermediate_level < osm_details.changeset_count <
                  advanced_level
                  and user.mapping_level != MappingLevel.INTERMEDIATE.value):
                user.mapping_level = MappingLevel.INTERMEDIATE.value
                UserService.notify_level_upgrade(user_id, user.username,
                                                 "INTERMEDIATE")
        except OSMServiceError:
            # Swallow exception as we don't want to blow up the server for this
            current_app.logger.error("Error attempting to update mapper level")
            return

        user.save()
Exemplo n.º 2
0
    def get_mapping_level(user_id: int):
        """ Gets mapping level user is at"""
        user = UserService.get_user_by_id(user_id)

        return MappingLevel(user.mapping_level)