Commit 8030bce0 by ichuang Committed by Matthew Mongeau

bugfixes - correctmap should reinit self.cmap on init

parent 70e942fe
......@@ -200,6 +200,7 @@ class LoncapaProblem(object):
self.student_answers = answers
oldcmap = self.correct_map # old CorrectMap
newcmap = CorrectMap() # start new with empty CorrectMap
log.debug('Responders: %s' % self.responders)
for responder in self.responders.values():
results = responder.evaluate_answers(answers,oldcmap) # call the responsetype instance to do the actual grading
newcmap.update(results)
......
......@@ -17,11 +17,17 @@ class CorrectMap(object):
Behaves as a dict.
'''
cmap = {}
def __init__(self,*args,**kwargs):
self.cmap = dict() # start with empty dict
self.__getitem__ = self.cmap.__getitem__
self.__iter__ = self.cmap.__iter__
self.items = self.cmap.items
self.keys = self.cmap.keys
self.set(*args,**kwargs)
def __iter__(self):
return self.cmap.__iter__()
def set(self, answer_id=None, correctness=None, npoints=None, msg='', hint='', hintmode=None):
if answer_id is not None:
self.cmap[answer_id] = {'correctness': correctness,
......@@ -47,7 +53,7 @@ class CorrectMap(object):
dict of dicts format.
'''
if correct_map and not (type(correct_map[correct_map.keys()[0]])==dict):
for k in self.cmap.keys(): self.cmap.pop(k) # empty current dict
self.__init__() # empty current dict
for k in correct_map: self.set(k,correct_map[k]) # create new dict entries
else:
self.cmap = correct_map
......@@ -98,9 +104,5 @@ class CorrectMap(object):
raise Exception('CorrectMap.update called with invalid argument %s' % other_cmap)
self.cmap.update(other_cmap.get_dict())
__getitem__ = cmap.__getitem__
__iter__ = cmap.__iter__
items = cmap.items
keys = cmap.keys
......@@ -158,6 +158,7 @@ class LoncapaResponse(object):
'''
new_cmap = self.get_score(student_answers)
self.get_hints(student_answers, new_cmap, old_cmap)
# log.debug('new_cmap = %s' % new_cmap)
return new_cmap
def get_hints(self, student_answers, new_cmap, old_cmap):
......@@ -492,7 +493,7 @@ def sympy_check2():
if cfn in self.context:
self.code = self.context[cfn]
else:
msg = "%s: can't find cfn in context = %s" % (unicode(self),self.context)
msg = "%s: can't find cfn %s in context" % (unicode(self),cfn)
msg += "\nSee XML source line %s" % getattr(self.xml,'sourceline','<unavailable>')
raise LoncapaProblemError(msg)
......@@ -896,7 +897,7 @@ class FormulaResponse(LoncapaResponse):
given,
cs = self.case_sensitive)
except UndefinedVariable as uv:
log.debbug('formularesponse: undefined variable in given=%s' % given)
log.debug('formularesponse: undefined variable in given=%s' % given)
raise StudentInputError(uv.message+" not permitted in answer")
except Exception, err:
#traceback.print_exc()
......
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