def attempt_problem_number(exercise_name, problem_number): user_data = models.UserData.current() if user_data: exercise = models.Exercise.get_by_name(exercise_name) user_exercise = user_data.get_or_insert_exercise(exercise) if user_exercise and problem_number: user_exercise, user_exercise_graph = attempt_problem( user_data, user_exercise, problem_number, request.request_int("attempt_number"), request.request_string("attempt_content"), request.request_string("sha1"), request.request_string("seed"), request.request_bool("complete"), request.request_int("count_hints", default=0), int(request.request_float("time_taken")), request.request_string("non_summative"), request.request_string("problem_type"), request.remote_addr, ) # this always returns a delta of points earned each attempt points_earned = user_data.points - user_data.original_points() if (user_exercise.streak == 0): # never award points for a zero streak points_earned = 0 if (user_exercise.streak == 1): # award points for the first correct exercise done, even if no prior history exists # and the above pts-original points gives a wrong answer points_earned = user_data.points if ( user_data.points == points_earned) else points_earned add_action_results( user_exercise, { "exercise_message_html": templatetags.exercise_message( exercise, user_data.coaches, user_exercise_graph.states(exercise.name)), "points_earned": { "points": points_earned }, "attempt_correct": request.request_bool("complete") }) return user_exercise logging.warning("Problem %d attempted with no user_data present", problem_number) return unauthorized_response()
def hint_problem_number(exercise_name, problem_number): user_data = models.UserData.current() if user_data: exercise = models.Exercise.get_by_name(exercise_name) user_exercise = user_data.get_or_insert_exercise(exercise) if user_exercise and problem_number: prev_user_exercise_graph = models.UserExerciseGraph.get(user_data) attempt_number = request.request_int("attempt_number") count_hints = request.request_int("count_hints") user_exercise, user_exercise_graph, goals_updated = attempt_problem( user_data, user_exercise, problem_number, attempt_number, request.request_string("attempt_content"), request.request_string("sha1"), request.request_string("seed"), request.request_bool("complete"), count_hints, int(request.request_float("time_taken")), request.request_string("non_summative"), request.request_string("problem_type"), request.remote_addr, ) user_states = user_exercise_graph.states(exercise.name) review_mode = request.request_bool("review_mode", default=False) exercise_message_html = templatetags.exercise_message(exercise, user_exercise_graph, review_mode=review_mode) add_action_results(user_exercise, { "exercise_message_html": exercise_message_html, "exercise_state": { "state": [state for state in user_states if user_states[state]], "template" : exercise_message_html, } }) # A hint will count against the user iff they haven't attempted the question yet and it's their first hint if attempt_number == 0 and count_hints == 1: bingo("hints_costly_hint") bingo("hints_costly_hint_binary") return user_exercise logging.warning("Problem %d attempted with no user_data present", problem_number) return unauthorized_response()
def video_download_available(video_id): video = models.Video.all().filter("youtube_id =", video_id).get() if video: video.download_version = models.Video.CURRENT_DOWNLOAD_VERSION if request.request_bool( "available", default=False) else 0 video.put() return video
def attempt_problem_number(exercise_name, problem_number): user_data = models.UserData.current() if user_data: exercise = models.Exercise.get_by_name(exercise_name) user_exercise = user_data.get_or_insert_exercise(exercise) if user_exercise and problem_number: user_exercise, user_exercise_graph = attempt_problem( user_data, user_exercise, problem_number, request.request_int("attempt_number"), request.request_string("attempt_content"), request.request_string("sha1"), request.request_string("seed"), request.request_bool("complete"), request.request_int("count_hints", default=0), int(request.request_float("time_taken")), request.request_string("non_summative"), request.request_string("problem_type"), request.remote_addr, ) # this always returns a delta of points earned each attempt points_earned = user_data.points - user_data.original_points() if(user_exercise.streak == 0): # never award points for a zero streak points_earned = 0 if(user_exercise.streak == 1): # award points for the first correct exercise done, even if no prior history exists # and the above pts-original points gives a wrong answer points_earned = user_data.points if (user_data.points == points_earned) else points_earned add_action_results(user_exercise, { "exercise_message_html": templatetags.exercise_message(exercise, user_data.coaches, user_exercise_graph.states(exercise.name)), "points_earned" : { "points" : points_earned }, "attempt_correct" : request.request_bool("complete") }) return user_exercise logging.warning("Problem %d attempted with no user_data present", problem_number) return unauthorized_response()
def hint_problem_number(exercise_name, problem_number): user_data = models.UserData.current() if user_data: exercise = models.Exercise.get_by_name(exercise_name) user_exercise = user_data.get_or_insert_exercise(exercise) if user_exercise and problem_number: attempt_number = request.request_int("attempt_number") count_hints = request.request_int("count_hints") user_exercise, user_exercise_graph = attempt_problem( user_data, user_exercise, problem_number, attempt_number, request.request_string("attempt_content"), request.request_string("sha1"), request.request_string("seed"), request.request_bool("complete"), count_hints, int(request.request_float("time_taken")), request.request_string("non_summative"), request.request_string("problem_type"), request.remote_addr, ) add_action_results( user_exercise, { "exercise_message_html": templatetags.exercise_message( exercise, user_data.coaches, user_exercise_graph.states(exercise.name)), }) # A hint will count against the user iff they haven't attempted the question yet and it's their first hint if attempt_number == 0 and count_hints == 1: bingo("hints_costly_hint") bingo("hints_costly_hint_binary") return user_exercise logging.warning("Problem %d attempted with no user_data present", problem_number) return unauthorized_response()
def attempt_problem_number(exercise_name, problem_number): user_data = models.UserData.current() if user_data: exercise = models.Exercise.get_by_name(exercise_name) user_exercise = user_data.get_or_insert_exercise(exercise) if user_exercise and problem_number: user_exercise, user_exercise_graph, goals_updated = attempt_problem( user_data, user_exercise, problem_number, request.request_int("attempt_number"), request.request_string("attempt_content"), request.request_string("sha1"), request.request_string("seed"), request.request_bool("complete"), request.request_int("count_hints", default=0), int(request.request_float("time_taken")), request.request_string("non_summative"), request.request_string("problem_type"), request.remote_addr, ) # this always returns a delta of points earned each attempt points_earned = user_data.points - user_data.original_points() if(user_exercise.streak == 0): # never award points for a zero streak points_earned = 0 if(user_exercise.streak == 1): # award points for the first correct exercise done, even if no prior history exists # and the above pts-original points gives a wrong answer points_earned = user_data.points if (user_data.points == points_earned) else points_earned user_states = user_exercise_graph.states(exercise.name) correct = request.request_bool("complete") review_mode = request.request_bool("review_mode", default=False) action_results = { "exercise_state": { "state": [state for state in user_states if user_states[state]], "template" : templatetags.exercise_message(exercise, user_exercise_graph, review_mode=review_mode), }, "points_earned": {"points": points_earned}, "attempt_correct": correct, } if goals_updated: action_results['updateGoals'] = [g.get_visible_data(None) for g in goals_updated] if review_mode: action_results['reviews_left'] = ( user_exercise_graph.reviews_left_count() + (1 - correct)) add_action_results(user_exercise, action_results) return user_exercise logging.warning("Problem %d attempted with no user_data present", problem_number) return unauthorized_response()
def video_download_available(video_id): video = models.Video.all().filter("youtube_id =", video_id).get() if video: video.download_version = models.Video.CURRENT_DOWNLOAD_VERSION if request.request_bool("available", default=False) else 0 video.put() return video