diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 4293e60ea3..7338b9c3c3 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -27,6 +27,9 @@ from student.models import CourseEnrollment from bulk_email.models import CourseAuthorization from class_dashboard.dashboard_data import get_section_display_name, get_array_section_has_problem +from analyticsclient.client import RestClient +from analyticsclient.course import Course + from .tools import get_units_with_due_date, title_or_url, bulk_email_is_enabled_for_course from opaque_keys.edx.locations import SlashSeparatedCourseKey @@ -245,6 +248,25 @@ def _section_analytics(course_key, access): 'get_distribution_url': reverse('get_distribution', kwargs={'course_id': course_key.to_deprecated_string()}), 'proxy_legacy_analytics_url': reverse('proxy_legacy_analytics', kwargs={'course_id': course_key.to_deprecated_string()}), } + + if settings.FEATURES.get('ENABLE_ANALYTICS_ACTIVE_COUNT'): + auth_token = settings.ANALYTICS_DATA_TOKEN + base_url = settings.ANALYTICS_DATA_URL + + client = RestClient(base_url=base_url, auth_token=auth_token) + course = Course(client, course_key) + + section_data['active_student_count'] = course.recent_active_user_count['count'] + + def format_date(value): + return value.split('T')[0] + + start = course.recent_active_user_count['interval_start'] + end = course.recent_active_user_count['interval_end'] + + section_data['active_student_count_start'] = format_date(start) + section_data['active_student_count_end'] = format_date(end) + return section_data diff --git a/lms/envs/aws.py b/lms/envs/aws.py index 25369651b3..bd5ee9e0e8 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -343,6 +343,10 @@ if 'DATADOG_API' in AUTH_TOKENS: ANALYTICS_SERVER_URL = ENV_TOKENS.get("ANALYTICS_SERVER_URL") ANALYTICS_API_KEY = AUTH_TOKENS.get("ANALYTICS_API_KEY", "") +# Analytics data source +ANALYTICS_DATA_URL = ENV_TOKENS.get("ANALYTICS_DATA_URL") +ANALYTICS_DATA_TOKEN = AUTH_TOKENS.get("ANALYTICS_DATA_TOKEN", "") + # Zendesk ZENDESK_USER = AUTH_TOKENS.get("ZENDESK_USER") ZENDESK_API_KEY = AUTH_TOKENS.get("ZENDESK_API_KEY") diff --git a/lms/envs/dev.py b/lms/envs/dev.py index e1c68d92e4..999f046271 100644 --- a/lms/envs/dev.py +++ b/lms/envs/dev.py @@ -264,6 +264,10 @@ PIPELINE_SASS_ARGUMENTS = '--debug-info --require {proj_dir}/static/sass/bourbon ANALYTICS_SERVER_URL = "http://127.0.0.1:9000/" ANALYTICS_API_KEY = "" +ANALYTICS_DATA_URL = "http://127.0.0.1:8080" +ANALYTICS_DATA_TOKEN = "" +FEATURES['ENABLE_ANALYTICS_ACTIVE_COUNT'] = True + ##### segment-io ###### # If there's an environment variable set, grab it and turn on Segment.io diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 7d7aabfe0d..a89de22001 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -32,6 +32,16 @@ FEATURES['ENABLE_INSTRUCTOR_EMAIL'] = True # Enable email for all Studio cou FEATURES['REQUIRE_COURSE_EMAIL_AUTH'] = False # Give all courses email (don't require django-admin perms) +########################## ANALYTICS TESTING ######################## + +ANALYTICS_SERVER_URL = "http://127.0.0.1:9000/" +ANALYTICS_API_KEY = "" + +ANALYTICS_DATA_URL = "http://127.0.0.1:8080" +ANALYTICS_DATA_TOKEN = "" +FEATURES['ENABLE_ANALYTICS_ACTIVE_COUNT'] = True + + ################################ DEBUG TOOLBAR ################################ INSTALLED_APPS += ('debug_toolbar',) diff --git a/lms/static/sass/course/instructor/_instructor_2.scss b/lms/static/sass/course/instructor/_instructor_2.scss index 96959814f0..d1c3964d93 100644 --- a/lms/static/sass/course/instructor/_instructor_2.scss +++ b/lms/static/sass/course/instructor/_instructor_2.scss @@ -766,3 +766,12 @@ section.instructor-dashboard-content-2 { input[name="subject"] { width:600px; } + +.enrollment-wrapper { + margin-bottom: $baseline * 2; + + .count { + color: green; + font-weight: bold; + } +} diff --git a/lms/templates/instructor/instructor_dashboard_2/analytics.html b/lms/templates/instructor/instructor_dashboard_2/analytics.html index b06b2c7501..44fae53dcb 100644 --- a/lms/templates/instructor/instructor_dashboard_2/analytics.html +++ b/lms/templates/instructor/instructor_dashboard_2/analytics.html @@ -15,6 +15,18 @@ +%if settings.FEATURES.get('ENABLE_ANALYTICS_ACTIVE_COUNT'): +