Add grades to AssingmentEvaluation
This commit is contained in:
parent
2d6cee9f9f
commit
5868468a48
|
|
@ -34,6 +34,8 @@ async function submitEvaluation() {
|
|||
course_session_id: courseSessionStore.currentCourseSession!.id,
|
||||
completion_data: {},
|
||||
completion_status: "evaluation_submitted",
|
||||
evaluation_grade: grade.value,
|
||||
evaluation_points: userPoints.value,
|
||||
});
|
||||
emit("submitEvaluation");
|
||||
}
|
||||
|
|
@ -44,9 +46,6 @@ function subTaskByPoints(task: AssignmentEvaluationTask, points = 0) {
|
|||
|
||||
function evaluationForTask(task: AssignmentEvaluationTask) {
|
||||
const expertData = props.assignmentCompletion.completion_data[task.id]?.expert_data;
|
||||
if (task.id === "0e701176-a817-427b-b8ea-a7cd59f212cb") {
|
||||
console.log("######################## ", expertData.text, expertData.points);
|
||||
}
|
||||
if (!expertData) {
|
||||
return {
|
||||
points: 0,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const emit = defineEmits<{
|
|||
<p class="text-sm text-gray-900">{{ task.value.title }}</p>
|
||||
<button
|
||||
v-if="props.allowEdit"
|
||||
class="link whitespace-nowrap pl-2text-sm"
|
||||
class="link pl-2text-sm whitespace-nowrap"
|
||||
@click="emit('editTask', task)"
|
||||
>
|
||||
{{ $t("assignment.edit") }}
|
||||
|
|
|
|||
|
|
@ -540,7 +540,7 @@ export interface AssignmentCompletion {
|
|||
created_at: string;
|
||||
updated_at: string;
|
||||
submitted_at: string;
|
||||
evaluated_at: string | null;
|
||||
evaluation_submitted_at: string | null;
|
||||
assignment_user: number;
|
||||
assignment: number;
|
||||
course_session: number;
|
||||
|
|
@ -558,4 +558,6 @@ export type UpsertUserAssignmentCompletion = {
|
|||
|
||||
export type EvaluationCompletionData = UpsertUserAssignmentCompletion & {
|
||||
assignment_user_id: number;
|
||||
evaluation_grade?: number;
|
||||
evaluation_points?: number;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ urlpatterns = [
|
|||
path(r"api/assignment/upsert/", upsert_user_assignment_completion,
|
||||
name="upsert_user_assignment_completion"),
|
||||
path(r"api/assignment/evaluate/", evaluate_assignment_completion,
|
||||
name="grade_assignment_completion"),
|
||||
name="evaluate_assignment_completion"),
|
||||
path(r"api/assignment/<int:assignment_id>/<int:course_session_id>/",
|
||||
request_assignment_completion,
|
||||
name="request_assignment_completion"),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
from wagtail.blocks import StreamValue
|
||||
from wagtail.blocks.list_block import ListBlock, ListValue
|
||||
from wagtail.rich_text import RichText
|
||||
|
||||
from vbv_lernwelt.assignment.models import (
|
||||
EvaluationSubTaskBlock,
|
||||
TaskContentStreamBlock,
|
||||
|
|
@ -19,6 +15,9 @@ from vbv_lernwelt.assignment.tests.assignment_factories import (
|
|||
from vbv_lernwelt.core.utils import replace_whitespace
|
||||
from vbv_lernwelt.course.consts import COURSE_TEST_ID, COURSE_UK
|
||||
from vbv_lernwelt.course.models import CoursePage
|
||||
from wagtail.blocks import StreamValue
|
||||
from wagtail.blocks.list_block import ListBlock, ListValue
|
||||
from wagtail.rich_text import RichText
|
||||
|
||||
|
||||
def create_uk_assignments(course_id=COURSE_UK):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.2.13 on 2023-05-01 15:43
|
||||
# Generated by Django 3.2.13 on 2023-05-05 14:10
|
||||
|
||||
import django.db.models.deletion
|
||||
import wagtail.blocks
|
||||
|
|
@ -8,12 +8,13 @@ from django.db import migrations, models
|
|||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("course", "0006_alter_coursesession_attendance_days"),
|
||||
("wagtailcore", "0083_workflowcontenttype"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("course", "0006_alter_coursesession_attendance_days"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
|
@ -274,6 +275,8 @@ class Migration(migrations.Migration):
|
|||
"evaluation_user_email",
|
||||
models.CharField(blank=True, default="", max_length=255),
|
||||
),
|
||||
("evaluation_grade", models.FloatField(blank=True, null=True)),
|
||||
("evaluation_points", models.FloatField(blank=True, null=True)),
|
||||
(
|
||||
"assignment",
|
||||
models.ForeignKey(
|
||||
|
|
@ -328,7 +331,12 @@ class Migration(migrations.Migration):
|
|||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
("submitted_at", models.DateTimeField(blank=True, null=True)),
|
||||
("evaluated_at", models.DateTimeField(blank=True, null=True)),
|
||||
(
|
||||
"evaluation_submitted_at",
|
||||
models.DateTimeField(blank=True, null=True),
|
||||
),
|
||||
("evaluation_grade", models.FloatField(blank=True, null=True)),
|
||||
("evaluation_points", models.FloatField(blank=True, null=True)),
|
||||
(
|
||||
"completion_status",
|
||||
models.CharField(
|
||||
|
|
|
|||
|
|
@ -214,8 +214,11 @@ class Assignment(CourseBasePage):
|
|||
if sub_dict["type"] in subtask_types
|
||||
]
|
||||
|
||||
def filter_evaluation_tasks(self):
|
||||
return self.evaluation_tasks.raw_data
|
||||
def get_evaluation_tasks(self):
|
||||
return [task for task in self.evaluation_tasks.raw_data]
|
||||
|
||||
def get_input_tasks(self):
|
||||
return self.filter_user_subtasks() + self.get_evaluation_tasks()
|
||||
|
||||
|
||||
AssignmentCompletionStatus = Enum(
|
||||
|
|
@ -229,7 +232,7 @@ class AssignmentCompletion(models.Model):
|
|||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
submitted_at = models.DateTimeField(null=True, blank=True)
|
||||
evaluated_at = models.DateTimeField(null=True, blank=True)
|
||||
evaluation_submitted_at = models.DateTimeField(null=True, blank=True)
|
||||
evaluation_user = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE,
|
||||
|
|
@ -237,6 +240,8 @@ class AssignmentCompletion(models.Model):
|
|||
blank=True,
|
||||
related_name="+",
|
||||
)
|
||||
evaluation_grade = models.FloatField(null=True, blank=True)
|
||||
evaluation_points = models.FloatField(null=True, blank=True)
|
||||
|
||||
assignment_user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
assignment = models.ForeignKey(Assignment, on_delete=models.CASCADE)
|
||||
|
|
@ -292,3 +297,5 @@ class AssignmentCompletionAuditLog(models.Model):
|
|||
assignment_user_email = models.CharField(max_length=255)
|
||||
assignment_slug = models.CharField(max_length=255)
|
||||
evaluation_user_email = models.CharField(max_length=255, blank=True, default="")
|
||||
evaluation_grade = models.FloatField(null=True, blank=True)
|
||||
evaluation_points = models.FloatField(null=True, blank=True)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class AssignmentCompletionSerializer(serializers.ModelSerializer):
|
|||
"created_at",
|
||||
"updated_at",
|
||||
"submitted_at",
|
||||
"evaluated_at",
|
||||
"evaluation_submitted_at",
|
||||
"assignment_user",
|
||||
"assignment",
|
||||
"course_session",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ def update_assignment_completion(
|
|||
completion_data=None,
|
||||
completion_status: Type[AssignmentCompletionStatus] = "in_progress",
|
||||
evaluation_user: User | None = None,
|
||||
evaluation_grade: float | None = None,
|
||||
evaluation_points: float | None = None,
|
||||
validate_completion_status_change: bool = True,
|
||||
copy_task_data: bool = False,
|
||||
) -> AssignmentCompletion:
|
||||
|
|
@ -74,6 +76,13 @@ def update_assignment_completion(
|
|||
}
|
||||
)
|
||||
|
||||
if completion_status == "in_progress" and ac.completion_status != "in_progress":
|
||||
raise serializers.ValidationError(
|
||||
{
|
||||
"completion_status": f"Cannot set completion status to in_progress when it is {ac.completion_status}"
|
||||
}
|
||||
)
|
||||
|
||||
if completion_status in ["evaluation_submitted", "evaluation_in_progress"]:
|
||||
if evaluation_user is None:
|
||||
raise serializers.ValidationError(
|
||||
|
|
@ -83,10 +92,27 @@ def update_assignment_completion(
|
|||
)
|
||||
ac.evaluation_user = evaluation_user
|
||||
|
||||
if completion_status == "evaluation_submitted":
|
||||
if evaluation_grade is None:
|
||||
raise serializers.ValidationError(
|
||||
{
|
||||
"evaluation_grade": "evaluation_grade is required for evaluation_submitted status"
|
||||
}
|
||||
)
|
||||
if evaluation_points is None:
|
||||
raise serializers.ValidationError(
|
||||
{
|
||||
"evaluation_points": "evaluation_points is required for evaluation_submitted status"
|
||||
}
|
||||
)
|
||||
|
||||
ac.evaluation_grade = evaluation_grade
|
||||
ac.evaluation_points = evaluation_points
|
||||
|
||||
if completion_status == "submitted":
|
||||
ac.submitted_at = timezone.now()
|
||||
elif completion_status == "evaluation_submitted":
|
||||
ac.evaluated_at = timezone.now()
|
||||
ac.evaluation_submitted_at = timezone.now()
|
||||
|
||||
ac.completion_status = completion_status
|
||||
|
||||
|
|
@ -100,7 +126,7 @@ def update_assignment_completion(
|
|||
|
||||
if copy_task_data:
|
||||
# copy over the question data, so that we don't lose the context
|
||||
substasks = assignment.filter_user_subtasks()
|
||||
substasks = assignment.get_input_tasks()
|
||||
for key, value in ac.completion_data.items():
|
||||
task_data = find_first(substasks, pred=lambda x: x["id"] == key)
|
||||
ac.completion_data[key].update(task_data)
|
||||
|
|
@ -122,9 +148,9 @@ def update_assignment_completion(
|
|||
acl.evaluation_user_email = evaluation_user.email
|
||||
|
||||
# copy over the question data, so that we don't lose the context
|
||||
substasks = assignment.filter_user_subtasks()
|
||||
subtasks = assignment.get_input_tasks()
|
||||
for key, value in acl.completion_data.items():
|
||||
task_data = find_first(substasks, pred=lambda x: x["id"] == key)
|
||||
task_data = find_first(subtasks, pred=lambda x: x["id"] == key)
|
||||
acl.completion_data[key].update(task_data)
|
||||
acl.save()
|
||||
|
||||
|
|
@ -135,15 +161,8 @@ def _remove_unknown_entries(assignment, completion_data):
|
|||
"""
|
||||
Removes all entries from completion_data which are not known to the assignment
|
||||
"""
|
||||
possible_subtask_uuids = [
|
||||
subtask["id"] for subtask in assignment.filter_user_subtasks()
|
||||
]
|
||||
possible_evaluation_uuids = [
|
||||
task["id"] for task in assignment.filter_evaluation_tasks()
|
||||
]
|
||||
input_task_ids = [task["id"] for task in assignment.get_input_tasks()]
|
||||
filtered_completion_data = {
|
||||
key: value
|
||||
for key, value in completion_data.items()
|
||||
if key in possible_subtask_uuids or key in possible_evaluation_uuids
|
||||
key: value for key, value in completion_data.items() if key in input_task_ids
|
||||
}
|
||||
return filtered_completion_data
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ class AssignmentApiTestCase(APITestCase):
|
|||
|
||||
# make api call
|
||||
self.client.login(username="admin", password="test")
|
||||
url = f"/api/assignment/grade/"
|
||||
url = f"/api/assignment/evaluate/"
|
||||
|
||||
response = self.client.post(
|
||||
url,
|
||||
|
|
@ -236,6 +236,8 @@ class AssignmentApiTestCase(APITestCase):
|
|||
"expert_data": {"points": 1, "comment": "Gut gemacht!"}
|
||||
},
|
||||
},
|
||||
"evaluation_grade": 4.5,
|
||||
"evaluation_points": 16,
|
||||
},
|
||||
format="json",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ class UpdateAssignmentCompletionTestCase(TestCase):
|
|||
completion_status="submitted",
|
||||
)
|
||||
|
||||
evaluation_task = self.assignment.filter_evaluation_tasks()[0]
|
||||
evaluation_task = self.assignment.get_evaluation_tasks()[0]
|
||||
|
||||
update_assignment_completion(
|
||||
assignment_user=self.user,
|
||||
|
|
@ -423,3 +423,120 @@ class UpdateAssignmentCompletionTestCase(TestCase):
|
|||
self.assertTrue(
|
||||
"evaluation_user" in error.exception.detail,
|
||||
)
|
||||
|
||||
def test_can_submit_evaluation(self):
|
||||
subtasks = self.assignment.filter_user_subtasks(
|
||||
subtask_types=["user_text_input"]
|
||||
)
|
||||
user_text_input = find_first(
|
||||
subtasks,
|
||||
pred=lambda x: (value := x.get("value"))
|
||||
and value.get("text", "").startswith(
|
||||
"Gibt es zusätzliche Deckungen, die du der Person empfehlen würdest?"
|
||||
),
|
||||
)
|
||||
|
||||
ac = AssignmentCompletion.objects.create(
|
||||
assignment_user=self.user,
|
||||
assignment=self.assignment,
|
||||
course_session=self.course_session,
|
||||
completion_status="submitted",
|
||||
completion_data={
|
||||
user_text_input["id"]: {
|
||||
"user_data": {"text": "Ich würde nichts weiteres empfehlen."}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
evaluation_task = self.assignment.get_evaluation_tasks()[0]
|
||||
|
||||
update_assignment_completion(
|
||||
assignment_user=self.user,
|
||||
assignment=self.assignment,
|
||||
course_session=self.course_session,
|
||||
completion_data={
|
||||
evaluation_task["id"]: {
|
||||
"expert_data": {"points": 2, "text": "Gut gemacht!"}
|
||||
},
|
||||
},
|
||||
completion_status="evaluation_in_progress",
|
||||
evaluation_user=self.trainer,
|
||||
)
|
||||
|
||||
with self.assertRaises(serializers.ValidationError) as error:
|
||||
# not setting grade will raise an error
|
||||
update_assignment_completion(
|
||||
assignment_user=self.user,
|
||||
assignment=self.assignment,
|
||||
course_session=self.course_session,
|
||||
completion_data={},
|
||||
completion_status="evaluation_submitted",
|
||||
evaluation_user=self.trainer,
|
||||
evaluation_grade=None,
|
||||
evaluation_points=None,
|
||||
)
|
||||
|
||||
update_assignment_completion(
|
||||
assignment_user=self.user,
|
||||
assignment=self.assignment,
|
||||
course_session=self.course_session,
|
||||
completion_data={},
|
||||
completion_status="evaluation_submitted",
|
||||
evaluation_user=self.trainer,
|
||||
evaluation_grade=4.5,
|
||||
evaluation_points=16,
|
||||
)
|
||||
|
||||
ac = AssignmentCompletion.objects.get(
|
||||
assignment_user=self.user,
|
||||
assignment=self.assignment,
|
||||
course_session=self.course_session,
|
||||
)
|
||||
|
||||
self.assertEqual(ac.completion_status, "evaluation_submitted")
|
||||
self.assertEqual(ac.evaluation_grade, 4.5)
|
||||
self.assertEqual(ac.evaluation_points, 16)
|
||||
trainer_input = ac.completion_data[evaluation_task["id"]]
|
||||
self.assertDictEqual(
|
||||
trainer_input["expert_data"], {"points": 2, "text": "Gut gemacht!"}
|
||||
)
|
||||
user_input = ac.completion_data[user_text_input["id"]]
|
||||
self.assertDictEqual(
|
||||
user_input["user_data"], {"text": "Ich würde nichts weiteres empfehlen."}
|
||||
)
|
||||
|
||||
# will create AssignmentCompletionAuditLog entry
|
||||
acl = AssignmentCompletionAuditLog.objects.get(
|
||||
assignment_user=self.user,
|
||||
assignment=self.assignment,
|
||||
course_session=self.course_session,
|
||||
completion_status="evaluation_submitted",
|
||||
)
|
||||
self.assertEqual(acl.created_at.date(), date.today())
|
||||
self.assertEqual(acl.assignment_user_email, "student")
|
||||
self.assertEqual(
|
||||
acl.assignment_slug,
|
||||
"versicherungsvermittler-in-assignment-überprüfen-einer-motorfahrzeugs-versicherungspolice",
|
||||
)
|
||||
trainer_input = acl.completion_data[evaluation_task["id"]]
|
||||
self.assertDictEqual(
|
||||
trainer_input["expert_data"], {"points": 2, "text": "Gut gemacht!"}
|
||||
)
|
||||
user_input = acl.completion_data[user_text_input["id"]]
|
||||
self.assertDictEqual(
|
||||
user_input["user_data"], {"text": "Ich würde nichts weiteres empfehlen."}
|
||||
)
|
||||
|
||||
# AssignmentCompletionAuditLog entry will remain event after deletion of foreign keys
|
||||
ac.delete()
|
||||
self.user.delete()
|
||||
self.assignment.delete()
|
||||
acl = AssignmentCompletionAuditLog.objects.get(id=acl.id)
|
||||
self.assertEqual(acl.created_at.date(), date.today())
|
||||
self.assertEqual(acl.assignment_user_email, "student")
|
||||
self.assertEqual(
|
||||
acl.assignment_slug,
|
||||
"versicherungsvermittler-in-assignment-überprüfen-einer-motorfahrzeugs-versicherungspolice",
|
||||
)
|
||||
self.assertIsNone(acl.assignment_user)
|
||||
self.assertIsNone(acl.assignment)
|
||||
|
|
|
|||
|
|
@ -129,6 +129,8 @@ def evaluate_assignment_completion(request):
|
|||
"completion_status", "evaluation_in_progress"
|
||||
)
|
||||
completion_data = request.data.get("completion_data", {})
|
||||
evaluation_grade = request.data.get("evaluation_grade", None)
|
||||
evaluation_points = request.data.get("evaluation_grade", None)
|
||||
|
||||
assignment_page = Page.objects.get(id=assignment_id)
|
||||
assignment_user = User.objects.get(id=assignment_user_id)
|
||||
|
|
@ -149,6 +151,8 @@ def evaluate_assignment_completion(request):
|
|||
completion_status=completion_status,
|
||||
copy_task_data=False,
|
||||
evaluation_user=request.user,
|
||||
evaluation_grade=evaluation_grade,
|
||||
evaluation_points=evaluation_points,
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
|
|
@ -160,6 +164,8 @@ def evaluate_assignment_completion(request):
|
|||
course_session_id=course_session_id,
|
||||
completion_status=completion_status,
|
||||
evaluation_user_id=request.user.id,
|
||||
evaluation_grade=evaluation_grade,
|
||||
evaluation_points=evaluation_points,
|
||||
)
|
||||
|
||||
return Response(status=200, data=AssignmentCompletionSerializer(ac).data)
|
||||
|
|
|
|||
Loading…
Reference in New Issue