本文整理汇总了Python中oasis.lib.DB.add_exam_q方法的典型用法代码示例。如果您正苦于以下问题:Python DB.add_exam_q方法的具体用法?Python DB.add_exam_q怎么用?Python DB.add_exam_q使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.DB
的用法示例。
在下文中一共展示了DB.add_exam_q方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mark_exam
# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import add_exam_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
示例2: gen_q_from_var
# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import add_exam_q [as 别名]
def gen_q_from_var(qt_id, student, exam, position, version, variation):
""" Generate a question given a specific variation. """
qvars = None
q_id = DB.create_q(qt_id,
DB.get_qt_name(qt_id),
student,
1,
variation,
version,
exam)
try:
q_id = int(q_id)
assert (q_id > 0)
except (ValueError, TypeError, AssertionError):
L.error("OaDB.createQuestion(%s,...) FAILED" % qt_id)
imageexists = DB.get_q_att_mimetype(qt_id, "image.gif", variation, version)
if not imageexists:
if not qvars:
qvars = DB.get_qt_variation(qt_id, variation, version)
qvars['Oasis_qid'] = q_id
image = DB.get_qt_att(qt_id, "image.gif", version)
if image:
newimage = gen_q_image(qvars, image)
DB.create_q_att(qt_id,
variation,
"image.gif",
"image/gif",
newimage,
version)
htmlexists = DB.get_q_att_mimetype(qt_id,
"qtemplate.html",
variation,
version)
if not htmlexists:
if not qvars:
qvars = DB.get_qt_variation(qt_id, variation, version)
html = DB.get_qt_att(qt_id, "qtemplate.html", version)
if html:
qvars['Oasis_qid'] = q_id
newhtml = gen_q_html(qvars, html)
L.info("generating new qattach qtemplate.html for %s" % q_id)
DB.create_q_att(qt_id,
variation,
"qtemplate.html",
"application/oasis-html",
newhtml,
version)
try:
q_id = int(q_id)
assert (q_id > 0)
except (ValueError, TypeError, AssertionError):
L.error("generateQuestionFromVar(%s,%s), can't find qid %s? " %
(qt_id, student, q_id))
if exam >= 1:
DB.add_exam_q(student, exam, q_id, position)
return q_id