def get_problem_set_grade_distrib(course_id, problem_set):
 db_query = models.StudentModule.objects.filter(course_id__exact=course_id, grade__isnull=False, module_type__exact='problem', module_state_key__in=problem_set).values('module_state_key', 'grade', 'max_grade').annotate(count_grade=Count('grade')).order_by('module_state_key', 'grade')
 prob_grade_distrib = {}
 for row in db_query:
  row_loc = course_id.make_usage_key_from_deprecated_string(row['module_state_key'])
  if (row_loc not in prob_grade_distrib):
   prob_grade_distrib[row_loc] = {'max_grade': 0, 'grade_distrib': []}
  curr_grade_distrib = prob_grade_distrib[row_loc]
  curr_grade_distrib['grade_distrib'].append((row['grade'], row['count_grade']))
  if (curr_grade_distrib['max_grade'] < row['max_grade']):
   curr_grade_distrib['max_grade'] = row['max_grade']
 return prob_grade_distrib

def get_problem_set_grade_distrib ( course_id , problem_set ) : db_query = models . StudentModule . objects . filter ( course_id__exact = course_id , grade__isnull = False , module_type__exact = 'problem' , module_state_key__in = problem_set ) . values ( 'module_state_key' , 'grade' , 'max_grade' ) . annotate ( count_grade = Count ( 'grade' ) ) . order_by ( 'module_state_key' , 'grade' ) prob_grade_distrib = { } for row in db_query : row_loc = course_id . make_usage_key_from_deprecated_string ( row [ 'module_state_key' ] ) if ( row_loc not in prob_grade_distrib ) : prob_grade_distrib [ row_loc ] = { 'max_grade' : 0 , 'grade_distrib' : [ ] } curr_grade_distrib = prob_grade_distrib [ row_loc ] curr_grade_distrib [ 'grade_distrib' ] . append ( ( row [ 'grade' ] , row [ 'count_grade' ] ) ) if ( curr_grade_distrib [ 'max_grade' ] < row [ 'max_grade' ] ) : curr_grade_distrib [ 'max_grade' ] = row [ 'max_grade' ] return prob_grade_distrib
returns the grade distribution for the problems specified in problem_set .