Пример #1
0
    def add_progress(self, exercises_and_videos):
        """Take a list of ExerciseAndVideo objects, set per-user progress."""
        # We can have many VideoLog entries for a single video.
        # Args are user, video, seconds watched, last second watched.
        # We stub out the time here so the database is deterministic.
        # TODO(csilvers): stub out datetime.datetime.now() and .utcnow()
        # and set these at some specific time.
        video_models.VideoLog.add_entry(
            self.user1, exercises_and_videos.video1,
            exercises_and_videos.video1.duration / 10,
            exercises_and_videos.video1.duration / 10 + 1)
        video_models.VideoLog.add_entry(
            self.user1, exercises_and_videos.video1,
            exercises_and_videos.video1.duration / 2,
            exercises_and_videos.video1.duration / 2 + 2)
        # TODO(csilvers): make sure the deferred task runs that flushes these.

        user_exercise1 = self.user1.get_or_insert_exercise(
            exercises_and_videos.exercise1)
        exercise_util.attempt_problem(
            self.user1,
            user_exercise1,
            1,  # problem_number
            1,  # attempt_number
            "one",  # attempt_content
            "TODO(csilvers)",  # sha1
            "random_seed",  # random seed
            False,  # gotten to the right answer?
            0,  # number of hints tried
            15,  # time taken (in seconds?)
            False,  # being done in review mode?
            False,  # being done in topic/power mode?
            "obsolete",  # problem_type
            "127.0.0.1",  # ip address
            async_problem_log_put=False)
Пример #2
0
    def add_progress(self, exercises_and_videos):
        """Take a list of ExerciseAndVideo objects, set per-user progress."""
        # TODO(csilvers): stub out datetime.datetime.now() and .utcnow()
        # and set these at some specific time.

        # We can have many VideoLog entries for a single video.
        # Args are user, video, seconds watched, last second watched.
        # We stub out the time here so the database is deterministic.
        video_models.VideoLog.add_entry(
            self.user1, exercises_and_videos.exponents.video,
            exercises_and_videos.exponents.video.duration / 10,
            exercises_and_videos.exponents.video.duration / 10 + 1)
        video_models.VideoLog.add_entry(
            self.user1, exercises_and_videos.exponents.video,
            exercises_and_videos.exponents.video.duration / 2,
            exercises_and_videos.exponents.video.duration / 2 + 2)

        user_exercise1 = self.user1.get_or_insert_exercise(
            exercises_and_videos.exponents.exercise)
        exercise_util.attempt_problem(self.user1, user_exercise1,
                                      1,   # problem_number
                                      1,   # attempt_number
                                      "one",  # attempt_content -- wrong!!
                                      "sha1_unused?",         # sha1
                                      "random_seed",     # random seed
                                      False,  # gotten to the right answer?
                                      0,      # number of hints tried
                                      15,     # time taken (in seconds?)
                                      False,  # being done in review mode?
                                      False,  # being done in topic/power mode?
                                      "obsolete",   # problem_type
                                      "127.0.0.1",  # ip address
                                      async_problem_log_put=False)
        # He's asking for a hint!
        exercise_util.attempt_problem(self.user1, user_exercise1,
                                      1, 2, "hint", "sha1", "random_seed2",
                                      False, 1, 90, False, False,
                                      "obsolete", "127.0.0.1",
                                      async_problem_log_put=False)
        # Ten seconds later (or maybe 100?), he gets it right.
        exercise_util.attempt_problem(self.user1, user_exercise1,
                                      1, 2, "two", "sha1", "random_seed2",
                                      True, 1, 100, False, False,
                                      "obsolete", "127.0.0.1",
                                      async_problem_log_put=False)
        # Now he's got it! -- the second problem is a breeze.
        exercise_util.attempt_problem(self.user1, user_exercise1,
                                      2, 1, "right", "sha1", "random_seed3",
                                      True, 0, 10, False, False,
                                      "obsolete", "127.0.0.1",
                                      async_problem_log_put=False)

        user_exercise2 = self.user1.get_or_insert_exercise(
            exercises_and_videos.equations.exercise)
        for i in xrange(1, 25):    # 20 is enough to get a streak badge
            exercise_util.attempt_problem(self.user1, user_exercise2,
                                          i, 1, "firsttry", "sha1", "seed4",
                                          True, 0, (30 - i), False, False,
                                          "obsolete", "127.0.0.1",
                                          async_problem_log_put=False)
Пример #3
0
    def add_progress(self, exercises_and_videos):
        """Take a list of ExerciseAndVideo objects, set per-user progress."""
        # We can have many VideoLog entries for a single video.
        # Args are user, video, seconds watched, last second watched.
        # We stub out the time here so the database is deterministic.
        # TODO(csilvers): stub out datetime.datetime.now() and .utcnow()
        # and set these at some specific time.
        video_models.VideoLog.add_entry(
            self.user1, exercises_and_videos.video1,
            exercises_and_videos.video1.duration / 10,
            exercises_and_videos.video1.duration / 10 + 1)
        video_models.VideoLog.add_entry(
            self.user1, exercises_and_videos.video1,
            exercises_and_videos.video1.duration / 2,
            exercises_and_videos.video1.duration / 2 + 2)
        # TODO(csilvers): make sure the deferred task runs that flushes these.

        user_exercise1 = self.user1.get_or_insert_exercise(
            exercises_and_videos.exercise1)
        exercise_util.attempt_problem(self.user1, user_exercise1,
                                      1,   # problem_number
                                      1,   # attempt_number
                                      "one",  # attempt_content
                                      "TODO(csilvers)",  # sha1
                                      "random_seed",     # random seed
                                      False,  # gotten to the right answer?
                                      0,      # number of hints tried
                                      15,     # time taken (in seconds?)
                                      False,  # being done in review mode?
                                      False,  # being done in topic/power mode?
                                      "obsolete",   # problem_type
                                      "127.0.0.1",  # ip address
                                      async_problem_log_put=False)
Пример #4
0
    def test_new_badge_mapreduce(self):
        # Setting up the data is a bit complicated.  First, we have to
        # have a user do 5 correct exercises in a row, to earn the
        # easiest streak-badge.  But we have to do it in a way that
        # the code doesn't award the badge right away.  Then we can
        # run the mapreduce, which should award the badge then.  To do
        # this, we stub out the call that would normally award the
        # badge right away.
        orig_update_fn = util_badges.update_with_user_exercise
        try:
            util_badges.update_with_user_exercise = lambda *args, **kw: None
            new_user = user_models.UserData.insert_for('badgeuser',
                                                       '*****@*****.**')
            exercise = exercise_models.Exercise.get_by_name('exponent_rules')
            user_exercise = new_user.get_or_insert_exercise(exercise)
            for i in xrange(1, 10):  # 5 is enough, but we'll do 10
                exercise_util.attempt_problem(new_user,
                                              user_exercise,
                                              i,
                                              1,
                                              "firsttry",
                                              "sha1",
                                              "seed",
                                              True,
                                              0,
                                              3,
                                              False,
                                              False,
                                              "obsolete",
                                              "127.0.0.1", {},
                                              "TEST",
                                              "TEST",
                                              1,
                                              7,
                                              async_problem_log_put=False,
                                              async_stack_log_put=False)
        finally:
            util_badges.update_with_user_exercise = orig_update_fn

        # The badges info should be empty.
        b = models_badges.UserBadge.all().filter('user ='******'user =', new_user.user).get()
        self.assertNotEqual(None, b)
Пример #5
0
    def test_new_badge_mapreduce(self):
        # Setting up the data is a bit complicated.  First, we have to
        # have a user do 5 correct exercises in a row, to earn the
        # easiest streak-badge.  But we have to do it in a way that
        # the code doesn't award the badge right away.  Then we can
        # run the mapreduce, which should award the badge then.  To do
        # this, we stub out the call that would normally award the
        # badge right away.
        orig_update_fn = util_badges.update_with_user_exercise
        try:
            util_badges.update_with_user_exercise = lambda *args, **kw: None
            new_user = user_models.UserData.insert_for('badgeuser',
                                                       '*****@*****.**')
            exercise = exercise_models.Exercise.get_by_name('exponent_rules')
            user_exercise = new_user.get_or_insert_exercise(exercise)
            for i in xrange(1, 10):    # 5 is enough, but we'll do 10
                exercise_util.attempt_problem(new_user, user_exercise,
                                              i, 1, "firsttry", "sha1", "seed",
                                              True, 0, 3, False, False,
                                              "obsolete", "127.0.0.1", {},
                                              "TEST", "TEST", 1, 7,
                                              async_problem_log_put=False,
                                              async_stack_log_put=False)
        finally:
            util_badges.update_with_user_exercise = orig_update_fn

        # The badges info should be empty.
        b = models_badges.UserBadge.all().filter('user ='******'user =', new_user.user).get()
        self.assertNotEqual(None, b)