Commit e40b0d0d by JM Van Thong

Fixed data order when loading json record from request.

parent 27b8f01f
......@@ -7,6 +7,8 @@ import os
import urllib
import datetime
from datetime import datetime, timedelta
import json
from collections import OrderedDict
from django.conf import settings
from django.contrib.auth.models import User, Group
......@@ -272,11 +274,10 @@ def instructor_dashboard(request, course_id):
#----------------------------------------
# analytics
analytics_json = None
attempted_problems = None
students_enrolled_json = None
students_active_json = None
daily_activity_json = None
students_daily_activity_json = None
students_per_problem_correct_json = None
overall_grade_distribution = None
dropoff_per_day = None
......@@ -287,29 +288,32 @@ def instructor_dashboard(request, course_id):
to_day = datetime.today().date()
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
# 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 = req.json
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))
students_active_json = req.json
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 = req.json
students_per_problem_correct_json = json.loads(req.content, object_pairs_hook=OrderedDict)
# grade distribution for the course
# 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 = req.json
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 = req.json
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)
# the following is ++incorrect++ use of studentmodule table
req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=StudentsDailyActivity&course_id=%s&from=%s" % (course_id,from_day))
students_daily_activity_json = req.json
# number of students active in the past 7 days (including current day) --- online version! experimental
to_day = datetime.today().date()
......@@ -317,9 +321,6 @@ def instructor_dashboard(request, course_id):
req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=DailyActivityAnalyzer&course_id=%s&from=%s&to=%s" % (course_id,from_day, to_day))
daily_activity_json = req.json
req = requests.get(settings.ANALYTICS_SERVER_URL + "get_analytics?aname=StudentsPerHomework&course_id=%s" % course_id)
analytics_json = req.json
#----------------------------------------
# context for rendering
context = {'course': course,
......@@ -334,14 +335,13 @@ def instructor_dashboard(request, course_id):
'plots': plots, # psychometrics
'course_errors': modulestore().get_item_errors(course.location),
'djangopid' : os.getpid(),
'analytics_json' : analytics_json,
'students_enrolled_json' : students_enrolled_json,
'students_active_json' : students_active_json,
'daily_activity_json' : daily_activity_json,
'students_daily_activity_json' : students_daily_activity_json,
'students_per_problem_correct_json' : students_per_problem_correct_json,
'overall_grade_distribution' : overall_grade_distribution,
'dropoff_per_day' : dropoff_per_day,
'attempted_problems' : attempted_problems,
}
return render_to_response('courseware/instructor_dashboard.html', context)
......
......@@ -177,10 +177,10 @@ function goto( mode)
%if modeflag.get('Analytics'):
<p>
Number of students enrolled: ${students_enrolled_json['data']['nb_students_enrolled']}
Number of students enrolled: ${students_enrolled_json['data']['value']}
</p>
<p>
Number of active students for the past 7 days: ${students_active_json['data']['nb_students_active']}
Number of active students for the past 7 days: ${students_active_json['data']['value']}
</p>
<p>
......@@ -233,7 +233,7 @@ function goto( mode)
<div class="divScroll">
<table class="stat_table">
<tr><th>Module</th><th>Number of students</th></tr>
% for k,v in analytics_json['data'].items():
% for k,v in attempted_problems['data'].items():
<tr>
<td>${k}</td> <td>${v}</td>
</tr>
......@@ -255,18 +255,6 @@ function goto( mode)
</table>
</p>
<p>
<h2>Daily activity for the past 7 days:</h2>
<table class="stat_table">
<tr><th>Day</td><th>Number of students</td></tr>
% for k,v in students_daily_activity_json['data'].items():
<tr>
<td>${k}</td> <td>${v}</td>
</tr>
% endfor
</table>
</p>
%endif
##-----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment