|
@@ -2840,6 +2840,48 @@ class LearningAnalyticsService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (count($selected) < $totalQuestions) {
|
|
|
|
|
+ $remainingNeed = $totalQuestions - count($selected);
|
|
|
|
|
+ $targetPool = [];
|
|
|
|
|
+ foreach ($targetKpOrder as $kpCode) {
|
|
|
|
|
+ $targetPool = array_merge($targetPool, $questionsByKp[$kpCode] ?? []);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $backfillSelected = $this->takeQuestionsForPracticeTarget(
|
|
|
|
|
+ $targetPool,
|
|
|
|
|
+ $remainingNeed,
|
|
|
|
|
+ null,
|
|
|
|
|
+ [],
|
|
|
|
|
+ $usedIds
|
|
|
|
|
+ );
|
|
|
|
|
+ foreach ($backfillSelected as $question) {
|
|
|
|
|
+ $question['practice_backfill_reason'] = 'target_kp_shortage';
|
|
|
|
|
+ $selected[] = $question;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $remainingNeed = $totalQuestions - count($selected);
|
|
|
|
|
+ if ($remainingNeed > 0 && $supplementQuestions !== []) {
|
|
|
|
|
+ $supplementBackfill = $this->takeQuestionsForPracticeTarget(
|
|
|
|
|
+ $supplementQuestions,
|
|
|
|
|
+ $remainingNeed,
|
|
|
|
|
+ null,
|
|
|
|
|
+ [],
|
|
|
|
|
+ $usedIds
|
|
|
|
|
+ );
|
|
|
|
|
+ foreach ($supplementBackfill as $question) {
|
|
|
|
|
+ $question['practice_backfill_reason'] = 'supplement_kp_shortage';
|
|
|
|
|
+ $selected[] = $question;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Log::info('selectQuestionsByKpTargets: applied global backfill', [
|
|
|
|
|
+ 'target_count' => $totalQuestions,
|
|
|
|
|
+ 'selected_count' => count($selected),
|
|
|
|
|
+ 'shortage_by_kp' => $shortageByKp,
|
|
|
|
|
+ 'backfill_count' => count($selected) - ($totalQuestions - array_sum($shortageByKp)),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (count($selected) < $totalQuestions) {
|
|
if (count($selected) < $totalQuestions) {
|
|
|
Log::warning('selectQuestionsByKpTargets: planned KP selection produced fewer questions', [
|
|
Log::warning('selectQuestionsByKpTargets: planned KP selection produced fewer questions', [
|
|
|
'target_count' => $totalQuestions,
|
|
'target_count' => $totalQuestions,
|