Award partial points from AI assessment

This commit is contained in:
Wojtek
2026-10-16 12:43:22 +02:00
parent af98d0d1d4
commit aa12305e65
5 changed files with 39 additions and 10 deletions
@@ -132,26 +132,34 @@ class ResultModel extends BaseDatabaseModel
);
}
$feedback = (new AiService())->evaluate(
$aiResult = (new AiService())->evaluate(
$provider,
$apiKey,
strip_tags((string) $question->question),
(string) ($answer['selected'] ?? ''),
(string) $question->answer_open
(string) $question->answer_open,
(int) $question->points
);
$item->answers[$questionId]['ai_feedback'] = $feedback;
$item->answers[$questionId]['ai_feedback'] = $aiResult['feedback'];
$item->answers[$questionId]['awarded_points'] = $aiResult['awarded_points'];
$correctionPoints = 0;
foreach ($item->answers as $savedAnswer) {
$correctionPoints += (int) ($savedAnswer['awarded_points'] ?? 0);
}
$db = Factory::getContainer()->get('DatabaseDriver');
$row = (object) [
'id' => $id,
'answers' => json_encode($item->answers, JSON_UNESCAPED_UNICODE),
'points_after' => (int) $item->points_before + $correctionPoints,
];
if (!$db->updateObject('#__testquestions_results', $row, 'id')) {
throw new \RuntimeException('Nie udało się zapisać oceny AI.');
}
return $feedback;
return $aiResult['feedback'];
}
public function evaluateAllWithAi(int $id): array