Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
zesje
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Works on my machine
zesje
Commits
5f20a63c
Commit
5f20a63c
authored
5 years ago
by
RABijl
Browse files
Options
Downloads
Plain Diff
resolves merge conflicts with develop again
parents
eb83ae52
930968ac
Branches
fix/combine-precise-positioning-with-pregrading
Branches containing commit
No related tags found
1 merge request
!28
combine precise positioning with pregrading
Pipeline
#18421
passed
5 years ago
Stage: build
Stage: test
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
tests/test_pregrader.py
+3
-3
3 additions, 3 deletions
tests/test_pregrader.py
zesje/api/images.py
+2
-3
2 additions, 3 deletions
zesje/api/images.py
zesje/pdf_generation.py
+10
-7
10 additions, 7 deletions
zesje/pdf_generation.py
zesje/pregrader.py
+2
-1
2 additions, 1 deletion
zesje/pregrader.py
with
17 additions
and
14 deletions
tests/test_pregrader.py
+
3
−
3
View file @
5f20a63c
...
...
@@ -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
This diff is collapsed.
Click to expand it.
zesje/api/images.py
+
2
−
3
View file @
5f20a63c
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
zesje/pdf_generation.py
+
10
−
7
View file @
5f20a63c
...
...
@@ -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
-
mark
boxsize
# 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
,
mark
boxsize
,
mark
boxsize
)
canvas
.
rect
(
x
,
box_y
,
CHECKBOX_FORMAT
[
"
box
_
size
"
],
CHECKBOX_FORMAT
[
"
box
_
size
"
]
)
def
generate_datamatrix
(
exam_id
,
page_num
,
copy_num
):
...
...
This diff is collapsed.
Click to expand it.
zesje/pregrader.py
+
2
−
1
View file @
5f20a63c
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment