Skip to content
Snippets Groups Projects
Commit 5f20a63c authored by RABijl's avatar RABijl
Browse files

resolves merge conflicts with develop again

parents eb83ae52 930968ac
Branches fix/combine-precise-positioning-with-pregrading
No related tags found
1 merge request!28combine precise positioning with pregrading
Pipeline #18421 passed
......@@ -20,7 +20,7 @@ def scanned_image(datadir):
ids=["1 filled", "2 empty", "3 marked with line", "4 completely filled",
"5 marked with an x", "e marked with a cirle inside"])
def test_ideal_crops(box_coords, result, scanned_image):
assert pregrader.box_is_filled(box_coords, scanned_image, cut_padding=0.1) == result
assert pregrader.box_is_filled(box_coords, scanned_image, cut_padding=0.1, box_size=9) == result
@pytest.mark.parametrize('box_coords, result', [((341, 471), True), ((352, 482), True), ((448, 482), True),
......@@ -30,7 +30,7 @@ def test_ideal_crops(box_coords, result, scanned_image):
"4 fully filled with the label", "6 empty with label",
"7 partially cropped, filled and a part of 6", "B empty with cb at the bottom"])
def test_shifted_crops(box_coords, result, scanned_image):
assert pregrader.box_is_filled(box_coords, scanned_image, cut_padding=0.1) == result
assert pregrader.box_is_filled(box_coords, scanned_image, cut_padding=0.1, box_size=9) == result
@pytest.mark.parametrize('box_coords, result', [((60, 562), True), ((107, 562), True),
......@@ -38,4 +38,4 @@ def test_shifted_crops(box_coords, result, scanned_image):
ids=["A filled with trailing letter", "C filled with letters close",
"D blank with trailing letter"])
def test_trailing_text(box_coords, result, scanned_image):
assert pregrader.box_is_filled(box_coords, scanned_image, cut_padding=0.1) == result
assert pregrader.box_is_filled(box_coords, scanned_image, cut_padding=0.1, box_size=9) == result
......@@ -5,8 +5,7 @@ import cv2
from ..images import get_box, guess_dpi
from ..database import Exam, Submission, Problem, Page, Solution
BOX_SIZE = 9
from ..pdf_generation import CHECKBOX_FORMAT
def get(exam_id, problem_id, submission_id, full_page=False):
......@@ -70,7 +69,7 @@ def get(exam_id, problem_id, submission_id, full_page=False):
if option.feedback_id in fb:
x = int(option.x / 72 * dpi)
y = int(option.y / 72 * dpi)
box_length = int(BOX_SIZE / 72 * dpi)
box_length = int(CHECKBOX_FORMAT["box_size"] / 72 * dpi)
x1 = x + box_length
y1 = y + box_length
page_im = cv2.rectangle(page_im, (x, y), (x1, y1), (0, 255, 0), 3)
......
......@@ -18,6 +18,12 @@ MARKER_FORMAT = {
"bar_length": 40 * mm
}
# the parameters of drawing checkboxes
CHECKBOX_FORMAT = {
"margin": 5,
"font_size": 11,
"box_size": 9
}
PAGE_FORMATS = {
"A4": (595.276, 841.89),
"US letter": (612, 792),
......@@ -182,20 +188,17 @@ def generate_checkbox(canvas, x, y, label):
A string representing the label that is drawn on top of the box, will only take the first character
"""
fontsize = 11 # Size of font
margin = 5 # Margin between elements and sides
markboxsize = fontsize - 2 # Size of checkboxes boxes
x_label = x + 1 # location of the label
y_label = y + margin # remove fontsize from the y label since we draw from the bottom left up
box_y = y - markboxsize # remove the markboxsize because the y is the coord of the top
y_label = y + CHECKBOX_FORMAT["margin"] # remove fontsize from the y label since we draw from the bottom left up
box_y = y - CHECKBOX_FORMAT["box_size"] # remove the markboxsize because the y is the coord of the top
# and reportlab prints from the bottom
# check that there is a label to print
if (label and not (len(label) == 0)):
canvas.setFont('Helvetica', fontsize)
canvas.setFont('Helvetica', CHECKBOX_FORMAT["font_size"])
canvas.drawString(x_label, y_label, label[0])
canvas.rect(x, box_y, markboxsize, markboxsize)
canvas.rect(x, box_y, CHECKBOX_FORMAT["box_size"], CHECKBOX_FORMAT["box_size"])
def generate_datamatrix(exam_id, page_num, copy_num):
......
......@@ -3,6 +3,7 @@ import numpy as np
from .database import db, Solution
from .images import guess_dpi, get_box
from .pdf_generation import CHECKBOX_FORMAT
def add_feedback_to_solution(sub, exam, page, page_img):
......@@ -26,7 +27,7 @@ def add_feedback_to_solution(sub, exam, page, page_img):
for mc_option in problem.mc_options:
box = (mc_option.x, mc_option.y)
if box_is_filled(box, page_img):
if box_is_filled(box, page_img, box_size=CHECKBOX_FORMAT["box_size"]):
feedback = mc_option.feedback
sol.feedback.append(feedback)
db.session.commit()
......
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