From 5af39a9a66e6bd32eb3d4b885ede094aa5beb419 Mon Sep 17 00:00:00 2001 From: Ruben Young On <r.d.youngon@student.tudelft.nl> Date: Wed, 22 May 2019 14:34:20 +0200 Subject: [PATCH] Changed structure --- zesje/pregrader.py | 22 +++++++++++++--------- zesje/scans.py | 5 +++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/zesje/pregrader.py b/zesje/pregrader.py index 3e2fa51e..0100cd1f 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 0560e807..580e4653 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( -- GitLab