Award partial points from AI assessment
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user