update: add similar text on assessment result on role teacher
This commit is contained in:
parent
2e1bfd66b3
commit
10c219bbbd
|
|
@ -338,16 +338,33 @@
|
||||||
@php
|
@php
|
||||||
$totalBenar = 0;
|
$totalBenar = 0;
|
||||||
$totalSalah = 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) {
|
foreach ($questions as $question) {
|
||||||
$answer = $question->answers->first();
|
$answer = $question->answers->first();
|
||||||
$isCorrect = false;
|
$isCorrect = false;
|
||||||
|
|
||||||
if ($question->type === 'multiple_choice' && $answer) {
|
if ($question->type === 'multiple_choice' && $answer) {
|
||||||
$isCorrect = $answer->option->is_correct;
|
$isCorrect = optional($answer->option)->is_correct;
|
||||||
} elseif ($question->type === 'essay') {
|
} elseif ($question->type === 'essay' && $answer) {
|
||||||
$isCorrect = strtolower(trim($answer->answer_text)) === strtolower(trim($question->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) {
|
if ($isCorrect) {
|
||||||
|
|
@ -357,23 +374,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mengubah status asesmen ke bahasa Indonesia
|
|
||||||
$statusMap = [
|
$statusMap = [
|
||||||
'completed' => 'Selesai',
|
'completed' => 'Selesai',
|
||||||
'in_progress' => 'Sedang Dikerjakan',
|
'in_progress' => 'Sedang Dikerjakan',
|
||||||
'pending' => 'Menunggu',
|
'pending' => 'Menunggu',
|
||||||
];
|
];
|
||||||
$statusAsesmen = $statusMap[$assessment->status] ?? 'Tidak Dikenal'; // Menangani status yang tidak dikenal
|
$statusAsesmen = $statusMap[$assessment->status] ?? 'Tidak Dikenal';
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<p style="font-size: 24px; font-weight: 500; color: #34364A;">Assessment Result</p>
|
<p style="font-size: 24px; font-weight: 500; color: #34364A;">Hasil Asesmen Siswa</p>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<h5>Detail Jawaban</h5>
|
<h5>Detail Jawaban</h5>
|
||||||
|
|
||||||
<!-- Row for Pie Chart and User Information -->
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- Card with Pie Chart -->
|
<!-- Pie Chart & Ringkasan -->
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="card mt-3 p-3 text-center shadow-sm">
|
<div class="card mt-3 p-3 text-center shadow-sm">
|
||||||
<h5 class="mb-2">Ringkasan Jawaban</h5>
|
<h5 class="mb-2">Ringkasan Jawaban</h5>
|
||||||
|
|
@ -381,7 +396,6 @@
|
||||||
<strong class="text-success">Benar: {{ $totalBenar }}</strong> |
|
<strong class="text-success">Benar: {{ $totalBenar }}</strong> |
|
||||||
<strong class="text-danger">Salah: {{ $totalSalah }}</strong>
|
<strong class="text-danger">Salah: {{ $totalSalah }}</strong>
|
||||||
</p>
|
</p>
|
||||||
<!-- Pie Chart -->
|
|
||||||
<div class="d-flex justify-content-center align-items-center">
|
<div class="d-flex justify-content-center align-items-center">
|
||||||
<canvas id="piechart" style="height: 150px; width: 150px;"></canvas>
|
<canvas id="piechart" style="height: 150px; width: 150px;"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -391,7 +405,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Card with User Information and Assessment Status -->
|
<!-- Info Pengguna -->
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="card mt-3 p-3 shadow-sm">
|
<div class="card mt-3 p-3 shadow-sm">
|
||||||
<h5 class="mb-2">Informasi Pengguna</h5>
|
<h5 class="mb-2">Informasi Pengguna</h5>
|
||||||
|
|
@ -408,13 +422,26 @@
|
||||||
@php
|
@php
|
||||||
$answer = $question->answers->first();
|
$answer = $question->answers->first();
|
||||||
$isCorrect = false;
|
$isCorrect = false;
|
||||||
|
$similarityScore = null;
|
||||||
|
|
||||||
if ($question->type === 'multiple_choice' && $answer) {
|
if ($question->type === 'multiple_choice' && $answer) {
|
||||||
$isCorrect = $answer->option->is_correct;
|
$isCorrect = optional($answer->option)->is_correct;
|
||||||
} elseif ($question->type === 'essay') {
|
} elseif ($question->type === 'essay' && $answer) {
|
||||||
$isCorrect = strtolower(trim($answer->answer_text)) === strtolower(trim($question->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
|
@endphp
|
||||||
|
|
||||||
<li class="list-group-item d-flex flex-column">
|
<li class="list-group-item d-flex flex-column">
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<strong>{{ $index + 1 }}. {{ $question->question_text }}</strong>
|
<strong>{{ $index + 1 }}. {{ $question->question_text }}</strong>
|
||||||
|
|
@ -426,7 +453,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="mt-2">
|
<p class="mt-2">
|
||||||
<strong>Jawaban Anda:</strong>
|
<strong>Jawaban Siswa:</strong>
|
||||||
@if ($question->type === 'multiple_choice')
|
@if ($question->type === 'multiple_choice')
|
||||||
{{ optional($answer)->option->option_text ?? 'Tidak Dijawab' }}
|
{{ optional($answer)->option->option_text ?? 'Tidak Dijawab' }}
|
||||||
@else
|
@else
|
||||||
|
|
@ -434,11 +461,9 @@
|
||||||
@endif
|
@endif
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@if ($question->type === 'essay')
|
@if ($question->type === 'essay' && $similarityScore !== null)
|
||||||
<p>
|
<p><strong>Skor Kemiripan:</strong> {{ number_format($similarityScore, 2) }}%</p>
|
||||||
<strong>Feedback:</strong>
|
<p><strong>Feedback:</strong> {{ $answer->feedback ?? 'Tidak ada feedback' }}</p>
|
||||||
{{ optional($answer)->feedback ?? 'Tidak ada feedback' }}
|
|
||||||
</p>
|
|
||||||
@endif
|
@endif
|
||||||
</li>
|
</li>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user