コード例 #1
0
ファイル: models.py プロジェクト: QCInvestments/django-oppia
    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()
        selfTrackers = 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) + selfTrackers.count()
        self.total_downloads = (0 if first_tracker else self.total_downloads) + selfTrackers.filter(type='download').count()

        new_points = Points.objects
        if newest_points_pk > 0:
            new_points = new_points.filter(pk__gt=last_points_pk, pk__lte=newest_points_pk, course=self.course,user=self.user)
        else:
            new_points = new_points.filter(pk__gt=last_points_pk, course=self.course,user=self.user)
        new_points = new_points.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 = Course.get_badges(self.course, self.user)
        self.completed_activities = Course.get_activities_completed(self.course, self.user)

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

        elapsed_time = time.time() - t
        print('took %.2f seconds' % elapsed_time)
コード例 #2
0
def course_completion_rates(request,course_id):

    if not request.user.is_staff:
        return HttpResponse('Unauthorized', status=401)

    try:
        course = Course.objects.get(pk=course_id)
    except Course.DoesNotExist:
        raise Http404

    users_completed = []
    users_incompleted = []

    courseActivities = course.get_no_activities()
    users = User.objects.filter(tracker__course=course).distinct()
    for user in users:
        userActivities = Course.get_activities_completed(course, user)
        userObj = {'user': user}
        userObj['activities_completed'] = userActivities
        userObj['completion_percent'] = (userActivities * 100 / courseActivities)
        if (userActivities >= courseActivities):
            users_completed.append(userObj)
        else:
            users_incompleted.append(userObj)

    return render_to_response('oppia/reports/course_completion_rates.html',
                              {
                                  'course': course,
                                  'users_enroled_count': len(users_completed) + len(users_incompleted),
                                  'users_completed': users_completed,
                                  'users_incompleted': users_incompleted,
                              },
                              context_instance=RequestContext(request))
コード例 #3
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()