Added grades SectionPercentage namedtuple. Fixed bug where problem ids were being used for section labels in graph.
This commit is contained in:
@@ -13,6 +13,8 @@ from student.models import UserProfile
|
||||
log = logging.getLogger("mitx.courseware")
|
||||
|
||||
Score = namedtuple("Score", "earned possible graded section")
|
||||
SectionPercentage = namedtuple("SectionPercentage", "percentage label summary")
|
||||
|
||||
|
||||
def get_grade(user, problem, cache):
|
||||
## HACK: assumes max score is fixed per problem
|
||||
@@ -107,12 +109,12 @@ def grade_sheet(student):
|
||||
section_total = Score(sum([score.earned for score in scores]),
|
||||
sum([score.possible for score in scores]),
|
||||
False,
|
||||
p.get("id"))
|
||||
s.get("name"))
|
||||
|
||||
graded_total = Score(sum([score.earned for score in scores if score.graded]),
|
||||
sum([score.possible for score in scores if score.graded]),
|
||||
True,
|
||||
p.get("id"))
|
||||
s.get("name"))
|
||||
|
||||
#Add the graded total to totaled_scores
|
||||
format = s.get('format') if s.get('format') else ""
|
||||
@@ -152,13 +154,13 @@ def grade_summary_6002x(totaled_scores):
|
||||
|
||||
def totalWithDrops(scores, drop_count):
|
||||
#Note that this key will sort the list descending
|
||||
sorted_scores = sorted( enumerate(scores), key=lambda x: -x[1]['percentage'] )
|
||||
sorted_scores = sorted( enumerate(scores), key=lambda x: -x[1].percentage )
|
||||
# A list of the indices of the dropped scores
|
||||
dropped_indices = [score[0] for score in sorted_scores[-drop_count:]]
|
||||
aggregate_score = 0
|
||||
for index, score in enumerate(scores):
|
||||
if index not in dropped_indices:
|
||||
aggregate_score += score['percentage']
|
||||
aggregate_score += score.percentage
|
||||
|
||||
aggregate_score /= len(scores) - drop_count
|
||||
|
||||
@@ -183,7 +185,7 @@ def grade_summary_6002x(totaled_scores):
|
||||
|
||||
label = "HW {0:02d}".format(i + 1)
|
||||
|
||||
homework_percentages.append( {'percentage': percentage, 'summary': summary, 'label' : label} )
|
||||
homework_percentages.append(SectionPercentage(percentage, label, summary) )
|
||||
homework_total, homework_dropped_indices = totalWithDrops(homework_percentages, 2)
|
||||
|
||||
#Figure the lab scores
|
||||
@@ -205,7 +207,7 @@ def grade_summary_6002x(totaled_scores):
|
||||
|
||||
label = "Lab {0:02d}".format(i + 1)
|
||||
|
||||
lab_percentages.append( {'percentage': percentage, 'summary': summary, 'label' : label} )
|
||||
lab_percentages.append(SectionPercentage(percentage, label, summary) )
|
||||
lab_total, lab_dropped_indices = totalWithDrops(lab_percentages, 2)
|
||||
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ $(function() {
|
||||
<%
|
||||
earned = section['section_total'].earned
|
||||
total = section['section_total'].possible
|
||||
percentageString = "{0:.0%}".format( float(earned)/total) if earned > 0 else ""
|
||||
percentageString = "{0:.0%}".format( float(earned)/total) if earned > 0 and total > 0 else ""
|
||||
%>
|
||||
|
||||
<h3><a href="${reverse('courseware_section', args=format_url_params([chapter['course'], chapter['chapter'], section['section']])) }">
|
||||
|
||||
@@ -22,7 +22,7 @@ $(function () {
|
||||
|
||||
<%
|
||||
colors = ["#b72121", "#600101", "#666666", "#333333"]
|
||||
|
||||
#'
|
||||
tickIndex = 1
|
||||
sectionSpacer = 0.5
|
||||
sectionIndex = 0
|
||||
@@ -38,13 +38,13 @@ $(function () {
|
||||
if 'subscores' in section: ##This is for sections like labs or homeworks, with several smaller components and a total
|
||||
series.append({
|
||||
'label' : section['category'],
|
||||
'data' : [[i + tickIndex, score['percentage']] for i,score in enumerate(section['subscores'])],
|
||||
'data' : [[i + tickIndex, score.percentage] for i,score in enumerate(section['subscores'])],
|
||||
'color' : colors[sectionIndex]
|
||||
})
|
||||
|
||||
ticks += [[i + tickIndex, score['label'] ] for i,score in enumerate(section['subscores'])]
|
||||
ticks += [[i + tickIndex, score.label ] for i,score in enumerate(section['subscores'])]
|
||||
bottomTicks.append( [tickIndex + len(section['subscores'])/2, section['category']] )
|
||||
detail_tooltips[ section['category'] ] = [score['summary'] for score in section['subscores']]
|
||||
detail_tooltips[ section['category'] ] = [score.summary for score in section['subscores']]
|
||||
|
||||
droppedScores += [[tickIndex + index, 0.05] for index in section['dropped_indices']]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user