|
@@ -1071,6 +1071,36 @@ class IntelligentExamController extends Controller
|
|
|
$adjustedQuestions[$index]['score'] = $questionScores[$index] ?? 5;
|
|
$adjustedQuestions[$index]['score'] = $questionScores[$index] ?? 5;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $total = array_sum(array_column($adjustedQuestions, 'score'));
|
|
|
|
|
+ $diff = (int) $targetTotalScore - (int) $total;
|
|
|
|
|
+ if ($diff !== 0 && ! empty($adjustedQuestions)) {
|
|
|
|
|
+ $count = count($adjustedQuestions);
|
|
|
|
|
+ $i = $count - 1;
|
|
|
|
|
+ while ($diff !== 0) {
|
|
|
|
|
+ $score = $adjustedQuestions[$i]['score'];
|
|
|
|
|
+ if ($diff > 0) {
|
|
|
|
|
+ $adjustedQuestions[$i]['score'] = $score + 1;
|
|
|
|
|
+ $diff--;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if ($score > 1) {
|
|
|
|
|
+ $adjustedQuestions[$i]['score'] = $score - 1;
|
|
|
|
|
+ $diff++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $i--;
|
|
|
|
|
+ if ($i < 0) {
|
|
|
|
|
+ $i = $count - 1;
|
|
|
|
|
+ if ($diff < 0) {
|
|
|
|
|
+ $minScore = min(array_column($adjustedQuestions, 'score'));
|
|
|
|
|
+ if ($minScore <= 1) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return $adjustedQuestions;
|
|
return $adjustedQuestions;
|
|
|
}
|
|
}
|
|
|
|
|
|