Commit 26fc621f by Piotr Mitros

Rerandomize patch merged

parents 83f5b67b 208c4d06
...@@ -53,7 +53,7 @@ html_special_response = {"textline":textline.render, ...@@ -53,7 +53,7 @@ html_special_response = {"textline":textline.render,
"schematic":schematic.render} "schematic":schematic.render}
class LoncapaProblem(object): class LoncapaProblem(object):
def __init__(self, filename, id=None, state=None): def __init__(self, filename, id=None, state=None, seed=None):
## Initialize class variables from state ## Initialize class variables from state
self.seed = None self.seed = None
self.student_answers = dict() self.student_answers = dict()
...@@ -61,6 +61,9 @@ class LoncapaProblem(object): ...@@ -61,6 +61,9 @@ class LoncapaProblem(object):
self.done = False self.done = False
self.filename = filename self.filename = filename
if seed != None:
self.seed = seed
if id: if id:
self.problem_id = id self.problem_id = id
else: else:
...@@ -78,10 +81,14 @@ class LoncapaProblem(object): ...@@ -78,10 +81,14 @@ class LoncapaProblem(object):
if 'done' in state: if 'done' in state:
self.done = state['done'] self.done = state['done']
# print self.seed
# TODO: Does this deplete the Linux entropy pool? Is this fast enough? # TODO: Does this deplete the Linux entropy pool? Is this fast enough?
if not self.seed: if not self.seed:
self.seed=struct.unpack('i', os.urandom(4))[0] self.seed=struct.unpack('i', os.urandom(4))[0]
# print filename, self.seed, seed
## Parse XML file ## Parse XML file
#log.debug(u"LoncapaProblem() opening file {0}".format(filename)) #log.debug(u"LoncapaProblem() opening file {0}".format(filename))
file_text = open(filename).read() file_text = open(filename).read()
......
...@@ -81,7 +81,7 @@ class Module(XModule): ...@@ -81,7 +81,7 @@ class Module(XModule):
# User submitted a problem, and hasn't reset. We don't want # User submitted a problem, and hasn't reset. We don't want
# more submissions. # more submissions.
if self.lcp.done and self.rerandomize: if self.lcp.done and self.rerandomize == "always":
#print "!" #print "!"
check_button = False check_button = False
save_button = False save_button = False
...@@ -95,7 +95,7 @@ class Module(XModule): ...@@ -95,7 +95,7 @@ class Module(XModule):
attempts_str = " ({a}/{m})".format(a=self.attempts, m=self.max_attempts) attempts_str = " ({a}/{m})".format(a=self.attempts, m=self.max_attempts)
# We don't need a "save" button if infinite number of attempts and non-randomized # We don't need a "save" button if infinite number of attempts and non-randomized
if self.max_attempts == None and self.rerandomize == False: if self.max_attempts == None and self.rerandomize != "always":
save_button = False save_button = False
# Check if explanation is available, and if so, give a link # Check if explanation is available, and if so, give a link
...@@ -164,12 +164,12 @@ class Module(XModule): ...@@ -164,12 +164,12 @@ class Module(XModule):
self.show_answer="closed" self.show_answer="closed"
self.rerandomize=content_parser.item(dom2.xpath('/problem/@rerandomize')) self.rerandomize=content_parser.item(dom2.xpath('/problem/@rerandomize'))
if self.rerandomize=="": if self.rerandomize=="" or self.rerandomize=="always" or self.rerandomize=="true":
self.rerandomize=True self.rerandomize="always"
elif self.rerandomize=="false": elif self.rerandomize=="false" or self.rerandomize=="per_student":
self.rerandomize=False self.rerandomize="per_student"
elif self.rerandomize=="true": elif self.rerandomize=="never":
self.rerandomize=True self.rerandomize="never"
else: else:
raise Exception("Invalid rerandomize attribute "+self.rerandomize) raise Exception("Invalid rerandomize attribute "+self.rerandomize)
...@@ -181,7 +181,11 @@ class Module(XModule): ...@@ -181,7 +181,11 @@ 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.lcp=LoncapaProblem(filename, self.item_id, state) if self.rerandomize == 'never':
seed = 1
else:
seed = None
self.lcp=LoncapaProblem(filename, self.item_id, state, seed = seed)
def handle_ajax(self, dispatch, get): def handle_ajax(self, dispatch, get):
if dispatch=='problem_get': if dispatch=='problem_get':
...@@ -270,7 +274,7 @@ class Module(XModule): ...@@ -270,7 +274,7 @@ class Module(XModule):
# Problem submitted. Student should reset before checking # Problem submitted. Student should reset before checking
# again. # again.
if self.lcp.done and self.rerandomize: if self.lcp.done and self.rerandomize == "always":
event_info['failure']='unreset' event_info['failure']='unreset'
self.tracker('save_problem_check_fail', event_info) self.tracker('save_problem_check_fail', event_info)
print "cpdr" print "cpdr"
...@@ -331,7 +335,7 @@ class Module(XModule): ...@@ -331,7 +335,7 @@ class Module(XModule):
# Problem submitted. Student should reset before saving # Problem submitted. Student should reset before saving
# again. # again.
if self.lcp.done and self.rerandomize: if self.lcp.done and self.rerandomize == "always":
event_info['failure']='done' event_info['failure']='done'
self.tracker('save_problem_fail', event_info) self.tracker('save_problem_fail', event_info)
return "Problem needs to be reset prior to save." return "Problem needs to be reset prior to save."
...@@ -364,7 +368,7 @@ class Module(XModule): ...@@ -364,7 +368,7 @@ class Module(XModule):
self.lcp.student_answers = dict() self.lcp.student_answers = dict()
if self.rerandomize: if self.rerandomize == "always":
self.lcp.context=dict() self.lcp.context=dict()
self.lcp.questions=dict() # Detailed info about questions in problem instance. TODO: Should be by id and not lid. self.lcp.questions=dict() # Detailed info about questions in problem instance. TODO: Should be by id and not lid.
self.lcp.seed=None self.lcp.seed=None
......
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