Fixed analytics counts on instructor dashboard.
LMS-11228
This commit is contained in:
@@ -123,6 +123,7 @@ def profile_distribution(course_id, feature):
|
||||
""" Get the count of enrolled students matching the feature value. """
|
||||
return CourseEnrollment.objects.filter(
|
||||
course_id=course_id,
|
||||
is_active=True,
|
||||
**get_filter(feature, value)
|
||||
).count()
|
||||
|
||||
@@ -141,7 +142,8 @@ def profile_distribution(course_id, feature):
|
||||
elif feature in _OPEN_CHOICE_FEATURES:
|
||||
prd.type = 'OPEN_CHOICE'
|
||||
profiles = UserProfile.objects.filter(
|
||||
user__courseenrollment__course_id=course_id
|
||||
user__courseenrollment__course_id=course_id,
|
||||
user__courseenrollment__is_active=True
|
||||
)
|
||||
query_distribution = profiles.values(
|
||||
feature).annotate(Count(feature)).order_by()
|
||||
|
||||
@@ -17,6 +17,7 @@ class TestAnalyticsDistributions(TestCase):
|
||||
|
||||
self.users = [UserFactory(
|
||||
profile__gender=['m', 'f', 'o'][i % 3],
|
||||
profile__level_of_education=['a', 'hs', 'el'][i % 3],
|
||||
profile__year_of_birth=i + 1930
|
||||
) for i in xrange(30)]
|
||||
|
||||
@@ -49,6 +50,26 @@ class TestAnalyticsDistributions(TestCase):
|
||||
self.assertNotIn('no_data', distribution.data)
|
||||
self.assertEqual(distribution.data[1930], 1)
|
||||
|
||||
def test_gender_count(self):
|
||||
course_enrollments = CourseEnrollment.objects.filter(
|
||||
course_id=self.course_id, user__profile__gender='m'
|
||||
)
|
||||
distribution = profile_distribution(self.course_id, "gender")
|
||||
self.assertEqual(distribution.data['m'], len(course_enrollments))
|
||||
course_enrollments[0].deactivate()
|
||||
distribution = profile_distribution(self.course_id, "gender")
|
||||
self.assertEqual(distribution.data['m'], len(course_enrollments) - 1)
|
||||
|
||||
def test_level_of_education_count(self):
|
||||
course_enrollments = CourseEnrollment.objects.filter(
|
||||
course_id=self.course_id, user__profile__level_of_education='hs'
|
||||
)
|
||||
distribution = profile_distribution(self.course_id, "level_of_education")
|
||||
self.assertEqual(distribution.data['hs'], len(course_enrollments))
|
||||
course_enrollments[0].deactivate()
|
||||
distribution = profile_distribution(self.course_id, "level_of_education")
|
||||
self.assertEqual(distribution.data['hs'], len(course_enrollments) - 1)
|
||||
|
||||
|
||||
class TestAnalyticsDistributionsNoData(TestCase):
|
||||
'''Test analytics distribution gathering.'''
|
||||
|
||||
Reference in New Issue
Block a user