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

Commit

Permalink
Add passing_users to course summary (#170)
Browse files Browse the repository at this point in the history
EDU-153
  • Loading branch information
Eric Fischer authored May 24, 2017
1 parent 5a85c45 commit e72a562
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Gabe Mulley <[email protected]>
Jason Bau <[email protected]>
John Jarvis <[email protected]>
Dmitry Viskov <[email protected]>
Eric Fischer <[email protected]>
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,17 @@ def generate_daily_data(self, course_id, start_date, end_date):
progress.update(1)
date = date + datetime.timedelta(days=1)

for mode, ratio in enrollment_mode_ratios.iteritems():
for index, (mode, ratio) in enumerate(enrollment_mode_ratios.iteritems()):
count = int(ratio * daily_total)
pass_rate = min(random.normalvariate(.45 + (.1 * index), .15), 1.0)
cumulative_count = count + random.randint(0, 100)
models.CourseMetaSummaryEnrollment.objects.create(
course_id=course_id, catalog_course_title='Demo Course', catalog_course='Demo_Course',
start_time=timezone.now() - datetime.timedelta(weeks=6),
end_time=timezone.now() + datetime.timedelta(weeks=10),
pacing_type='self_paced', availability='Starting Soon', enrollment_mode=mode, count=count,
cumulative_count=cumulative_count, count_change_7_days=random.randint(-50, 50))
cumulative_count=cumulative_count, count_change_7_days=random.randint(-50, 50),
passing_users=int(cumulative_count * pass_rate))

models.CourseProgramMetadata.objects.create(course_id=course_id, program_id='Demo_Program',
program_type='Demo', program_title='Demo Program')
Expand Down
1 change: 1 addition & 0 deletions analytics_data_api/v0/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CourseMetaSummaryEnrollment(BaseCourseModel):
count = models.IntegerField(null=False)
cumulative_count = models.IntegerField(null=False)
count_change_7_days = models.IntegerField(default=0)
passing_users = models.IntegerField(default=0)

class Meta(BaseCourseModel.Meta):
db_table = 'course_meta_summary_enrollment'
Expand Down
1 change: 1 addition & 0 deletions analytics_data_api/v0/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ class CourseMetaSummaryEnrollmentSerializer(ModelSerializerWithCreatedField, Dyn
count = serializers.IntegerField(default=0)
cumulative_count = serializers.IntegerField(default=0)
count_change_7_days = serializers.IntegerField(default=0)
passing_users = serializers.IntegerField(default=0)
enrollment_modes = serializers.SerializerMethodField()
programs = serializers.SerializerMethodField()

Expand Down
13 changes: 12 additions & 1 deletion analytics_data_api/v0/tests/views/test_course_summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create_model(self, model_id, **kwargs):
start_time=datetime.datetime(2016, 10, 11, tzinfo=pytz.utc),
end_time=datetime.datetime(2016, 12, 18, tzinfo=pytz.utc),
pacing_type='instructor', availability=kwargs['availability'], enrollment_mode=mode,
count=5, cumulative_count=10, count_change_7_days=1, create=self.now,)
count=5, cumulative_count=10, count_change_7_days=1, passing_users=1, create=self.now,)
if 'programs' in kwargs and kwargs['programs']:
# Create a link from this course to a program
G(models.CourseProgramMetadata, course_id=model_id, program_id=CourseSamples.program_ids[0],
Expand Down Expand Up @@ -70,20 +70,23 @@ def expected_result(self, item_id, modes=None, availability='Current', programs=
('count', count_factor * num_modes),
('cumulative_count', cumulative_count_factor * num_modes),
('count_change_7_days', count_change_factor * num_modes),
('passing_users', count_change_factor * num_modes),
('enrollment_modes', {}),
])
summary['enrollment_modes'].update({
mode: {
'count': count_factor,
'cumulative_count': cumulative_count_factor,
'count_change_7_days': count_change_factor,
'passing_users': count_change_factor,
} for mode in modes
})
summary['enrollment_modes'].update({
mode: {
'count': 0,
'cumulative_count': 0,
'count_change_7_days': 0,
'passing_users': 0,
} for mode in set(enrollment_modes.ALL) - set(modes)
})
no_prof = summary['enrollment_modes'].pop(enrollment_modes.PROFESSIONAL_NO_ID)
Expand All @@ -92,6 +95,7 @@ def expected_result(self, item_id, modes=None, availability='Current', programs=
'count': prof['count'] + no_prof['count'],
'cumulative_count': prof['cumulative_count'] + no_prof['cumulative_count'],
'count_change_7_days': prof['count_change_7_days'] + no_prof['count_change_7_days'],
'passing_users': prof['passing_users'] + no_prof['passing_users'],
})
if programs:
summary['programs'] = [CourseSamples.program_ids[0]]
Expand Down Expand Up @@ -159,3 +163,10 @@ def test_programs(self):
response = self.authenticated_get(self.path(exclude=self.always_exclude[:1], programs=['True']))
self.assertEquals(response.status_code, 200)
self.assertItemsEqual(response.data, self.all_expected_results(programs=True))

@ddt.data('passing_users', )
def test_exclude(self, field):
self.generate_data()
response = self.authenticated_get(self.path(exclude=[field]))
self.assertEquals(response.status_code, 200)
self.assertEquals(str(response.data).count(field), 0)
7 changes: 6 additions & 1 deletion analytics_data_api/v0/views/course_summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class CourseSummariesView(APIListView):
model = models.CourseMetaSummaryEnrollment
model_id_field = 'course_id'
programs_model = models.CourseProgramMetadata
count_fields = ('count', 'cumulative_count', 'count_change_7_days') # are initialized to 0 by default
count_fields = ('count', 'cumulative_count', 'count_change_7_days',
'passing_users') # are initialized to 0 by default
summary_meta_fields = ['catalog_course_title', 'catalog_course', 'start_time', 'end_time',
'pacing_type', 'availability'] # fields to extract from summary model

Expand Down Expand Up @@ -120,6 +121,10 @@ def postprocess_field_dict(self, field_dict):
# don't do expensive looping for programs if we are just going to throw it away
field_dict = self.add_programs(field_dict)

for field in self.exclude:
for mode in field_dict['enrollment_modes']:
_ = field_dict['enrollment_modes'][mode].pop(field, None)

return field_dict

def add_programs(self, field_dict):
Expand Down

0 comments on commit e72a562

Please sign in to comment.