def remark_exam(exam, student): """Re-mark the exam using the latest marking. """ qtemplates = Exams.get_qts(exam) examtotal = 0.0 end = Exams.get_mark_time(exam, student) for qtemplate in qtemplates: question = DB.get_exam_q_by_qt_student(exam, qtemplate, student) answers = DB.get_q_guesses_before_time(question, end) try: marks = mark_q(question, answers) except OaMarkerError: L.warn("Marker Error, question %d while re-marking exam %s for student %s!" % (question, exam, student)) 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['C%d' % part] == 'Correct': marks['C%d' % part] = "<b><font color='darkgreen'>Correct</font></b>" try: mark = float(marks['M%d' % part]) except (ValueError, TypeError, KeyError): mark = 0 total += mark DB.update_q_score(question, total) # OaDB.setQuestionStatus(question, 3) # 3 = marked examtotal += total Exams.save_score(exam, student, examtotal) return examtotal
def remark_exam(exam, student): """Re-mark the exam using the latest marking. """ qtemplates = Exams.get_qts(exam) examtotal = 0.0 end = Exams.get_mark_time(exam, student) for qtemplate in qtemplates: question = DB.get_exam_q_by_qt_student(exam, qtemplate, student) answers = DB.get_q_guesses_before_time(question, end) try: marks = mark_q(question, answers) except OaMarkerError: L.warn( "Marker Error, question %d while re-marking exam %s for student %s!" % (question, exam, student)) 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['C%d' % part] == 'Correct': marks['C%d' % part] = "<b><font color='darkgreen'>Correct</font></b>" try: mark = float(marks['M%d' % part]) except (ValueError, TypeError, KeyError): mark = 0 total += mark DB.update_q_score(question, total) # OaDB.setQuestionStatus(question, 3) # 3 = marked examtotal += total Exams.save_score(exam, student, examtotal) return examtotal
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
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