Commit 1b4d400c by cjt

lab support

parent 6660646f
...@@ -11,11 +11,12 @@ import calc, eia ...@@ -11,11 +11,12 @@ import calc, eia
from util import contextualize_text from util import contextualize_text
from inputtypes import textline, schematic from inputtypes import textline, schematic
from responsetypes import numericalresponse, formularesponse, customresponse from responsetypes import numericalresponse, formularesponse, customresponse, schematicresponse
response_types = {'numericalresponse':numericalresponse, response_types = {'numericalresponse':numericalresponse,
'formularesponse':formularesponse, 'formularesponse':formularesponse,
'customresponse':customresponse} 'customresponse':customresponse,
'schematicresponse':schematicresponse}
entry_types = ['textline', 'schematic'] entry_types = ['textline', 'schematic']
response_properties = ["responseparam", "answer"] response_properties = ["responseparam", "answer"]
# How to convert from original XML to HTML # How to convert from original XML to HTML
...@@ -23,6 +24,7 @@ response_properties = ["responseparam", "answer"] ...@@ -23,6 +24,7 @@ response_properties = ["responseparam", "answer"]
html_transforms = {'problem': {'tag':'div'}, html_transforms = {'problem': {'tag':'div'},
"numericalresponse": {'tag':'span'}, "numericalresponse": {'tag':'span'},
"customresponse": {'tag':'span'}, "customresponse": {'tag':'span'},
"schematicresponse": {'tag':'span'},
"formularesponse": {'tag':'span'}, "formularesponse": {'tag':'span'},
"text": {'tag':'span'}} "text": {'tag':'span'}}
...@@ -36,7 +38,7 @@ global_context={'random':random, ...@@ -36,7 +38,7 @@ global_context={'random':random,
# These should be removed from HTML output, including all subelements # These should be removed from HTML output, including all subelements
html_problem_semantics = ["responseparam", "answer", "script"] html_problem_semantics = ["responseparam", "answer", "script"]
# These should be removed from HTML output, but keeping subelements # These should be removed from HTML output, but keeping subelements
html_skip = ["numericalresponse", "customresponse", "formularesponse", "text"] html_skip = ["numericalresponse", "customresponse", "schematicresponse", "formularesponse", "text"]
# These should be transformed # These should be transformed
html_special_response = {"textline":textline.render, html_special_response = {"textline":textline.render,
"schematic":schematic.render} "schematic":schematic.render}
......
...@@ -17,7 +17,19 @@ class schematic(object): ...@@ -17,7 +17,19 @@ class schematic(object):
eid = element.get('id') eid = element.get('id')
height = element.get('height') height = element.get('height')
width = element.get('width') width = element.get('width')
context = {'id':eid, 'value':value, 'state':state, 'width':width, 'height':height} parts = element.get('parts')
analyses = element.get('analyses')
initial_value = element.get('initial_value')
context = {
'id':eid,
'value':value,
'initial_value':initial_value,
'state':state,
'width':width,
'height':height,
'parts':parts,
'analyses':analyses,
}
html=render_to_string("schematicinput.html", context) html=render_to_string("schematicinput.html", context)
return etree.XML(html) return etree.XML(html)
......
import random, numpy, math, scipy import random, numpy, math, scipy, json
from util import contextualize_text from util import contextualize_text
from calc import evaluator from calc import evaluator
import random, math import random, math
...@@ -63,7 +63,6 @@ class customresponse(object): ...@@ -63,7 +63,6 @@ class customresponse(object):
# be handled by capa_problem # be handled by capa_problem
return {} return {}
class formularesponse(object): class formularesponse(object):
def __init__(self, xml, context): def __init__(self, xml, context):
self.xml = xml self.xml = xml
...@@ -114,3 +113,28 @@ class formularesponse(object): ...@@ -114,3 +113,28 @@ class formularesponse(object):
def get_answers(self): def get_answers(self):
return {self.answer_id:self.correct_answer} return {self.answer_id:self.correct_answer}
class schematicresponse(object):
def __init__(self, xml, context):
self.xml = xml
self.answer_ids = xml.xpath('//*[@id=$id]//schematic/@id',
id=xml.get('id'))
self.context = context
answer = xml.xpath('//*[@id=$id]//answer',
id=xml.get('id'))[0]
answer_src = answer.get('src')
if answer_src != None:
self.code = open(settings.DATA_DIR+'src/'+answer_src).read()
else:
self.code = answer.text
def grade(self, student_answers):
submission = [json.loads(student_answers[k]) for k in sorted(self.answer_ids)]
self.context.update({'submission':submission})
exec self.code in global_context, self.context
return zip(sorted(self.answer_ids), self.context['correct'])
def get_answers(self):
# Since this is explicitly specified in the problem, this will
# be handled by capa_problem
return {}
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