import logging from json import dumps from app.check_access import check_access from app.criteria import CRITERIONS from app.criteria.utils import create_criterion from app.criteria_pack import CriteriaPackFactory from app.lti_session_passback.auth_checkers import is_admin from app.mongo_models import Criterion from app.mongo_odm import CriterionPackDBManager, TrainingsDBManager, CriterionDBManager from app.root_logger import get_root_logger from app.utils import check_argument_is_convertible_to_object_id, remove_blank_and_none, try_load_json, check_dict_keys api_criteria = Blueprint('api_criteria', __name__, url_prefix="/api/criterion") logger = get_root_logger('web') @api_criteria.route('/create/', methods=['POST']) def create_new_criterion(): if not is_admin(): return {}, 404 return update_criterion('') @api_criteria.route('/<criterion_name>/', methods=['GET']) def get_criterion(criterion_name): if not check_access(): return {}, 404 db_criterion = CriterionDBManager().get_criterion_by_name(criterion_name)
import sys from time import sleep from lti.tool_provider import ToolProvider from app.bd_helper.bd_helper import ConsumersDBManager, get_unpassed_checks, set_passbacked_flag, get_user from app.utils.repeated_timer import RepeatedTimer import configparser config = configparser.ConfigParser() config.read('app/config.ini') from app.root_logger import get_root_logger logger = get_root_logger('passback_grades') class ChecksPassBack: def __init__(self, timeout_seconds=10): self._timeout_seconds = timeout_seconds def grade_passback(self, check): user = check.get('user') passback_params = get_user(user).params_for_passback if not passback_params: return consumer_secret = ConsumersDBManager.get_secret( passback_params['oauth_consumer_key']) response = ToolProvider.from_unpacked_request( secret=consumer_secret, params=passback_params, headers=None, url=None).post_replace_result(score=check.get('score'))
import sys from time import sleep from app.presentation import Presentation from app.config import Config from app.mongo_odm import DBManager, RecognizedPresentationsToProcessDBManager, TrainingsDBManager from app.recognized_presentation import RecognizedPresentation from app.root_logger import get_root_logger from app.status import PresentationStatus logger = get_root_logger(service_name='recognized_presentation_processor') class RecognizedPresentationProcessor: def run(self): while True: try: recognized_presentation_db = RecognizedPresentationsToProcessDBManager() \ .extract_recognized_presentation_to_process() if not recognized_presentation_db: sleep(10) continue training_id = recognized_presentation_db.training_id recognized_presentation_id = recognized_presentation_db.file_id logger.info( 'Extracted recognized presentation with recognized_presentation_id = {}, training_id = {}.' .format(recognized_presentation_id, training_id)) TrainingsDBManager().change_presentation_status( training_id, PresentationStatus.PROCESSING) json_file = DBManager().get_file(recognized_presentation_id) if json_file is None:
import sys from time import sleep from app.audio import Audio from app.config import Config from app.criteria_pack import CriteriaPackFactory from app.feedback_evaluator import FeedbackEvaluatorFactory from app.mongo_odm import CriterionPackDBManager, DBManager, TrainingsToProcessDBManager, TrainingsDBManager, TaskAttemptsDBManager from app.presentation import Presentation from app.root_logger import get_root_logger from app.status import PresentationStatus, TrainingStatus from app.training import Training logger = get_root_logger(service_name='training_processor') class TrainingProcessor: def run(self): while True: try: training_id = TrainingsToProcessDBManager().extract_training_id_to_process() if not training_id: sleep(10) continue logger.info('Extracted training with training_id = {}.'.format(training_id)) training_db = TrainingsDBManager().get_training(training_id) if training_db is None: TrainingsDBManager().change_training_status_by_training_id( training_id, TrainingStatus.PROCESSING_FAILED ) verdict = 'Training with training_id = {} was not found.'.format(training_id)
import sys from time import sleep from app.audio import Audio from app.config import Config from app.mongo_odm import DBManager, RecognizedAudioToProcessDBManager, TrainingsDBManager from app.recognized_audio import RecognizedAudio from app.root_logger import get_root_logger from app.status import AudioStatus logger = get_root_logger(service_name='recognized_audio_processor') class RecognizedAudioProcessor: def run(self): while True: try: recognized_audio_db = RecognizedAudioToProcessDBManager( ).extract_recognized_audio_to_process() if not recognized_audio_db: sleep(10) continue training_id = recognized_audio_db.training_id recognized_audio_id = recognized_audio_db.file_id logger.info( 'Extracted recognized audio with recognized_audio_id = {}, training_id = {}.' .format(recognized_audio_id, training_id)) TrainingsDBManager().change_audio_status( training_id, AudioStatus.PROCESSING) json_file = DBManager().get_file(recognized_audio_id) if json_file is None:
from collections import defaultdict import sys from time import sleep from app.config import Config from app.mongo_odm import DBManager, PresentationFilesDBManager, PresentationsToRecognizeDBManager, TrainingsDBManager, \ RecognizedPresentationsToProcessDBManager from app.presentation_recognizer import PRESENTATION_RECOGNIZERS from app.root_logger import get_root_logger from app.status import PresentationStatus logger = get_root_logger(service_name='presentation_processor') class PresentationProcessor: def __init__(self, presentation_recognizers): self.presentation_recognizers = presentation_recognizers def run(self): while True: try: presentation_to_recognize_db = PresentationsToRecognizeDBManager( ).extract_presentation_to_recognize() if not presentation_to_recognize_db: sleep(10) continue training_id = presentation_to_recognize_db.training_id presentation_file_id = presentation_to_recognize_db.file_id presentation_file_info = PresentationFilesDBManager( ).get_presentation_file(presentation_file_id) logger.info(
app.register_blueprint(api_files) app.register_blueprint(api_logs) app.register_blueprint(api_presentations) app.register_blueprint(api_sessions) app.register_blueprint(api_task_attempts) app.register_blueprint(api_trainings) app.register_blueprint(api_version) app.register_blueprint(routes_admin) app.register_blueprint(routes_criterion) app.register_blueprint(routes_criteria_pack) app.register_blueprint(routes_lti) app.register_blueprint(routes_presentations) app.register_blueprint(routes_trainings) app.register_blueprint(routes_version) logger = get_root_logger(service_name='web') class ReverseProxied(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): forwarded_scheme = environ.get("HTTP_X_FORWARDED_PROTO", None) preferred_scheme = app.config.get("PREFERRED_URL_SCHEME", None) if "https" in [forwarded_scheme, preferred_scheme]: environ["wsgi.url_scheme"] = "https" return self.app(environ, start_response) def resubmit_failed_trainings():
import sys from time import sleep from lti import ToolProvider from app.config import Config from app.mongo_odm import ConsumersDBManager, TaskAttemptsToPassBackDBManager, TaskAttemptsDBManager from app.root_logger import get_root_logger from app.status import PassBackStatus from app.utils import is_testing_active, RepeatedTimer logger = get_root_logger(service_name='task_attempt_to_pass_back_processor') class TaskAttemptToPassBackProcessor: def __init__(self, timeout_seconds=10): self._timeout_seconds = timeout_seconds def grade_passback(self, task_attempt_db, training_id, is_retry): params_for_passback = task_attempt_db.params_for_passback consumer_secret = ConsumersDBManager().get_secret( params_for_passback['oauth_consumer_key']) training_count = task_attempt_db.training_count if training_count == 0: normalized_score = 0 else: scores = list(task_attempt_db.training_scores.values()) total_score = sum( [score if score is not None else 0 for score in scores]) normalized_score = total_score / training_count response = ToolProvider.from_unpacked_request(
import sys from datetime import datetime from bson import ObjectId from app.audio_recognizer import AudioRecognizer, VoskAudioRecognizer from app.config import Config from app.mongo_models import Trainings from app.mongo_odm import DBManager, AudioToRecognizeDBManager, TrainingsDBManager, RecognizedAudioToProcessDBManager from app.root_logger import get_root_logger from app.status import AudioStatus from app.utils import RepeatedTimer logger = get_root_logger(service_name='audio_processor') class AudioProcessor: """ Class to transform raw audio into recognized audio. """ def __init__(self, audio_recognizer: AudioRecognizer, extract_audio_to_recognize_timeout_seconds=10): self._audio_recognizer = audio_recognizer self._extract_audio_to_recognize_timeout_seconds = extract_audio_to_recognize_timeout_seconds def _hangle_error(self, training_id: ObjectId, verdict: str, score=0,