Beispiel #1
0
    def update_summary(
            self,
            last_tracker_pk=0,
            newest_tracker_pk=0,
            # range of tracker ids to process
            last_points_pk=0,
            newest_points_pk=0
        # range of points ids to process
    ):

        first_tracker = (last_tracker_pk == 0)
        first_points = (last_points_pk == 0)

        self_trackers = Tracker.objects.filter(user=self.user,
                                               course=self.course,
                                               pk__gt=last_tracker_pk,
                                               pk__lte=newest_tracker_pk)

        activity_trackers = self_trackers.exclude(
            type=constants.STR_TRACKER_TYPE_DOWNLOAD)

        # Add the values that are directly obtained from the last pks
        self.total_activity = (0 if first_tracker else self.total_activity
                               ) + activity_trackers.count()
        self.total_downloads = (
            0
            if first_tracker else self.total_downloads) + self_trackers.filter(
                type=constants.STR_TRACKER_TYPE_DOWNLOAD).count()

        filters = {
            'user': self.user,
            'course': self.course,
            'pk__gt': last_points_pk
        }
        if newest_points_pk > 0:
            filters['pk__lte'] = newest_points_pk
        new_points = Points.objects.filter(** filters) \
            .aggregate(total=Sum('points'))['total']

        if new_points:
            self.points = (0 if first_points else self.points) + new_points

        # Values that need to be recalculated (as the course digests may vary)
        self.pretest_score = Course.get_pre_test_score(self.course, self.user)
        self.quizzes_passed = Course.get_no_quizzes_completed(
            self.course, self.user)
        self.completed_activities = Course.get_activities_completed(
            self.course, self.user)
        self.media_viewed = Course.get_media_viewed(self.course, self.user)
        self.badges_achieved = Award.get_userawards(self.user, self.course)

        # Update the data in the database
        self.save()

        # update total_activity_current and total_activity_previous
        self.update_current_previous_activity()
Beispiel #2
0
    def update_summary(
            self,
            last_tracker_pk=0,
            newest_tracker_pk=0,  # range of tracker ids to process
            last_points_pk=0,
            newest_points_pk=0  # range of points ids to process
    ):

        first_tracker = (last_tracker_pk == 0)
        first_points = (last_points_pk == 0)

        t = time.time()
        self_trackers = Tracker.objects.filter(user=self.user,
                                               course=self.course,
                                               pk__gt=last_tracker_pk,
                                               pk__lte=newest_tracker_pk)

        ### Add the values that are directly obtained from the last pks
        self.total_activity = (0 if first_tracker else
                               self.total_activity) + self_trackers.count()
        self.total_downloads = (0 if first_tracker else
                                self.total_downloads) + self_trackers.filter(
                                    type='download').count()

        filters = {
            'user': self.user,
            'course': self.course,
            'pk__gt': last_points_pk
        }
        if newest_points_pk > 0:
            filters['pk__lte'] = newest_points_pk
        new_points = Points.objects.filter(**filters).aggregate(
            total=Sum('points'))['total']

        if new_points:
            self.points = (0 if first_points else self.points) + new_points

        ### Values that need to be recalculated (as the course digests may vary)
        self.pretest_score = Course.get_pre_test_score(self.course, self.user)
        self.quizzes_passed = Course.get_no_quizzes_completed(
            self.course, self.user)
        self.badges_achieved = Award.get_userawards(self.user, self.course)
        self.completed_activities = Course.get_activities_completed(
            self.course, self.user)
        self.media_viewed = Course.get_media_viewed(self.course, self.user)

        ### Update the data in the database
        self.save()

        elapsed_time = time.time() - t
        print('took %.2f seconds' % elapsed_time)
    def update_summary(self,
                       last_tracker_pk=0, newest_tracker_pk=0,  # range of tracker ids to process
                       last_points_pk=0, newest_points_pk=0     # range of points ids to process
                       ):

        first_tracker = (last_tracker_pk == 0)
        first_points = (last_points_pk == 0)

        t = time.time()
        self_trackers = Tracker.objects.filter(user=self.user, course=self.course, pk__gt=last_tracker_pk, pk__lte=newest_tracker_pk)

        ### Add the values that are directly obtained from the last pks
        self.total_activity = (0 if first_tracker else self.total_activity) + self_trackers.count()
        self.total_downloads = (0 if first_tracker else self.total_downloads) + self_trackers.filter(type='download').count()

        filters = {
            'user': self.user,
            'course': self.course,
            'pk__gt': last_points_pk
        }
        if newest_points_pk > 0:
            filters['pk__lte'] = newest_points_pk
        new_points = Points.objects.filter( ** filters).aggregate(total=Sum('points'))['total']

        if new_points:
            self.points = (0 if first_points else self.points) + new_points

        ### Values that need to be recalculated (as the course digests may vary)
        self.pretest_score = Course.get_pre_test_score(self.course, self.user)
        self.quizzes_passed = Course.get_no_quizzes_completed(self.course, self.user)
        self.badges_achieved = Award.get_userawards(self.user, self.course)
        self.completed_activities = Course.get_activities_completed(self.course, self.user)
        self.media_viewed = Course.get_media_viewed(self.course, self.user)

        ### Update the data in the database
        self.save()

        elapsed_time = time.time() - t
        print('took %.2f seconds' % elapsed_time)