Commit e49fd700 by Lyla Fischer

respones to code review

parent bfff8222
...@@ -83,7 +83,6 @@ def grade_sheet(student): ...@@ -83,7 +83,6 @@ def grade_sheet(student):
graded = True if s.get('graded') == "true" else False graded = True if s.get('graded') == "true" else False
scores=[] scores=[]
weighted=False
if len(problems)>0: if len(problems)>0:
for p in problems: for p in problems:
(correct,total) = get_grade(student, p, response_by_id) (correct,total) = get_grade(student, p, response_by_id)
...@@ -101,33 +100,9 @@ def grade_sheet(student): ...@@ -101,33 +100,9 @@ def grade_sheet(student):
correct = random.randrange( max(total-2, 1) , total + 1 ) correct = random.randrange( max(total-2, 1) , total + 1 )
else: else:
correct = total correct = total
if p.get("weight"): scores.append( Score(int(correct),total, float(p.get("weight", 1)), graded, p.get("name")) )
weighted=True
scores.append( Score(int(correct),total, p.get("weight", 1), graded, p.get("name")) ) section_total, graded_total = aggregate_scores(scores)
if weighted:
total_correct_graded = sum([(score.earned*1.0/score.possible)*int(score.weight) for score in scores if score.graded])
total_possible_graded = sum([int(score.weight) for score in scores if score.graded])
total_correct = sum([(score.earned*1.0/score.possible)*int(score.weight) for score in scores])
total_possible = sum([int(score.weight) for score in scores])
section_weight = s.get("weight", 1)
else:
total_correct_graded=sum([score.earned for score in scores if score.graded])
total_possible_graded=sum([score.possible for score in scores if score.graded])
total_correct = sum([score.earned for score in scores])
total_possible = sum([score.possible for score in scores])
section_weight = None
#regardless of whether or not it is graded
section_total = Score(total_correct,
total_possible,
section_weight,
False,
p.get("id"))
#selecting only graded things
graded_total = Score(total_correct_graded,
total_possible_graded,
section_weight,
True,
p.get("id"))
#Add the graded total to totaled_scores #Add the graded total to totaled_scores
format = s.get('format') if s.get('format') else "" format = s.get('format') if s.get('format') else ""
subtitle = s.get('subtitle') if s.get('subtitle') else format subtitle = s.get('subtitle') if s.get('subtitle') else format
...@@ -155,6 +130,25 @@ def grade_sheet(student): ...@@ -155,6 +130,25 @@ def grade_sheet(student):
'grade_summary' : grade_summary, #graded assessments only 'grade_summary' : grade_summary, #graded assessments only
} }
def aggregate_scores(scores):
total_correct_graded = sum((score.earned*1.0/score.possible)*score.weight for score in scores if score.graded)
total_possible_graded = sum(score.weight for score in scores if score.graded)
total_correct = sum((score.earned*1.0/score.possible)*score.weight for score in scores)
total_possible = sum(score.weight for score in scores)
#regardless of whether or not it is graded
all_total = Score(total_correct,
total_possible,
1,
False,
"summary")
#selecting only graded things
graded_total = Score(total_correct_graded,
total_possible_graded,
1,
True,
"summary")
return all_total, graded_total
def grade_summary_6002x(totaled_scores): def grade_summary_6002x(totaled_scores):
""" """
......
...@@ -71,7 +71,9 @@ class Module(XModule): ...@@ -71,7 +71,9 @@ class Module(XModule):
def get_problem_html(self, encapsulate=True): def get_problem_html(self, encapsulate=True):
html = self.lcp.get_html() html = self.lcp.get_html()
content={'name':self.name, content={'name':self.name,
'html':html} 'html':html,
'weight': self.weight,
}
# We using strings as truthy values, because the terminology of the check button # We using strings as truthy values, because the terminology of the check button
# is context-specific. # is context-specific.
...@@ -136,7 +138,7 @@ class Module(XModule): ...@@ -136,7 +138,7 @@ class Module(XModule):
self.max_attempts = None self.max_attempts = None
dom2 = etree.fromstring(xml) dom2 = etree.fromstring(xml)
self.explanation=content_parser.item(dom2.xpath('/problem/@explain'), default="closed") self.explanation=content_parser.item(dom2.xpath('/problem/@explain'), default="closed")
self.explain_available=content_parser.item(dom2.xpath('/problem/@explain_available')) self.explain_available=content_parser.item(dom2.xpath('/problem/@explain_available'))
...@@ -186,6 +188,7 @@ class Module(XModule): ...@@ -186,6 +188,7 @@ class Module(XModule):
self.filename=content_parser.item(dom2.xpath('/problem/@filename')) self.filename=content_parser.item(dom2.xpath('/problem/@filename'))
filename=settings.DATA_DIR+"/problems/"+self.filename+".xml" filename=settings.DATA_DIR+"/problems/"+self.filename+".xml"
self.name=content_parser.item(dom2.xpath('/problem/@name')) self.name=content_parser.item(dom2.xpath('/problem/@name'))
self.weight=content_parser.item(dom2.xpath('/problem/@weight'))
if self.rerandomize == 'never': if self.rerandomize == 'never':
seed = 1 seed = 1
else: else:
......
...@@ -4,6 +4,7 @@ import numpy ...@@ -4,6 +4,7 @@ import numpy
import courseware.modules import courseware.modules
import courseware.capa.calc as calc import courseware.capa.calc as calc
from grades import Score, aggregate_scores
class ModelsTest(unittest.TestCase): class ModelsTest(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -53,3 +54,35 @@ class ModelsTest(unittest.TestCase): ...@@ -53,3 +54,35 @@ class ModelsTest(unittest.TestCase):
exception_happened = True exception_happened = True
self.assertTrue(exception_happened) self.assertTrue(exception_happened)
class GraderTest(unittest.TestCase):
def test_weighted_grading(self):
scores = []
all, graded = aggregate_scores(scores)
self.assertTrue(all.earned == 0)
self.assertTrue(graded.earned == 0)
self.assertTrue(all.possible == 0)
self.assertTrue(graded.possible == 0)
scores.append(Score(0,5,1,False, 'foo'))
all, graded = aggregate_scores(scores)
self.assertTrue(all.earned == 0)
self.assertTrue(graded.earned == 0)
print all
self.assertTrue(all.possible == 1)
self.assertTrue(graded.possible == 0)
scores.append(Score(3,5,1,True, 'foo'))
all, graded = aggregate_scores(scores)
self.assertTrue(all.earned == 3.0/5)
self.assertTrue(graded.earned == 3.0/5)
self.assertTrue(all.possible == 2)
self.assertTrue(graded.possible == 1)
scores.append(Score(2,5,2,True, 'foo'))
all, graded = aggregate_scores(scores)
self.assertTrue(all.earned == 7.0/5)
self.assertTrue(graded.earned == 7.0/5)
self.assertTrue(all.possible == 4)
self.assertTrue(graded.possible == 3)
<h2>${ problem['name'] }</h2> <h2 class="problem-header">${ problem['name'] }
% if problem['weight']:
: ${ problem['weight'] } points
% endif
</h2>
<section class="problem"> <section class="problem">
${ problem['html'] } ${ problem['html'] }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment