本文整理汇总了Python中oasis.lib.General.mark_q方法的典型用法代码示例。如果您正苦于以下问题:Python General.mark_q方法的具体用法?Python General.mark_q怎么用?Python General.mark_q使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.General
的用法示例。
在下文中一共展示了General.mark_q方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mark_q
# 需要导入模块: from oasis.lib import General [as 别名]
# 或者: from oasis.lib.General import mark_q [as 别名]
def mark_q(user_id, topic_id, q_id, request):
"""Mark the question and return the results"""
answers = {}
for i in request.form.keys():
part = re.search(r"^Q_(\d+)_ANS_(\d+)$", i)
if part:
newqid = int(part.groups()[0])
part = int(part.groups()[1])
if newqid == q_id:
value = request.form[i]
answers["G%d" % part] = value
DB.save_guess(newqid, part, value)
else:
L.warn("received guess for wrong question? (%d,%d,%d,%s)" %
(user_id, topic_id, q_id, request.form))
try:
marks = General.mark_q(q_id, answers)
DB.set_q_status(q_id, 3) # 3 = marked
DB.set_q_marktime(q_id)
except OaMarkerError:
L.warn("Marker Error - (%d, %d, %d, %s)" %
(user_id, topic_id, q_id, request.form))
marks = {}
q_body = General.render_mark_results(q_id, marks)
parts = [int(var[1:])
for var in marks.keys()
if re.search(r"^A([0-9]+)$", var) > 0]
parts.sort()
total = 0.0
for part in parts:
if 'M%d' % (part,) in marks:
total += float(marks['M%d' % (part,)])
DB.update_q_score(q_id, total) # 3 = marked
DB.set_q_status(q_id, 2)
return q_body
示例2: mark_exam
# 需要导入模块: from oasis.lib import General [as 别名]
# 或者: from oasis.lib.General import mark_q [as 别名]
def mark_exam(user_id, exam_id):
""" Submit the assessment and mark it.
Returns True if it went well, or False if a problem.
"""
numquestions = Exams.get_num_questions(exam_id)
status = Exams.get_user_status(user_id, exam_id)
L.info("Marking assessment %s for %s, status is %s" % (exam_id, user_id, status))
examtotal = 0.0
errors = 0
for position in range(1, numquestions + 1):
q_id = General.get_exam_q(exam_id, position, user_id)
if not q_id:
L.critical("Unable to retrieve exam question page %s, exam %s, for user %s" % (position, exam_id, user_id
)
)
errors += 1
continue
answers = DB.get_q_guesses(q_id)
# There's a small chance they got here without ever seeing a question,
# make sure it exists.
DB.add_exam_q(user_id, exam_id, q_id, position)
# First, mark the question
try:
marks = General.mark_q(q_id, answers)
DB.set_q_status(q_id, 3) # 3 = marked
DB.set_q_marktime(q_id)
except OaMarkerError:
L.warn("Marker Error in question %s, exam %s, student %s!" %
(q_id, exam_id, user_id))
return False
parts = [int(var[1:])
for var in marks.keys()
if re.search("^A([0-9]+)$", var) > 0]
parts.sort()
# Then calculate the mark
total = 0.0
for part in parts:
try:
mark = float(marks['M%d' % (part,)])
except (KeyError, ValueError):
mark = 0
total += mark
DB.update_q_score(q_id, total)
examtotal += total
if not errors:
Exams.set_user_status(user_id, exam_id, 5)
Exams.set_submit_time(user_id, exam_id)
Exams.save_score(exam_id, user_id, examtotal)
Exams.touchuserexam(exam_id, user_id)
if errors:
return False
L.info("user %s scored %s total on exam %s" %
(user_id, examtotal, exam_id))
return True
示例3: mark_q
# 需要导入模块: from oasis.lib import General [as 别名]
# 或者: from oasis.lib.General import mark_q [as 别名]
def mark_q(user_id, qtid, request):
"""Mark the question and show a page containing marking results."""
if "OaQID" in request.form:
qid = int(request.form["OaQID"])
else:
qid = None
out = u""
answers = {}
for i in request.form.keys():
part = re.search(r"^Q_(\d+)_ANS_(\d+)$", i)
if part:
newqid = int(part.groups()[0])
part = int(part.groups()[1])
value = request.form[i]
answers["G%d" % part] = value
DB.save_guess(newqid, part, value)
if qid:
try:
marks = General.mark_q(qid, answers)
DB.set_q_status(qid, 3) # 3 = marked
DB.set_q_marktime(qid)
except OaMarkerError:
log(INFO,
"getMarkQuestionPage(%d, %d, %s) Marker ERROR" %
(user_id, qtid, request.form))
marks = {}
out += General.render_mark_results(qid, marks)
parts = [int(var[1:])
for var in marks.keys()
if re.search("^A([0-9]+)$", var) > 0]
parts.sort()
total = 0.0
for part in parts:
if marks.has_key('M%d' % (part,)):
total += float(marks['M%d' % (part,)])
return out
示例4: render_own_marked_exam
# 需要导入模块: from oasis.lib import General [as 别名]
# 或者: from oasis.lib.General import mark_q [as 别名]
def render_own_marked_exam(student, exam):
""" Return a students instance of the exam, with HTML
version of the question,
their answers, and a marking summary.
returns list of questions/marks
[ {'pos': position,
'html': rendered (marked) question,
'marking': [ 'part': part number,
'guess': student guess,
'correct': correct answer,
'mark': (float) mark,
'tolerance': marking tolerance,
'comment': marking comment
]
}, ...
]
"""
questions = General.get_exam_qs(student, exam)
firstview, examsubmit = student_exam_duration(student, exam)
results = []
if not examsubmit:
return [{'pos': 1,
'html': "In Progress",
'marking': {}
}, ], False
examtotal = 0.0
for question in questions:
qtemplate = DB.get_q_parent(question)
answers = DB.get_q_guesses_before_time(question, examsubmit)
pos = DB.get_qt_exam_pos(exam, qtemplate)
marks = General.mark_q(question, answers)
parts = [int(var[1:])
for var in marks.keys()
if re.search("^A([0-9]+$)", var) > 0]
parts.sort()
marking = []
for part in parts:
guess = marks['G%d' % (part,)]
if guess == "None":
guess = None
answer = marks['A%d' % (part,)]
score = marks['M%d' % (part,)]
tolerance = marks['T%d' % (part,)]
comment = marks['C%d' % (part,)]
examtotal += score
marking.append({
'part': part,
'guess': guess,
'correct': answer,
'mark': score,
'tolerance': tolerance,
'comment': comment
})
html = General.render_q_html(question)
results.append({
'pos': pos,
'html': html,
'marking': marking
})
return results, examtotal