From a9d3736cfbbed09e3ad9b9bcee30530b7f63bc92 Mon Sep 17 00:00:00 2001 From: jmvt Date: Wed, 16 Jan 2013 15:09:54 -0500 Subject: [PATCH] Replace all calls to analytics service to use the get methods (pulls from mongodb). Added error handling. --- lms/djangoapps/instructor/views.py | 36 ++-- .../courseware/instructor_dashboard.html | 166 +++++++++++------- 2 files changed, 129 insertions(+), 73 deletions(-) diff --git a/lms/djangoapps/instructor/views.py b/lms/djangoapps/instructor/views.py index 37fd133590..6c59200786 100644 --- a/lms/djangoapps/instructor/views.py +++ b/lms/djangoapps/instructor/views.py @@ -289,31 +289,43 @@ def instructor_dashboard(request, course_id): from_day = to_day - timedelta(days=7) # WARNING: do not use req.json because the preloaded json doesn't preserve the order of the original record + # use instead: json.loads(req.content, object_pairs_hook=OrderedDict) # number of students enrolled in this course - req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=StudentsEnrolled&course_id=%s" % course_id) - students_enrolled_json = json.loads(req.content, object_pairs_hook=OrderedDict) + req = requests.get(settings.ANALYTICS_SERVER_URL + "get?aname=StudentsEnrolled&course_id=%s" % course_id) + if req.content != 'None': + students_enrolled_json = json.loads(req.content, object_pairs_hook=OrderedDict) # number of students active in the past 7 days (including current day), i.e. with at least one activity for the period #req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=StudentsActive&course_id=%s&from=%s" % (course_id,from_day)) - req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=StudentsActive&course_id=%s" % (course_id,)) # default is active past 7 days - students_active_json = json.loads(req.content, object_pairs_hook=OrderedDict) + req = requests.get(settings.ANALYTICS_SERVER_URL + "get?aname=StudentsActive&course_id=%s" % (course_id,)) # default is active past 7 days + if req.content != 'None': + students_active_json = json.loads(req.content, object_pairs_hook=OrderedDict) # number of students per problem who have problem graded correct - req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=StudentsPerProblemCorrect&course_id=%s&from=%s" % (course_id,from_day)) - students_per_problem_correct_json = json.loads(req.content, object_pairs_hook=OrderedDict) + req = requests.get(settings.ANALYTICS_SERVER_URL + "get?aname=StudentsPerProblemCorrect&course_id=%s" % (course_id,)) + if req.content != 'None': + students_per_problem_correct_json = json.loads(req.content, object_pairs_hook=OrderedDict) + + # number of students per problem who have problem graded correct <<< THIS IS FOR ACTIVE STUDENTS +# req = requests.get(settings.ANALYTICS_SERVER_URL + "get?aname=StudentsPerProblemCorrect&course_id=%s&from=%s" % (course_id,from_day)) +# if req.content != 'None': +# students_per_problem_correct_json = json.loads(req.content, object_pairs_hook=OrderedDict) # grade distribution for the course +++ this is not the desired distribution +++ - req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=OverallGradeDistribution&course_id=%s" % (course_id,)) - overall_grade_distribution = json.loads(req.content, object_pairs_hook=OrderedDict) + req = requests.get(settings.ANALYTICS_SERVER_URL + "get?aname=OverallGradeDistribution&course_id=%s" % (course_id,)) + if req.content != 'None': + overall_grade_distribution = json.loads(req.content, object_pairs_hook=OrderedDict) # number of students distribution drop off per day - req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=StudentsDropoffPerDay&course_id=%s&from=%s" % (course_id,from_day)) - dropoff_per_day = json.loads(req.content, object_pairs_hook=OrderedDict) + req = requests.get(settings.ANALYTICS_SERVER_URL + "get?aname=StudentsDropoffPerDay&course_id=%s&from=%s" % (course_id,from_day)) + if req.content != 'None': + dropoff_per_day = json.loads(req.content, object_pairs_hook=OrderedDict) # number of students per problem who attempted this problem at least once - req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=StudentsAttemptedProblems&course_id=%s" % course_id) - attempted_problems = json.loads(req.content, object_pairs_hook=OrderedDict) + req = requests.get(settings.ANALYTICS_SERVER_URL + "get?aname=StudentsAttemptedProblems&course_id=%s" % course_id) + if req.content != 'None': + attempted_problems = json.loads(req.content, object_pairs_hook=OrderedDict) # number of students active in the past 7 days (including current day) --- online version! experimental diff --git a/lms/templates/courseware/instructor_dashboard.html b/lms/templates/courseware/instructor_dashboard.html index 94d05792f3..29f1602721 100644 --- a/lms/templates/courseware/instructor_dashboard.html +++ b/lms/templates/courseware/instructor_dashboard.html @@ -218,10 +218,29 @@ function goto( mode) %if modeflag.get('Analytics'):

- Number of students enrolled: ${students_enrolled_json['data']['value']} + Number of students enrolled: + % if students_enrolled_json is not None: + % if students_enrolled_json['status'] == 'success': + ${students_enrolled_json['data']['value']} + % else: + ${students_enrolled_json['error']} + % endif + % else: + null data + % endif

+

- Number of active students for the past 7 days: ${students_active_json['data']['value']} + Number of active students for the past 7 days: + % if students_active_json is not None: + % if students_active_json['status'] == 'success': + ${students_active_json['data']['value']} + % else: + ${students_active_json['error']} + % endif + % else: + null data + % endif

@@ -253,78 +272,103 @@ function goto( mode) -

Number of active students per problems who have this problem graded as correct:

+ % if students_per_problem_correct_json is not None: + % if students_per_problem_correct_json['status'] == 'success': +
- + % for k,v in students_per_problem_correct_json['data'].items(): - - - - % endfor -
ProblemNumber of students
ProblemNumber of students
${k} ${v}
-

- -

-

Grade distribution:

- -
- - - % for k,v in overall_grade_distribution['data'].items(): - - - + % endfor
GradeNumber of students
${k} ${v}
${k} ${v}
- + % else: + ${students_per_problem_correct_json['error']} + % endif + % else: + null data + % endif

-

-

Number of students who dropped off per day before becoming inactive:

+##

+##

Students who attempted at least one exercise:

+## +## % if attempted_problems is not None: +## % if attempted_problems['status'] == 'success': +##
+## +## +## % for k,v in attempted_problems['data'].items(): +## +## % endfor +##
ModuleNumber of students
${k} ${v}
+##
+## % else: +## ${attempted_problems['error']} +## % endif +## % else: +## null data +## % endif +##

+## +##

+##

Number of students who dropped off per day before becoming inactive:

+## +## % if dropoff_per_day is not None: +## % if dropoff_per_day['status'] == 'success': +##
+## +## +## % for k,v in dropoff_per_day['data'].items(): +## +## % endfor +##
DayNumber of students
${k} ${v}
+##
+## % else: +## ${dropoff_per_day['error']} +## % endif +## % else: +## null data +## % endif +##

+## +##

+##

Grade distribution:

+## +## % if overall_grade_distribution is not None: +## % if overall_grade_distribution['status'] == 'success': +##
+## +## +## % for k,v in overall_grade_distribution['data'].items(): +## +## % endfor +##
GradeNumber of students
${k} ${v}
+##
+## % else: +## ${dropoff_per_day['error']} +## % endif +## % else: +## null data +## % endif +##

-
- - - % for k,v in dropoff_per_day['data'].items(): - - - - % endfor -
DayNumber of students
${k} ${v}
-
-

-

-

Students who attempted at least one exercise:

+##

+##

Daily activity (online version):

+## +## +## % for k,v in daily_activity_json['data'].items(): +## +## +## +## % endfor +##
DayNumber of students
${k} ${v}
+##

-
- - - % for k,v in attempted_problems['data'].items(): - - - - % endfor -
ModuleNumber of students
${k} ${v}
-
- -

- -

-

Daily activity (online version):

- - - % for k,v in daily_activity_json['data'].items(): - - - - % endfor -
DayNumber of students
${k} ${v}
-

%endif