Просмотр исходного кода

fix: backfill wrong question practice shortages

yemeishu 1 неделя назад
Родитель
Сommit
493f4f373d
1 измененных файлов с 42 добавлено и 0 удалено
  1. 42 0
      app/Services/LearningAnalyticsService.php

+ 42 - 0
app/Services/LearningAnalyticsService.php

@@ -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) {
             Log::warning('selectQuestionsByKpTargets: planned KP selection produced fewer questions', [
                 'target_count' => $totalQuestions,