diff --git a/zesje/pregrader.py b/zesje/pregrader.py index 2339d325ce78b345a66bd1678fa7d3b3d4d37937..a70fbf141a52e039d29fc6dd5fbc7ef557e8796f 100644 --- a/zesje/pregrader.py +++ b/zesje/pregrader.py @@ -9,7 +9,7 @@ # coupled feedback cannot be deleted -from zesje.database import db, Exam, Submission +from zesje.database import db, Exam, Submission, Solution def pregrade(exam_token, image): @@ -28,24 +28,32 @@ def pregrade(exam_token, image): def add_feedback_to_solution(page_img, barcode): + """ + Adds the multiple choice options that are identified as marked as a feedback option to a solution + + Params + ------ + 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 = exam.problems - problems_on_page = list(filter(lambda p: p.widget.page == barcode.page, problems)) + problems_on_page = [p for p in exam.problems if p.widget.page == barcode.page] for problem in problems_on_page: for mc_option in problem.mc_options: box = (mc_option.x, mc_option.y) - # check width and so forth + sol = [s for s in sub.solutions if s.submission_id == sub.id] + # check if box is filled if box_is_filled(box, page_img): - sub.feedback = mc_option.feedback + sol.feedback = mc_option.feedback db.session.commit() -def box_is_filled(box, image): +def box_is_filled(box, page_img): pass diff --git a/zesje/scans.py b/zesje/scans.py index 580e46531e4fb090bb42e868e30a2ad3b3a7632e..cb44b6dd8fd614043755105b586fc11009444ebc 100644 --- a/zesje/scans.py +++ b/zesje/scans.py @@ -241,8 +241,7 @@ 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) - - add_feedback_to_solution() + add_feedback_to_solution(image_array, barcode) if barcode.page == 0: description = guess_student(