diff --git a/zesje/pregrader.py b/zesje/pregrader.py index 3e2fa51ebbe7b52526f0a60a5aaa6ed663af2ca8..0100cd1fffa9157e4790357f78c38c84ab430e1e 100644 --- a/zesje/pregrader.py +++ b/zesje/pregrader.py @@ -9,7 +9,7 @@ # coupled feedback cannot be deleted -from zesje.database import db, Exam +from zesje.database import db, Exam, Submission def pregrade(exam_token, image): @@ -27,17 +27,21 @@ def pregrade(exam_token, image): pass -def add_feedback_to_solution(solution, image): - problem = solution.problem +def add_feedback_to_solution(image, barcode): + exam = Exam.query.filter(Exam.token == barcode.token).first() + sub = Submission.query.filter(Submission.copy_number == barcode.copy, Submission.exam_id == exam.id).one_or_none() - for mc_option in problem.mc_options: - box = (mc_option.x, mc_option.y) + for solution in sub.solutions: + problem = solution.problem - # check width and so forth + for mc_option in problem.mc_options: + box = (mc_option.x, mc_option.y) - if box_is_filled(box, image): - solution.feedback = mc_option.feedback - db.session.commit() + # check width and so forth + + if box_is_filled(box, image): + solution.feedback = mc_option.feedback + db.session.commit() def box_is_filled(box, image): diff --git a/zesje/scans.py b/zesje/scans.py index 0560e8074f54029e7933eac4dd92d77ad7408c9c..580e46531e4fb090bb42e868e30a2ad3b3a7632e 100644 --- a/zesje/scans.py +++ b/zesje/scans.py @@ -16,7 +16,7 @@ from .database import db, Scan, Exam, Page, Student, Submission, Solution, ExamW from .datamatrix import decode_raw_datamatrix from .images import guess_dpi, get_box from .factory import make_celery - +from .pregrader import add_feedback_to_solution ExtractedBarcode = namedtuple('ExtractedBarcode', ['token', 'copy', 'page']) @@ -241,7 +241,8 @@ def process_page(image_data, exam_config, output_dir=None, strict=False): return True, "Testing, image not saved and database not updated." update_database(image_path, barcode) - # call our own function to pregrade + + add_feedback_to_solution() if barcode.page == 0: description = guess_student(