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

Commit 915cab3

Browse files
committed
Updated field names in course summaries.
* renamed start/end_time to start/end_date * renamed modes to enrollment_modes
1 parent e122056 commit 915cab3

5 files changed

Lines changed: 30 additions & 29 deletions

File tree

analytics_data_api/management/commands/generate_fake_course_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def generate_daily_data(self, course_id, start_date, end_date):
140140
cumulative_count = count + random.randint(0, 100)
141141
models.CourseMetaSummaryEnrollment.objects.create(
142142
course_id=course_id, catalog_course_title='Demo Course', catalog_course='Demo_Course',
143-
start_date=timezone.now() - datetime.timedelta(weeks=6),
144-
end_date=timezone.now() + datetime.timedelta(weeks=10),
145-
pacing_type='self_paced', availability='Current', mode=mode, count=count,
143+
start_time=timezone.now() - datetime.timedelta(weeks=6),
144+
end_time=timezone.now() + datetime.timedelta(weeks=10),
145+
pacing_type='self_paced', availability='Current', enrollment_mode=mode, count=count,
146146
cumulative_count=cumulative_count, count_change_7_days=random.randint(-50, 50))
147147

148148
progress.update(1)

analytics_data_api/v0/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ class Meta(BaseCourseEnrollment.Meta):
7070
class CourseMetaSummaryEnrollment(BaseCourseModel):
7171
catalog_course_title = models.CharField(db_index=True, max_length=255)
7272
catalog_course = models.CharField(db_index=True, max_length=255)
73-
start_date = models.DateTimeField()
74-
end_date = models.DateTimeField()
73+
start_time = models.DateTimeField()
74+
end_time = models.DateTimeField()
7575
pacing_type = models.CharField(db_index=True, max_length=255)
7676
availability = models.CharField(db_index=True, max_length=255)
77-
mode = models.CharField(max_length=255)
77+
enrollment_mode = models.CharField(max_length=255)
7878
count = models.IntegerField(null=False)
7979
cumulative_count = models.IntegerField(null=False)
8080
count_change_7_days = models.IntegerField(default=0)
8181

8282
class Meta(BaseCourseModel.Meta):
8383
db_table = 'course_meta_summary_enrollment'
8484
ordering = ('course_id',)
85-
unique_together = [('course_id', 'mode',)]
85+
unique_together = [('course_id', 'enrollment_mode',)]
8686

8787

8888
class CourseEnrollmentByBirthYear(BaseCourseEnrollment):

analytics_data_api/v0/serializers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,18 +539,19 @@ class CourseMetaSummaryEnrollmentSerializer(ModelSerializerWithCreatedField, Dyn
539539
course_id = serializers.CharField()
540540
catalog_course_title = serializers.CharField()
541541
catalog_course = serializers.CharField()
542-
start_date = serializers.DateTimeField(format=settings.DATETIME_FORMAT)
543-
end_date = serializers.DateTimeField(format=settings.DATETIME_FORMAT)
542+
start_date = serializers.DateTimeField(source='start_time', format=settings.DATETIME_FORMAT)
543+
end_date = serializers.DateTimeField(source='end_time', format=settings.DATETIME_FORMAT)
544544
pacing_type = serializers.CharField()
545545
availability = serializers.CharField()
546546
count = serializers.IntegerField(default=0)
547547
cumulative_count = serializers.IntegerField(default=0)
548548
count_change_7_days = serializers.IntegerField(default=0)
549-
modes = serializers.SerializerMethodField()
549+
enrollment_modes = serializers.SerializerMethodField()
550550

551-
def get_modes(self, obj):
552-
return obj.get('modes', None)
551+
def get_enrollment_modes(self, obj):
552+
return obj.get('enrollment_modes', None)
553553

554554
class Meta(object):
555555
model = models.CourseMetaSummaryEnrollment
556-
exclude = ('id', 'mode')
556+
# start_date and end_date used instead of start_time and end_time
557+
exclude = ('id', 'start_time', 'end_time', 'enrollment_mode')

analytics_data_api/v0/tests/views/test_course_summaries.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def generate_data(self, course_ids=None, modes=None):
4545
for course_id in course_ids:
4646
for mode in modes:
4747
G(self.model, course_id=course_id, catalog_course_title='Title', catalog_course='Catalog',
48-
start_date=datetime.datetime(2016, 10, 11, tzinfo=pytz.utc),
49-
end_date=datetime.datetime(2016, 12, 18, tzinfo=pytz.utc),
50-
pacing_type='instructor', availability='current', mode=mode,
48+
start_time=datetime.datetime(2016, 10, 11, tzinfo=pytz.utc),
49+
end_time=datetime.datetime(2016, 12, 18, tzinfo=pytz.utc),
50+
pacing_type='instructor', availability='current', enrollment_mode=mode,
5151
count=5, cumulative_count=10, count_change_7_days=1, create=self.now,)
5252

5353
def expected_summary(self, course_id, modes=None):
@@ -67,28 +67,28 @@ def expected_summary(self, course_id, modes=None):
6767
'end_date': datetime.datetime(2016, 12, 18, tzinfo=pytz.utc).strftime(settings.DATETIME_FORMAT),
6868
'pacing_type': 'instructor',
6969
'availability': 'current',
70-
'modes': {},
70+
'enrollment_modes': {},
7171
'count': count_factor * num_modes,
7272
'cumulative_count': cumulative_count_factor * num_modes,
7373
'count_change_7_days': count_change_factor * num_modes,
7474
'created': self.now.strftime(settings.DATETIME_FORMAT),
7575
}
76-
summary['modes'].update({
76+
summary['enrollment_modes'].update({
7777
mode: {
7878
'count': count_factor,
7979
'cumulative_count': cumulative_count_factor,
8080
'count_change_7_days': count_change_factor,
8181
} for mode in modes
8282
})
83-
summary['modes'].update({
83+
summary['enrollment_modes'].update({
8484
mode: {
8585
'count': 0,
8686
'cumulative_count': 0,
8787
'count_change_7_days': 0,
8888
} for mode in set(enrollment_modes.ALL) - set(modes)
8989
})
90-
no_prof = summary['modes'].pop(enrollment_modes.PROFESSIONAL_NO_ID)
91-
prof = summary['modes'].get(enrollment_modes.PROFESSIONAL)
90+
no_prof = summary['enrollment_modes'].pop(enrollment_modes.PROFESSIONAL_NO_ID)
91+
prof = summary['enrollment_modes'].get(enrollment_modes.PROFESSIONAL)
9292
prof.update({
9393
'count': prof['count'] + no_prof['count'],
9494
'cumulative_count': prof['cumulative_count'] + no_prof['cumulative_count'],
@@ -121,7 +121,7 @@ def test_one_course(self, course_id):
121121

122122
@ddt.data(
123123
['availability'],
124-
['modes', 'course_id'],
124+
['enrollment_mode', 'course_id'],
125125
)
126126
def test_fields(self, fields):
127127
self.generate_data()

analytics_data_api/v0/views/course_summaries.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CourseSummariesView(generics.ListAPIView):
3535
* count: The total count of currently enrolled learners across modes.
3636
* cumulative_count: The total cumulative total of all users ever enrolled across modes.
3737
* count_change_7_days: Total difference in enrollment counts over the past 7 days across modes.
38-
* modes: For each enrollment mode, the count, cumulative_count, and count_change_7_days.
38+
* enrollment_modes: For each enrollment mode, the count, cumulative_count, and count_change_7_days.
3939
* created: The date the counts were computed.
4040
4141
**Parameters**
@@ -78,10 +78,10 @@ def default_summary(self, course_id, count_fields):
7878
summary = {
7979
'course_id': course_id,
8080
'created': None,
81-
'modes': {},
81+
'enrollment_modes': {},
8282
}
8383
summary.update({field: 0 for field in count_fields})
84-
summary['modes'].update({
84+
summary['enrollment_modes'].update({
8585
mode: {
8686
count_field: 0 for count_field in count_fields
8787
} for mode in enrollment_modes.ALL
@@ -97,11 +97,11 @@ def group_by_mode(self, queryset):
9797

9898
# aggregate the enrollment counts for each mode
9999
for summary in summaries:
100-
summary_meta_fields = ['catalog_course_title', 'catalog_course', 'start_date', 'end_date',
100+
summary_meta_fields = ['catalog_course_title', 'catalog_course', 'start_time', 'end_time',
101101
'pacing_type', 'availability']
102102
item.update({field: getattr(summary, field) for field in summary_meta_fields})
103-
item['modes'].update({
104-
summary.mode: {field: getattr(summary, field) for field in count_fields}
103+
item['enrollment_modes'].update({
104+
summary.enrollment_mode: {field: getattr(summary, field) for field in count_fields}
105105
})
106106

107107
# treat the most recent as the authoritative created date -- should be all the same
@@ -111,7 +111,7 @@ def group_by_mode(self, queryset):
111111
item.update({field: item[field] + getattr(summary, field) for field in count_fields})
112112

113113
# Merge professional with non verified professional
114-
modes = item['modes']
114+
modes = item['enrollment_modes']
115115
prof_no_id_mode = modes.pop(enrollment_modes.PROFESSIONAL_NO_ID, {})
116116
prof_mode = modes[enrollment_modes.PROFESSIONAL]
117117
for count_key in count_fields:

0 commit comments

Comments
 (0)