def get_problem_grade_distribution(course_id):
 db_query = models.StudentModule.objects.filter(course_id__exact=course_id, grade__isnull=False, module_type__exact='problem').values('module_state_key', 'grade', 'max_grade').annotate(count_grade=Count('grade'))
 prob_grade_distrib = {}
 total_student_count = {}
 for row in db_query:
  curr_problem = course_id.make_usage_key_from_deprecated_string(row['module_state_key'])
  if (curr_problem in prob_grade_distrib):
   prob_grade_distrib[curr_problem]['grade_distrib'].append((row['grade'], row['count_grade']))
   if ((prob_grade_distrib[curr_problem]['max_grade'] != row['max_grade']) and (prob_grade_distrib[curr_problem]['max_grade'] < row['max_grade'])):
    prob_grade_distrib[curr_problem]['max_grade'] = row['max_grade']
  else:
   prob_grade_distrib[curr_problem] = {'max_grade': row['max_grade'], 'grade_distrib': [(row['grade'], row['count_grade'])]}
  total_student_count[curr_problem] = (total_student_count.get(curr_problem, 0) + row['count_grade'])
 return (prob_grade_distrib, total_student_count)

def get_problem_grade_distribution ( course_id ) : db_query = models . StudentModule . objects . filter ( course_id__exact = course_id , grade__isnull = False , module_type__exact = 'problem' ) . values ( 'module_state_key' , 'grade' , 'max_grade' ) . annotate ( count_grade = Count ( 'grade' ) ) prob_grade_distrib = { } total_student_count = { } for row in db_query : curr_problem = course_id . make_usage_key_from_deprecated_string ( row [ 'module_state_key' ] ) if ( curr_problem in prob_grade_distrib ) : prob_grade_distrib [ curr_problem ] [ 'grade_distrib' ] . append ( ( row [ 'grade' ] , row [ 'count_grade' ] ) ) if ( ( prob_grade_distrib [ curr_problem ] [ 'max_grade' ] != row [ 'max_grade' ] ) and ( prob_grade_distrib [ curr_problem ] [ 'max_grade' ] < row [ 'max_grade' ] ) ) : prob_grade_distrib [ curr_problem ] [ 'max_grade' ] = row [ 'max_grade' ] else : prob_grade_distrib [ curr_problem ] = { 'max_grade' : row [ 'max_grade' ] , 'grade_distrib' : [ ( row [ 'grade' ] , row [ 'count_grade' ] ) ] } total_student_count [ curr_problem ] = ( total_student_count . get ( curr_problem , 0 ) + row [ 'count_grade' ] ) return ( prob_grade_distrib , total_student_count )
returns the grade distribution per problem for the course course_id the course id for the course interested in output is 2 dicts: prob-grade_distrib where the key is the problem module_id and the value is a dict with: max_grade - max grade for this problem grade_distrib - array of tuples .