def all_problem_grade_distribution(request, course_id): """ Creates a json with the grade distribution for all the problems in the course. `Request` django request `course_id` the course ID for the course interested in Returns the format in dashboard_data.get_d3_problem_grade_distrib """ json = {} # Only instructor for this particular course can request this information if has_instructor_access_for_class(request.user, course_id): try: json = dashboard_data.get_d3_problem_grade_distrib(course_id) except Exception as ex: # pylint: disable=broad-except log.error('Generating metrics failed with exception: %s', ex) json = {'error': "error"} else: json = { 'error': "Access Denied: User does not have access to this course's data" } return HttpResponse(simplejson.dumps(json), mimetype="application/json")
def all_problem_grade_distribution(request, course_id, enrollment): """ Creates a json with the grade distribution for all the problems in the course. `Request` django request `course_id` the course ID for the course interested in `enrollment` the number of students enrolled in the course Returns the format in dashboard_data.get_d3_problem_grade_distrib """ data = {} # Only instructor for this particular course can request this information course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) if has_instructor_access_for_class(request.user, course_key): try: data = dashboard_data.get_d3_problem_grade_distrib(course_key, int(enrollment)) except Exception as ex: # pylint: disable=broad-except log.error('Generating metrics failed with exception: %s', ex) data = {'error': "error"} else: data = {'error': "Access Denied: User does not have access to this course's data"} return HttpResponse(json.dumps(data), content_type="application/json")
def test_get_d3_problem_grade_distrib(self): d3_data = get_d3_problem_grade_distrib(self.course.id) for data in d3_data: for stack_data in data['data']: sum_values = 0 for problem in stack_data['stackData']: sum_values += problem['value'] self.assertEquals(USER_COUNT, sum_values)
def test_get_d3_problem_grade_distrib(self, mock_client): mock_client.return_value.modules.return_value.grade_distribution.return_value = [ { 'grade': 1, 'max_grade': 1, 'count': USER_COUNT, }, ] d3_data = get_d3_problem_grade_distrib(self.course.id, USER_COUNT) for data in d3_data: for stack_data in data['data']: sum_values = 0 for problem in stack_data['stackData']: sum_values += problem['value'] self.assertEquals(USER_COUNT, sum_values)
def all_problem_grade_distribution(request, course_id): """ Creates a json with the grade distribution for all the problems in the course. `Request` django request `course_id` the course ID for the course interested in Returns the format in dashboard_data.get_d3_problem_grade_distrib """ json = {} # Only instructor for this particular course can request this information if has_instructor_access_for_class(request.user, course_id): try: json = dashboard_data.get_d3_problem_grade_distrib(course_id) except Exception as ex: # pylint: disable=broad-except log.error('Generating metrics failed with exception: %s', ex) json = {'error': "error"} else: json = {'error': "Access Denied: User does not have access to this course's data"} return HttpResponse(simplejson.dumps(json), mimetype="application/json")