def post(self, course_id, user_id):
        args = result_parser.parse_args()
        timestamp = args['unix_seconds'] or int(time.time())

        try:
            # If this is a response to the "next" problem, advance to it first before storing
            # (shouldn't happen if PageLoad messages are posted correctly, but we won't require that)
            nex = self.repo.get_next_problem(course_id, user_id)
            self._rotate_problem(nex, course_id, user_id, **args)
            self.repo.post_interaction(course_id, args['problem'], user_id,
                                       args['correct'], args['attempt'],
                                       timestamp)

            # the user needs a new problem, start choosing one
            self.run_selector(course_id, user_id)
        except SelectException as e:
            abort(
                500,
                message=
                "Interaction successfully stored, but an error occurred starting "
                "a problem selection: " + e.message)
        except DataException as e:
            logger.exception("DATA EXCEPTION:")
            abort(500, message=e.message)

        return {"success": True}, 201
    def get(self, course_id, user_id):
        try:
            nex = self.repo.get_next_problem(course_id, user_id)
            cur = self.repo.get_current_problem(course_id, user_id)
        except DataException as e:
            abort(404, message=e.message)

        okay = bool(nex and 'error' not in nex)

        done_with_course = False
        if not cur:
            done_with_current = True
        else:
            try:
                done_with_current = self._check_current_done(
                    course_id, user_id, cur)
                done_with_course = self._check_course_done(course_id, user_id)
            except DataException as e:
                logger.exception("DATA EXCEPTION: ")
                abort(500, message=str(e))
        return {
            "next": nex,
            "current": cur,
            "done_with_current": done_with_current,
            "okay": okay,
            "done_with_course": done_with_course
        }
 def _post_request(self, function_name, *args, **kwargs):
     try:
         getattr(self.repo, function_name)(*args, **kwargs)
     except DataException as e:
         logger.exception('DataException: ')
         abort(500, message=str(e))
     return {'success': True}, 201
 def _get_request(self, function_name, *args):
     output_list = []
     try:
         output_list = getattr(self.repo, function_name)(*args)
     except DataException as e:
         logger.exception('DataException:')
         abort(404, message=str(e))
     return output_list
Exemple #5
0
    def post(self):
        args = param_parser.parse_args()
        course = args['course_id']
        user = args['user_id']

        try:
            default_param = self.repo.get_model_params(course)
        except DataException:
            logger.debug(
                "Default model's parameters are not found in the course description."
            )
            default_param = None

        try:
            skills_list = self.repo.get_skills(course)
            logger.debug(
                "Skills for the student {} are taken directly from the course {} in which student is enrolled"
                .format(user, course))
        except DataException:
            logger.exception(
                "Skills field are not found in the course: {}, student's skills cannot be added"
                .format(course))
            abort(
                500,
                "Course doesn't contain skills, please update the course {} and try adding student again."
                .format(course))
        try:
            key = self.create_search_key(course, user)
            default_param = self.repo.get(key)
            logger.debug(
                "User has been already enrolled in the course, adapt will use already chosen parameters: {}"
                .format(default_param))
        except DataException:
            logger.debug(
                "User has not been enrolled in the course yet, adapt enrolls user with parameters: {}"
                .format(default_param if default_param else args['params']))
            pass
        if default_param and isinstance(default_param, list):
            params = random.choice(default_param)
            logger.debug(
                "Default model's parameters are found, adapt enrolls user with parameters: {}"
                .format(params))
        elif default_param:
            params = default_param
            logger.debug(
                "Adapt enrolls user with parameters which is already used by the user in other adaptive course's "
                "section: {}".format(params))
        else:
            params = args['params']
        try:
            for skill in skills_list:
                self.selector.set_parameter(params, course, user, skill)
        except SelectException as e:
            abort(500, message=str(e))
        return {'success': True, 'configuredSkills': skills_list}, 201
    def post(self, course_id, user_id):
        args = load_parser.parse_args()
        timestamp = args['unix_seconds'] or int(time.time())

        try:
            self.repo.post_load(course_id, args['problem'], user_id, timestamp)
            nex = self.repo.get_next_problem(course_id, user_id)
            self._rotate_problem(nex, course_id, user_id, **args)
        except DataException as e:
            logger.exception("DATA EXCEPTION:")
            abort(500, message=e.message)

        return {"success": True}, 201
    def get(self, course_id, user_id):
        blob = {
            'data': {},
            'trajectories': {},
            'pretest_length': {},
            'posttest_length': {}
        }
        try:
            blob = fill_user_data(self.repo, course_id, user_id)

        except DataException as e:
            logger.exception("Data exception:")
            abort(500, message=str(e))
        return blob