Skip to content
Snippets Groups Projects
Commit 723430c9 authored by RABijl's avatar RABijl
Browse files

Merge branch 'feature/highlite_pregrade' into test/pregrading-with-precise-positioning

ge to explain why this merge is necessary,
parents 08c6dce7 bae3b291
No related branches found
No related tags found
1 merge request!28combine precise positioning with pregrading
......@@ -3,8 +3,8 @@ from flask import abort, Response
import numpy as np
import cv2
from ..images import get_box
from ..database import Exam, Submission, Problem, Page
from ..images import get_box, guess_dpi
from ..database import Exam, Submission, Problem, Page, Solution
def get(exam_id, problem_id, submission_id, full_page=False):
......@@ -56,6 +56,22 @@ def get(exam_id, problem_id, submission_id, full_page=False):
page_path = page.path
page_im = cv2.imread(page_path)
# pregrade highliting
solution = Solution.query.filter(Solution.submission_id == sub.id,
Solution.problem_id == problem_id).one_or_none()
if solution is not None:
dpi = guess_dpi(page_im)
fb = list(map(lambda x: x.id, solution.feedback))
for option in problem.mc_options:
if option.feedback_id in fb:
x = int((option.x) / 72 * dpi)
y = int((option.y) / 72 * dpi)
x1 = x + 20
y1 = y + 20
page_im = cv2.rectangle(page_im, (x, y), (x1, y1), (0, 255, 0), 3)
if not full_page:
raw_image = get_box(page_im, widget_area_in, padding=0.3)
else:
......
......@@ -4,6 +4,7 @@ from ..database import db, MultipleChoiceOption, FeedbackOption
def set_mc_data(mc_entry, name, x, y, mc_type, feedback_id, label):
"""Sets the data of a MultipleChoiceOption ORM object.
Parameters:
......@@ -21,6 +22,7 @@ def set_mc_data(mc_entry, name, x, y, mc_type, feedback_id, label):
mc_entry.x = x
mc_entry.y = y
mc_entry.type = mc_type
mc_entry.feedback_id = feedback_id
mc_entry.label = label
......@@ -63,6 +65,9 @@ class MultipleChoice(Resource):
# TODO: Set type here or add to request?
mc_type = 'mcq_widget'
# TODO: Set type here or add to request?
mc_type = 'mcq_widget'
if not id:
# Insert new empty feedback option that links to the same problem, with the label as name
new_feedback_option = FeedbackOption(problem_id=problem_id, text=label)
......@@ -71,6 +76,7 @@ class MultipleChoice(Resource):
# Insert new entry into the database
mc_entry = MultipleChoiceOption()
set_mc_data(mc_entry, name, x, y, mc_type, new_feedback_option.id, label)
db.session.add(mc_entry)
......@@ -87,6 +93,7 @@ class MultipleChoice(Resource):
return dict(status=404, message=f"Multiple choice question with id {id} does not exist"), 404
set_mc_data(mc_entry, name, x, y, mc_type, label)
db.session.commit()
return dict(status=200, message=f'Multiple choice question with id {id} updated'), 200
......@@ -120,6 +127,9 @@ class MultipleChoice(Resource):
if mult_choice.label:
json['label'] = mult_choice.label
if mult_choice.feedback_id:
json['feedback_id'] = mult_choice.feedback_id
return json
def delete(self, id):
......
......@@ -99,6 +99,7 @@ class Problem(db.Model):
exam_id = Column(Integer, ForeignKey('exam.id'), nullable=False)
feedback_options = db.relationship('FeedbackOption', backref='problem', order_by='FeedbackOption.id', lazy=True)
solutions = db.relationship('Solution', backref='problem', lazy=True)
mc_options = db.relationship('MultipleChoiceOption', backref='problem', lazy=True)
widget = db.relationship('ProblemWidget', backref='problem', uselist=False, lazy=True)
@hybrid_property
......@@ -176,6 +177,9 @@ class MultipleChoiceOption(Widget):
__mapper_args__ = {
'polymorphic_identity': 'mcq_widget'
}
__mapper_args__ = {
'polymorphic_identity': 'mcq_widget'
}
class ExamWidget(Widget):
......
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