Refactor feedback image handling and enhance sample answers display in exam scores user template
This commit is contained in:
+2
-1
@@ -485,10 +485,11 @@ class Rapid(QuestionBase):
|
|||||||
images = []
|
images = []
|
||||||
annotations_list = []
|
annotations_list = []
|
||||||
feedback_images = []
|
feedback_images = []
|
||||||
|
i: RapidImage
|
||||||
for i in self.images.all():
|
for i in self.images.all():
|
||||||
# TODO: add anotations
|
# TODO: add anotations
|
||||||
|
|
||||||
if i.feedback_image == True:
|
if i.feedback_image:
|
||||||
if feedback:
|
if feedback:
|
||||||
annotations_list.append(i.image_annotations)
|
annotations_list.append(i.image_annotations)
|
||||||
if based:
|
if based:
|
||||||
|
|||||||
@@ -34,6 +34,17 @@ from django.utils.html import format_html
|
|||||||
from helpers.images import combine_dicom_images_side_by_side
|
from helpers.images import combine_dicom_images_side_by_side
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from typing import List, TypedDict, Required, NotRequired
|
||||||
|
|
||||||
|
|
||||||
|
class QuestionData(TypedDict):
|
||||||
|
images: Required[list[str]]
|
||||||
|
annotations: Required[List[str]]
|
||||||
|
type: Required[str]
|
||||||
|
history: NotRequired[str]
|
||||||
|
answers: NotRequired[List[str]]
|
||||||
|
feedback: NotRequired[str]
|
||||||
|
feedback_images: NotRequired[List[str]]
|
||||||
|
|
||||||
|
|
||||||
def image_directory_path(instance, filename):
|
def image_directory_path(instance, filename):
|
||||||
@@ -215,6 +226,66 @@ class Question(QuestionBase):
|
|||||||
examinations = self.examination.all().values_list("examination", flat=True)
|
examinations = self.examination.all().values_list("examination", flat=True)
|
||||||
return ", ".join(examinations)
|
return ", ".join(examinations)
|
||||||
|
|
||||||
|
def get_sample_answers(self):
|
||||||
|
return self.sample_answers.all().order_by("-score")
|
||||||
|
|
||||||
|
def get_question_json(
|
||||||
|
self,
|
||||||
|
based: bool = True,
|
||||||
|
feedback: bool = False,
|
||||||
|
answers: bool = True,
|
||||||
|
history: bool = False,
|
||||||
|
annotations: bool = False,
|
||||||
|
) -> QuestionData:
|
||||||
|
"""Returns a json representation of the question"""
|
||||||
|
|
||||||
|
# Loop through rapidimage associations
|
||||||
|
images = []
|
||||||
|
annotations_list = []
|
||||||
|
feedback_images = []
|
||||||
|
i: QuestionImage
|
||||||
|
for i in self.images.all():
|
||||||
|
# TODO: add anotations
|
||||||
|
|
||||||
|
if i.feedback_image:
|
||||||
|
if feedback:
|
||||||
|
#annotations_list.append(i.image_annotations)
|
||||||
|
if based:
|
||||||
|
feedback_images.append(image_as_base64(i.image))
|
||||||
|
else:
|
||||||
|
feedback_images.append(
|
||||||
|
"{}/{}".format(settings.REMOTE_URL, i.image.url)
|
||||||
|
)
|
||||||
|
# feedback_images.append("{}/{}".format(settings.REMOTE_URL, i.image.url))
|
||||||
|
else:
|
||||||
|
#annotations_list.append(i.image_annotations)
|
||||||
|
if based:
|
||||||
|
images.append(image_as_base64(i.image))
|
||||||
|
else:
|
||||||
|
images.append("{}/{}".format(settings.REMOTE_URL, i.image.url))
|
||||||
|
|
||||||
|
json = {
|
||||||
|
"images": images,
|
||||||
|
# "feedback_image": [],
|
||||||
|
"type": "shorts",
|
||||||
|
}
|
||||||
|
|
||||||
|
#if annotations:
|
||||||
|
# json["annotations"] = annotations_list
|
||||||
|
|
||||||
|
if history:
|
||||||
|
json["history"] = self.history
|
||||||
|
|
||||||
|
if answers:
|
||||||
|
sample_answers = list(self.get_sample_answers().values_list("answer", "score"))
|
||||||
|
json["answers"] = sample_answers
|
||||||
|
|
||||||
|
if feedback:
|
||||||
|
json["feedback_images"] = feedback_images
|
||||||
|
json["feedback"] = self.feedback
|
||||||
|
|
||||||
|
return json
|
||||||
|
|
||||||
|
|
||||||
class QuestionImage(models.Model):
|
class QuestionImage(models.Model):
|
||||||
question = models.ForeignKey(
|
question = models.ForeignKey(
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
<div class="feedback"></div>
|
<div class="feedback"></div>
|
||||||
<div>
|
<div>
|
||||||
<details>
|
<details>
|
||||||
<summary>Answers:</summary><span class="answers"></span>
|
<summary>Sample Answers:</summary>
|
||||||
|
<span class="answers">
|
||||||
|
</span>
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -72,7 +74,16 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
window.dispatchEvent(event);
|
window.dispatchEvent(event);
|
||||||
$(".question-display-block .answers").empty().append(data.answers.toString());
|
console.log(data)
|
||||||
|
if (data.answers && data.answers.length > 0) {
|
||||||
|
// Format: [[answer, score], ...]
|
||||||
|
let formattedAnswers = data.answers.map(
|
||||||
|
ans => `<div class="sample-answer-block"><span class="sample-answer-text">${ans[0]}</span> <span class="sample-answer-score badge badge-info">Score: ${ans[1]}</span></div>`
|
||||||
|
).join('');
|
||||||
|
$(".question-display-block .answers").empty().append(`${formattedAnswers}`);
|
||||||
|
} else {
|
||||||
|
$(".question-display-block .answers").empty().append("No sample answers available");
|
||||||
|
}
|
||||||
n = parseInt(question_number) + 1
|
n = parseInt(question_number) + 1
|
||||||
$(".question-display-block .question-number").empty().append(n);
|
$(".question-display-block .question-number").empty().append(n);
|
||||||
$(".question-display-block .feedback").empty().append(`Feedback: ${data.feedback}<br />`);
|
$(".question-display-block .feedback").empty().append(`Feedback: ${data.feedback}<br />`);
|
||||||
@@ -100,4 +111,3 @@
|
|||||||
|
|
||||||
</style>
|
</style>
|
||||||
{% endblock css %}
|
{% endblock css %}
|
||||||
|
|
||||||
Reference in New Issue
Block a user