From 04221210de954717aeb36f77a3631dabc24b2783 Mon Sep 17 00:00:00 2001 From: Bridger Maxwell Date: Fri, 6 Apr 2012 15:47:21 -0400 Subject: [PATCH] Weighted section grading is mostly working, but the final grade isn't on the graph yet. --- djangoapps/courseware/grades.py | 36 ++++++++++++++++++++++++++++++++- templates/profile_graphs.js | 16 +++++++-------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/djangoapps/courseware/grades.py b/djangoapps/courseware/grades.py index 189ba0e46b..4f3db888ed 100644 --- a/djangoapps/courseware/grades.py +++ b/djangoapps/courseware/grades.py @@ -119,7 +119,36 @@ class FormatWithDropsGrader(CourseGrader): 'section_breakdown' : breakdown, #No grade_breakdown here } + +class WeightedSubsectionsGrader(CourseGrader): + """ + This grader takes a list of tuples containing (grader, section_name, weight) and computes + a final grade by totalling the contribution of each sub grader and weighting it + accordingly. For example, the sections may be + [ (homeworkGrader, "Homework", 0.15), (labGrader, "Labs", 0.15), (midtermGrader, "Midterm", 0.30), (finalGrader, "Final", 0.40) ] + """ + def __init__(self, sections): + self.sections = sections + def grade(self, grade_sheet): + total_percent = 0.0 + section_breakdown = [] + grade_breakdown = [] + + for subgrader, section_name, weight in self.sections: + subgrade_result = subgrader.grade(grade_sheet) + + weightedPercent = subgrade_result['percent'] * weight + section_detail = "{0} = {1:.1%} of a possible {2:.0%}".format(section_name, weightedPercent, weight) + section_category = "{0} - Weighted".format(section_name) + + total_percent += weightedPercent + section_breakdown += subgrade_result['section_breakdown'] + grade_breakdown.append( {'percent' : weightedPercent, 'detail' : section_detail, 'category' : section_category} ) + + return {'percent' : total_percent, + 'section_breakdown' : section_breakdown, + 'grade_breakdown' : grade_breakdown} def get_score(user, problem, cache): @@ -245,8 +274,13 @@ def grade_sheet(student): 'sections' : sections,}) - grader = FormatWithDropsGrader("Homework", 12, 2, "Homework", "Homework {index} - {name} - {percent:.0%} ({earned:g}/{possible:g})", + hwGrader = FormatWithDropsGrader("Homework", 12, 2, "Homework", "Homework {index} - {name} - {percent:.0%} ({earned:g}/{possible:g})", "Unreleased Homework {index} - 0% (?/?)", "HW {index:02d}", "Homework Average = {percent:.0%}", "HW Avg") + + labGrader = FormatWithDropsGrader("Lab", 12, 2, "Labs", "Lab {index} - {name} - {percent:.0%} ({earned:g}/{possible:g})", + "Unreleased Lab {index} - 0% (?/?)", "Lab {index:02d}", "Lab Average = {percent:.0%}", "Lab Avg") + + grader = WeightedSubsectionsGrader( [(hwGrader, "Homework", 0.15), (labGrader, "Labs", 0.15)] ) grade_summary = grader.grade(totaled_scores) diff --git a/templates/profile_graphs.js b/templates/profile_graphs.js index c43c140e60..dad0ee0001 100644 --- a/templates/profile_graphs.js +++ b/templates/profile_graphs.js @@ -19,20 +19,19 @@ $(function () { } /* -------------------------------- Grade detail bars -------------------------------- */ - + <% colors = ["#b72121", "#600101", "#666666", "#333333"] categories = {} - #' + tickIndex = 1 sectionSpacer = 0.5 sectionIndex = 0 - series = [] ticks = [] #These are the indices and x-axis labels for the data bottomTicks = [] #Labels on the bottom detail_tooltips = {} #This an dictionary mapping from 'section' -> array of detail_tooltips - droppedScores = [] #These are the datapoints to indicate assignments which aren't factored into the total score + droppedScores = [] #These are the datapoints to indicate assignments which are not factored into the total score dropped_score_tooltips = [] for section in grade_summary['section_breakdown']: @@ -44,7 +43,7 @@ $(function () { categories[ section['category'] ] = {'label' : section['category'], 'data' : [], 'color' : colors[colorIndex]} - + categoryData = categories[ section['category'] ] categoryData['data'].append( [tickIndex, section['percent']] ) @@ -60,9 +59,10 @@ $(function () { if section.get('prominent', False): tickIndex += sectionSpacer + %> - var series = ${ json.dumps(series) }; + var series = ${ json.dumps( categories.values() ) }; var ticks = ${ json.dumps(ticks) }; var bottomTicks = ${ json.dumps(bottomTicks) }; var detail_tooltips = ${ json.dumps(detail_tooltips) }; @@ -86,9 +86,7 @@ $(function () { var $grade_detail_graph = $("#${graph_div_id}"); if ($grade_detail_graph.length > 0) { var plot = $.plot($grade_detail_graph, series, options); - - var o = plot.pointOffset({x: ${overviewBarX} , y: ${totalScore}}); - $grade_detail_graph.append('
${"{totalscore:.0%}".format(totalscore=totalScore)}
'); + //We need to put back the plotting of the percent here } var previousPoint = null;