Example #1
0
 def update_alerts_for_enrollment(cls, sid, term_id, enrollment,
                                  no_activity_alerts_enabled,
                                  infrequent_activity_alerts_enabled):
     for section in enrollment['sections']:
         if section_is_eligible_for_alerts(enrollment=enrollment,
                                           section=section):
             # If the grade is in, what's done is done.
             if section.get('grade'):
                 continue
             if section.get('midtermGrade'):
                 cls.update_midterm_grade_alerts(sid, term_id,
                                                 section['ccn'],
                                                 enrollment['displayName'],
                                                 section['midtermGrade'])
             last_activity = None
             activity_percentile = None
             for canvas_site in enrollment.get('canvasSites', []):
                 student_activity = canvas_site.get('analytics', {}).get(
                     'lastActivity', {}).get('student')
                 if not student_activity or student_activity.get(
                         'roundedUpPercentile') is None:
                     continue
                 raw_epoch = student_activity.get('raw')
                 if last_activity is None or raw_epoch > last_activity:
                     last_activity = raw_epoch
                     activity_percentile = student_activity.get(
                         'roundedUpPercentile')
             if last_activity is None:
                 continue
             if (no_activity_alerts_enabled and last_activity == 0
                     and activity_percentile <=
                     app.config['ALERT_NO_ACTIVITY_PERCENTILE_CUTOFF']):
                 cls.update_no_activity_alerts(sid, term_id,
                                               enrollment['displayName'])
             elif (infrequent_activity_alerts_enabled
                   and last_activity > 0):
                 localized_last_activity = unix_timestamp_to_localtime(
                     last_activity).date()
                 localized_today = unix_timestamp_to_localtime(
                     time.time()).date()
                 days_since = (localized_today -
                               localized_last_activity).days
                 if (days_since >=
                         app.config['ALERT_INFREQUENT_ACTIVITY_DAYS']
                         and activity_percentile <= app.config[
                             'ALERT_INFREQUENT_ACTIVITY_PERCENTILE_CUTOFF']
                     ):
                     cls.update_infrequent_activity_alerts(
                         sid,
                         term_id,
                         enrollment['displayName'],
                         days_since,
                     )
Example #2
0
 def test_unix_timestamp_to_localtime(self):
     """Localizes timestamps."""
     assert util.unix_timestamp_to_localtime(1536300000).year == 2018
     assert util.unix_timestamp_to_localtime(1536300000).month == 9
     assert util.unix_timestamp_to_localtime(1536300000).day == 6
     assert util.unix_timestamp_to_localtime(1536300000).hour == 23
     assert util.unix_timestamp_to_localtime(1536305000).day == 7
     assert util.unix_timestamp_to_localtime(1536305000).hour == 0