1212from analytics_data_api .utils import date_range
1313
1414
15- class CourseActivityWeekly (models .Model ):
16- """A count of unique users who performed a particular action during a week."""
15+ class BaseCourseModel (models .Model ):
16+ course_id = models .CharField (db_index = True , max_length = 255 )
17+ created = models .DateTimeField (auto_now_add = True )
1718
1819 class Meta (object ):
20+ abstract = True
21+
22+
23+ class CourseActivityWeekly (BaseCourseModel ):
24+ """A count of unique users who performed a particular action during a week."""
25+
26+ class Meta (BaseCourseModel .Meta ):
1927 db_table = 'course_activity'
2028 index_together = [['course_id' , 'activity_type' ]]
2129 ordering = ('interval_end' , 'interval_start' , 'course_id' )
2230 get_latest_by = 'interval_end'
2331
24- course_id = models .CharField (db_index = True , max_length = 255 )
2532 interval_start = models .DateTimeField ()
2633 interval_end = models .DateTimeField (db_index = True )
2734 activity_type = models .CharField (db_index = True , max_length = 255 , db_column = 'label' )
2835 count = models .IntegerField ()
29- created = models .DateTimeField (auto_now_add = True )
3036
3137 @classmethod
3238 def get_most_recent (cls , course_id , activity_type ):
3339 """Activity for the week that was mostly recently computed."""
3440 return cls .objects .filter (course_id = course_id , activity_type = activity_type ).latest ('interval_end' )
3541
3642
37- class BaseCourseEnrollment (models .Model ):
38- course_id = models .CharField (max_length = 255 )
43+ class BaseCourseEnrollment (BaseCourseModel ):
3944 date = models .DateField (null = False , db_index = True )
4045 count = models .IntegerField (null = False )
41- created = models .DateTimeField (auto_now_add = True )
4246
43- class Meta (object ):
47+ class Meta (BaseCourseModel . Meta ):
4448 abstract = True
4549 get_latest_by = 'date'
4650 index_together = [('course_id' , 'date' ,)]
@@ -63,6 +67,24 @@ class Meta(BaseCourseEnrollment.Meta):
6367 unique_together = [('course_id' , 'date' , 'mode' )]
6468
6569
70+ class CourseMetaSummaryEnrollment (BaseCourseModel ):
71+ catalog_course_title = models .CharField (db_index = True , max_length = 255 )
72+ catalog_course = models .CharField (db_index = True , max_length = 255 )
73+ start_date = models .DateTimeField ()
74+ end_date = models .DateTimeField ()
75+ pacing_type = models .CharField (db_index = True , max_length = 255 )
76+ availability = models .CharField (db_index = True , max_length = 255 )
77+ mode = models .CharField (max_length = 255 )
78+ count = models .IntegerField (null = False )
79+ cumulative_count = models .IntegerField (null = False )
80+ count_change_7_days = models .IntegerField (default = 0 )
81+
82+ class Meta (BaseCourseModel .Meta ):
83+ db_table = 'course_meta_summary_enrollment'
84+ ordering = ('course_id' ,)
85+ unique_together = [('course_id' , 'mode' ,)]
86+
87+
6688class CourseEnrollmentByBirthYear (BaseCourseEnrollment ):
6789 birth_year = models .IntegerField (null = False )
6890
@@ -103,14 +125,13 @@ class Meta(BaseCourseEnrollment.Meta):
103125 unique_together = [('course_id' , 'date' , 'gender' )]
104126
105127
106- class BaseProblemResponseAnswerDistribution (models . Model ):
128+ class BaseProblemResponseAnswerDistribution (BaseCourseModel ):
107129 """ Base model for the answer_distribution table. """
108130
109- class Meta (object ):
131+ class Meta (BaseCourseModel . Meta ):
110132 db_table = 'answer_distribution'
111133 abstract = True
112134
113- course_id = models .CharField (db_index = True , max_length = 255 )
114135 module_id = models .CharField (db_index = True , max_length = 255 )
115136 part_id = models .CharField (db_index = True , max_length = 255 )
116137 correct = models .NullBooleanField ()
@@ -119,7 +140,6 @@ class Meta(object):
119140 variant = models .IntegerField (null = True )
120141 problem_display_name = models .TextField (null = True )
121142 question_text = models .TextField (null = True )
122- created = models .DateTimeField (auto_now_add = True )
123143
124144
125145class ProblemResponseAnswerDistribution (BaseProblemResponseAnswerDistribution ):
@@ -131,19 +151,17 @@ class Meta(BaseProblemResponseAnswerDistribution.Meta):
131151 count = models .IntegerField ()
132152
133153
134- class ProblemsAndTags (models . Model ):
154+ class ProblemsAndTags (BaseCourseModel ):
135155 """ Model for the tags_distribution table """
136156
137- class Meta (object ):
157+ class Meta (BaseCourseModel . Meta ):
138158 db_table = 'tags_distribution'
139159
140- course_id = models .CharField (db_index = True , max_length = 255 )
141160 module_id = models .CharField (db_index = True , max_length = 255 )
142161 tag_name = models .CharField (max_length = 255 )
143162 tag_value = models .CharField (max_length = 255 )
144163 total_submissions = models .IntegerField (default = 0 )
145164 correct_submissions = models .IntegerField (default = 0 )
146- created = models .DateTimeField (auto_now_add = True )
147165
148166
149167class ProblemFirstLastResponseAnswerDistribution (BaseProblemResponseAnswerDistribution ):
@@ -172,30 +190,26 @@ class Meta(BaseCourseEnrollment.Meta):
172190 unique_together = [('course_id' , 'date' , 'country_code' )]
173191
174192
175- class GradeDistribution (models . Model ):
193+ class GradeDistribution (BaseCourseModel ):
176194 """ Each row stores the count of a particular grade on a module for a given course. """
177195
178- class Meta (object ):
196+ class Meta (BaseCourseModel . Meta ):
179197 db_table = 'grade_distribution'
180198
181199 module_id = models .CharField (db_index = True , max_length = 255 )
182- course_id = models .CharField (db_index = True , max_length = 255 )
183200 grade = models .IntegerField ()
184201 max_grade = models .IntegerField ()
185202 count = models .IntegerField ()
186- created = models .DateTimeField (auto_now_add = True )
187203
188204
189- class SequentialOpenDistribution (models . Model ):
205+ class SequentialOpenDistribution (BaseCourseModel ):
190206 """ Each row stores the count of views a particular module has had in a given course. """
191207
192- class Meta (object ):
208+ class Meta (BaseCourseModel . Meta ):
193209 db_table = 'sequential_open_distribution'
194210
195211 module_id = models .CharField (db_index = True , max_length = 255 )
196- course_id = models .CharField (db_index = True , max_length = 255 )
197212 count = models .IntegerField ()
198- created = models .DateTimeField (auto_now_add = True )
199213
200214
201215class BaseVideo (models .Model ):
@@ -465,10 +479,9 @@ def get_timeline(self, course_id, username):
465479 return full_timeline
466480
467481
468- class ModuleEngagement (models . Model ):
482+ class ModuleEngagement (BaseCourseModel ):
469483 """User interactions with entities within the courseware."""
470484
471- course_id = models .CharField (db_index = True , max_length = 255 )
472485 username = models .CharField (max_length = 255 )
473486 date = models .DateField ()
474487 # This will be one of "problem", "video" or "discussion"
@@ -483,18 +496,17 @@ class ModuleEngagement(models.Model):
483496
484497 objects = ModuleEngagementTimelineManager ()
485498
486- class Meta (object ):
499+ class Meta (BaseCourseModel . Meta ):
487500 db_table = 'module_engagement'
488501
489502
490- class ModuleEngagementMetricRanges (models . Model ):
503+ class ModuleEngagementMetricRanges (BaseCourseModel ):
491504 """
492505 Represents the low and high values for a module engagement entity and event
493506 pair, known as the metric. The range_type will either be low, normal, or
494507 high, bounded by low_value and high_value.
495508 """
496509
497- course_id = models .CharField (db_index = True , max_length = 255 )
498510 start_date = models .DateField ()
499511 # This is a left-closed interval. No data from the end_date is included in the analysis.
500512 end_date = models .DateField ()
@@ -505,5 +517,5 @@ class ModuleEngagementMetricRanges(models.Model):
505517 high_value = models .FloatField ()
506518 low_value = models .FloatField ()
507519
508- class Meta (object ):
520+ class Meta (BaseCourseModel . Meta ):
509521 db_table = 'module_engagement_metric_ranges'
0 commit comments