def extract(self, site, date_for=None, **kwargs): # pylint: disable=unused-argument ''' We get the count from the User model since there can be registered users who have not enrolled. TODO: Exclude non-students from the user count ''' if not date_for: date_for = prev_day( datetime.datetime.utcnow().replace(tzinfo=utc).date()) data = dict() site_users = get_users_for_site(site) user_count = site_users.filter( date_joined__lt=as_datetime(next_day(date_for))).count() site_courses = get_courses_for_site(site) course_count = site_courses.filter( created__lt=as_datetime(next_day(date_for))).count() todays_active_users = get_site_active_users_for_date(site, date_for) todays_active_user_count = todays_active_users.count() mau = site_mau_1g_for_month_as_of_day(site, date_for) data['todays_active_user_count'] = todays_active_user_count data[ 'cumulative_active_user_count'] = get_previous_cumulative_active_user_count( site, date_for) + todays_active_user_count data['total_user_count'] = user_count data['course_count'] = course_count data['total_enrollment_count'] = get_total_enrollment_count( site, date_for) data['mau'] = mau.count() return data
def missing_course_daily_metrics(site, date_for): ''' Return a list of course ids for any courses missing from the set of CourseDailyMetrics for the given date (and site after we implement multi- tenancy) The type returned is CourseLocator We use this to make sure that we are not missing course data when we populat the SiteDailyMetrics instance for the given date ''' cdm_course_keys = [ as_course_key(cdm.course_id) for cdm in CourseDailyMetrics.objects.filter(site=site, date_for=date_for) ] site_course_overviews = get_courses_for_site(site) course_overviews = site_course_overviews.filter( created__lt=as_datetime(next_day(date_for))).exclude( id__in=cdm_course_keys) return set(course_overviews.values_list('id', flat=True))