Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1160 from edx/ashultz0/masters-count-for-index
Browse files Browse the repository at this point in the history
hook up masters count to index page
  • Loading branch information
ashultz0 authored Aug 11, 2021
2 parents a16a6c9 + 940a6d9 commit a6a13da
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
4 changes: 4 additions & 0 deletions acceptance_tests/test_course_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def _test_summary_metrics(self):
i = 7
count_change_i_days = course_summaries[0]['count_change_%s_days' % i]
verified_enrollment = course_summaries[0]['enrollment_modes']['verified']['count']
masters_enrollment = course_summaries[0]['enrollment_modes']['masters']['count']

tooltip = 'Current enrollments across all of your courses.'
self.assertMetricTileValid('current_enrollment', current_enrollment, tooltip)
Expand All @@ -329,3 +330,6 @@ def _test_summary_metrics(self):

tooltip = 'Verified enrollments across all of your courses.'
self.assertMetricTileValid('verified_enrollment', verified_enrollment, tooltip)

tooltip = "Master's enrollments across all of your courses."
self.assertMetricTileValid('masters_enrollment', masters_enrollment, tooltip)
27 changes: 19 additions & 8 deletions analytics_dashboard/courses/presenters/course_summaries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import reduce # pylint: disable=redefined-builtin

from analyticsclient.constants import enrollment_modes
from django.conf import settings
from django.core.cache import cache
from waffle import switch_is_active
Expand Down Expand Up @@ -77,13 +76,25 @@ def get_course_summaries(self, course_ids=None):
return summaries, self._get_last_updated(summaries)

def get_course_summary_metrics(self, summaries):
total = 0
current = 0
week_change = 0
verified = 0
masters = 0
for s in summaries:
total += s.get('cumulative_count', 0)
current += s.get('count', 0)
week_change += s.get('count_change_7_days', 0)
modes = s.get('enrollment_modes', {})
verified += modes.get(enrollment_modes.VERIFIED, {}).get('count', 0)
masters += modes.get(enrollment_modes.MASTERS, {}).get('count', 0)

summary = {
'total_enrollment': reduce(lambda x, y: x + y.get('cumulative_count', 0), summaries, 0),
'current_enrollment': reduce(lambda x, y: x + y.get('count', 0), summaries, 0),
'enrollment_change_7_days': reduce(lambda x, y: x + y.get('count_change_7_days', 0), summaries, 0),
'verified_enrollment': reduce(lambda x, y: x + y.get('enrollment_modes', {}).get('verified',
{}).get('count', 0),
summaries, 0),
'total_enrollment': total,
'current_enrollment': current,
'enrollment_change_7_days': week_change,
'verified_enrollment': verified,
'masters_enrollment': masters,
}

return summary
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class CourseSummariesPresenterTests(TestCase):
'cumulative_count': 4087,
'count_change_7_days': 0,
'passing_users': 100,
},
'masters': {
'count': 1101,
'cumulative_count': 1103,
'count_change_7_days': 0,
'passing_users': 0,
}
},
'created': utils.CREATED_DATETIME_STRING,
Expand All @@ -115,7 +121,7 @@ class CourseSummariesPresenterTests(TestCase):
'end_date': None,
'pacing_type': 'instructor_paced',
'availability': None,
'count': None,
'count': 0,
'cumulative_count': 1,
'count_change_7_days': 0,
'enrollment_modes': {
Expand Down Expand Up @@ -148,6 +154,12 @@ class CourseSummariesPresenterTests(TestCase):
'cumulative_count': 1,
'count_change_7_days': 0,
'passing_users': 0,
},
'masters': {
'count': 10,
'cumulative_count': 10,
'count_change_7_days': 0,
'passing_users': 0,
}
},
'created': utils.CREATED_DATETIME_STRING,
Expand Down Expand Up @@ -233,3 +245,14 @@ def test_no_summaries(self):
summaries, last_updated = presenter.get_course_summaries()
self.assertListEqual(summaries, [])
self.assertIsNone(last_updated)

def test_get_course_summary_metrics(self):
metrics = CourseSummariesPresenter().get_course_summary_metrics(self._PRESENTER_SUMMARIES.values())
expected = {
'total_enrollment': 5111,
'current_enrollment': 3888,
'enrollment_change_7_days': 4,
'verified_enrollment': 13,
'masters_enrollment': 1111,
}
self.assertEqual(metrics, expected)

0 comments on commit a6a13da

Please sign in to comment.