From 59c53ebbb2348efe62ee60b186d75b10c8acbfd6 Mon Sep 17 00:00:00 2001 From: Ruben Young On <r.d.youngon@student.tudelft.nl> Date: Thu, 23 May 2019 15:59:29 +0200 Subject: [PATCH] update_database now returns the submission --- zesje/pregrader.py | 9 +++------ zesje/scans.py | 6 ++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/zesje/pregrader.py b/zesje/pregrader.py index 54683e15..af594222 100644 --- a/zesje/pregrader.py +++ b/zesje/pregrader.py @@ -27,7 +27,7 @@ def pregrade(exam_token, image): pass -def add_feedback_to_solution(page_img, barcode, corner_keypoints): +def add_feedback_to_solution(submission, page, page_img, corner_keypoints): """ Adds the multiple choice options that are identified as marked as a feedback option to a solution @@ -36,16 +36,13 @@ def add_feedback_to_solution(page_img, barcode, corner_keypoints): page_img: image of the page barcode: data from the barcode on the page """ - 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() - - problems_on_page = Problem.query.filter(Problem.widget.page == barcode.page).all() + problems_on_page = Problem.query.filter(Problem.widget.page == page).all() for problem in problems_on_page: for mc_option in problem.mc_options: box = (mc_option.x, mc_option.y) - sol = Solution.query.filter(Solution.submission_id == sub.id).one_or_none() + sol = Solution.query.filter(Solution.problem_id == problem.id).one_or_none() # check if box is filled if box_is_filled(box, page_img, corner_keypoints): diff --git a/zesje/scans.py b/zesje/scans.py index 5bf992b8..c3f55ca4 100644 --- a/zesje/scans.py +++ b/zesje/scans.py @@ -240,8 +240,8 @@ def process_page(image_data, exam_config, output_dir=None, strict=False): else: return True, "Testing, image not saved and database not updated." - update_database(image_path, barcode) - add_feedback_to_solution(image_array, barcode, corner_keypoints) + submission, exam = update_database(image_path, barcode) + add_feedback_to_solution(submission, exam, barcode.page, image_array, corner_keypoints) if barcode.page == 0: description = guess_student( @@ -310,6 +310,8 @@ def update_database(image_path, barcode): db.session.commit() + return sub, exam + def decode_barcode(image, exam_config): """Extract a barcode from a PIL Image.""" -- GitLab