Skip to content
Snippets Groups Projects
Commit bde31337 authored by Ruben Young On's avatar Ruben Young On
Browse files

Pregrading now works

parent ff3d22ac
No related branches found
No related tags found
1 merge request!17Add pregrading
Pipeline #17942 passed with warnings
......@@ -17,18 +17,18 @@ from zesje.database import db, Solution, ProblemWidget
from zesje.images import guess_dpi, get_box, fix_corner_markers
def add_feedback_to_solution(page, page_img, corner_keypoints):
def add_feedback_to_solution(exam, page, page_img, corner_keypoints):
"""
Adds the multiple choice options that are identified as marked as a feedback option to a solution
Params
------
exam: the current exam
page_img: image of the page
barcode: data from the barcode on the page
corner_keypoints: locations of the corner keypoints
"""
problem_widgets = ProblemWidget.query.filter(ProblemWidget.page == page).all()
problems_on_page = [widget.problem for widget in problem_widgets]
problems_on_page = [problem for problem in exam.problems if problem.widget.page == page]
fixed_corner_keypoints = fix_corner_markers(corner_keypoints, page_img.shape)
......@@ -43,13 +43,15 @@ def add_feedback_to_solution(page, page_img, corner_keypoints):
box = (mc_option.x, mc_option.y)
if box_is_filled(box, page_img, top_left_point):
sol.feedback.append(mc_option.feedback)
db.session.commit()
feedback = mc_option.feedback
if mc_option.label:
sol.feedback.text = mc_option.label
feedback.text = mc_option.label
db.session.commit()
sol.feedback.append(feedback)
db.session.commit()
def box_is_filled(box, page_img, corner_keypoints, marker_margin=72/2.54, threshold=225, cut_padding=0.1, box_size=11):
"""
......
......@@ -338,8 +338,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(barcode.page, image_array, corner_keypoints)
exam = update_database(image_path, barcode)
add_feedback_to_solution(exam, barcode.page, image_array, corner_keypoints)
if barcode.page == 0:
description = guess_student(
......@@ -408,7 +408,7 @@ def update_database(image_path, barcode):
db.session.commit()
return sub, exam
return exam
def decode_barcode(image, exam_config):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment