From 10c219bbbdc5b9dcff337fafed0cf0f065d9e88a Mon Sep 17 00:00:00 2001 From: abiyasa05 Date: Sun, 6 Apr 2025 11:30:23 +0700 Subject: [PATCH] update: add similar text on assessment result on role teacher --- .../teacher/assessment_results/show.blade.php | 65 +++++++++++++------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/Penilaian Literasi/iClOP-V2/resources/views/literacy/teacher/assessment_results/show.blade.php b/Penilaian Literasi/iClOP-V2/resources/views/literacy/teacher/assessment_results/show.blade.php index 07daa95..a260692 100644 --- a/Penilaian Literasi/iClOP-V2/resources/views/literacy/teacher/assessment_results/show.blade.php +++ b/Penilaian Literasi/iClOP-V2/resources/views/literacy/teacher/assessment_results/show.blade.php @@ -338,16 +338,33 @@ @php $totalBenar = 0; $totalSalah = 0; + $essayThreshold = 50; + + $normalize = function ($text) { + $text = strtolower($text); + $text = preg_replace('/[^\p{L}\p{N}\s]/u', '', $text); + $text = preg_replace('/\s+/', ' ', $text); + return trim($text); + }; - // Hitung total benar dan salah terlebih dahulu (loop pertama) foreach ($questions as $question) { $answer = $question->answers->first(); $isCorrect = false; if ($question->type === 'multiple_choice' && $answer) { - $isCorrect = $answer->option->is_correct; - } elseif ($question->type === 'essay') { - $isCorrect = strtolower(trim($answer->answer_text)) === strtolower(trim($question->essay_answer)); + $isCorrect = optional($answer->option)->is_correct; + } elseif ($question->type === 'essay' && $answer) { + $userAnswer = $normalize($answer->answer_text ?? ''); + $correctAnswers = explode("\n", $question->essay_answer ?? ''); + $maxMatch = 0; + + foreach ($correctAnswers as $correct) { + $correctNormalized = $normalize($correct); + similar_text($userAnswer, $correctNormalized, $percent); + $maxMatch = max($maxMatch, $percent); + } + + $isCorrect = $maxMatch >= $essayThreshold; } if ($isCorrect) { @@ -357,23 +374,21 @@ } } - // Mengubah status asesmen ke bahasa Indonesia $statusMap = [ 'completed' => 'Selesai', 'in_progress' => 'Sedang Dikerjakan', 'pending' => 'Menunggu', ]; - $statusAsesmen = $statusMap[$assessment->status] ?? 'Tidak Dikenal'; // Menangani status yang tidak dikenal + $statusAsesmen = $statusMap[$assessment->status] ?? 'Tidak Dikenal'; @endphp
-

Assessment Result

+

Hasil Asesmen Siswa

Detail Jawaban
-
- +
Ringkasan Jawaban
@@ -381,7 +396,6 @@ Benar: {{ $totalBenar }} | Salah: {{ $totalSalah }}

-
@@ -391,7 +405,7 @@
- +
Informasi Pengguna
@@ -408,13 +422,26 @@ @php $answer = $question->answers->first(); $isCorrect = false; + $similarityScore = null; if ($question->type === 'multiple_choice' && $answer) { - $isCorrect = $answer->option->is_correct; - } elseif ($question->type === 'essay') { - $isCorrect = strtolower(trim($answer->answer_text)) === strtolower(trim($question->essay_answer)); + $isCorrect = optional($answer->option)->is_correct; + } elseif ($question->type === 'essay' && $answer) { + $userAnswer = $normalize($answer->answer_text ?? ''); + $correctAnswers = explode("\n", $question->essay_answer ?? ''); + $maxMatch = 0; + + foreach ($correctAnswers as $correct) { + $correctNormalized = $normalize($correct); + similar_text($userAnswer, $correctNormalized, $percent); + $maxMatch = max($maxMatch, $percent); + } + + $similarityScore = $maxMatch; + $isCorrect = $maxMatch >= $essayThreshold; } @endphp +
  • {{ $index + 1 }}. {{ $question->question_text }} @@ -426,7 +453,7 @@

    - Jawaban Anda: + Jawaban Siswa: @if ($question->type === 'multiple_choice') {{ optional($answer)->option->option_text ?? 'Tidak Dijawab' }} @else @@ -434,11 +461,9 @@ @endif

    - @if ($question->type === 'essay') -

    - Feedback: - {{ optional($answer)->feedback ?? 'Tidak ada feedback' }} -

    + @if ($question->type === 'essay' && $similarityScore !== null) +

    Skor Kemiripan: {{ number_format($similarityScore, 2) }}%

    +

    Feedback: {{ $answer->feedback ?? 'Tidak ada feedback' }}

    @endif
  • @endforeach