@php $v3 = $v3 ?? []; $summary = $v3['summary'] ?? []; $radar = $v3['radar'] ?? []; $modules = $v3['modules'] ?? []; $paths = $v3['paths'] ?? ['keep' => [], 'boost' => [], 'key' => []]; $rawPaperId = $paper['id'] ?? $paper['paper_id'] ?? 'unknown'; preg_match('/paper_(\d{15})/', $rawPaperId, $matches); $reportCode = $matches[1] ?? preg_replace('/[^0-9]/', '', (string) $rawPaperId); $generateDateTime = now()->format('Y年m月d日 H:i:s'); $scoreObtained = $summary['score_obtained'] ?? null; $scoreTotal = $summary['score_total'] ?? null; $scoreRate = $summary['score_rate'] ?? null; $averageMastery = $summary['average_mastery'] ?? null; $overallLabel = $summary['overall_label'] ?? '待评估'; $difficultySummary = $summary['difficulty'] ?? []; $comparisonSummary = $summary['comparison'] ?? []; $overallLabelDetail = $summary['overall_label_detail'] ?? []; $historySummary = $comparisonSummary['history'] ?? []; $peerSummary = $comparisonSummary['peers'] ?? []; $overallScore = isset($overallLabelDetail['composite_score']) ? (float) $overallLabelDetail['composite_score'] : null; $overallGrade = (string) ($overallLabelDetail['grade'] ?? 'D'); $currentPart = (float) ($overallLabelDetail['current_score'] ?? 0); $historyPart = (float) ($overallLabelDetail['history_score'] ?? 0); $peerPart = (float) ($overallLabelDetail['peer_score'] ?? 0); $adjustPart = (float) ($overallLabelDetail['difficulty_adjust'] ?? 0); $compositeFormulaResult = (0.50 * $currentPart) + (0.25 * $historyPart) + (0.25 * $peerPart) + $adjustPart; $overallBadge = function (string $grade): array { return match ($grade) { 'S' => ['bg' => '#f5f3ff', 'border' => '#6d28d9', 'text' => '#6d28d9', 'class' => 'badge-s'], 'A' => ['bg' => '#ecfdf3', 'border' => '#22c55e', 'text' => '#166534', 'class' => 'badge-excellent'], 'B' => ['bg' => '#eff6ff', 'border' => '#3b82f6', 'text' => '#1d4ed8', 'class' => 'badge-good'], 'C' => ['bg' => '#fff7ed', 'border' => '#f59e0b', 'text' => '#b45309', 'class' => 'badge-average'], default => ['bg' => '#fef2f2', 'border' => '#ef4444', 'text' => '#b91c1c', 'class' => 'badge-weak'], }; }; $overallVisual = $overallBadge((string) $overallGrade); $trendVisual = function (string $trend): array { return match ($trend) { '显著提升' => ['icon' => '▲', 'color' => '#16a34a'], '小幅提升' => ['icon' => '↗', 'color' => '#0ea5e9'], '基本持平' => ['icon' => '•', 'color' => '#64748b'], '小幅回落' => ['icon' => '↘', 'color' => '#f59e0b'], '明显回落' => ['icon' => '▼', 'color' => '#ef4444'], default => ['icon' => '•', 'color' => '#64748b'], }; }; $statusColor = function (string $status): string { return match ($status) { '良好' => '#16a34a', '一般' => '#f97316', '薄弱' => '#e11d48', default => '#64748b', }; }; $n = max(1, count($radar)); $cx = 210; $cy = 155; $r = 108; $outer = []; $inner = []; for ($i = 0; $i < $n; $i++) { $angle = -M_PI / 2 + (2 * M_PI * $i / $n); $ox = $cx + $r * cos($angle); $oy = $cy + $r * sin($angle); $outer[] = [$ox, $oy]; $value = isset($radar[$i]['value']) ? (float) $radar[$i]['value'] : 0.0; $ratio = max(0.0, min(1.0, $value / 5)); $ix = $cx + $r * $ratio * cos($angle); $iy = $cy + $r * $ratio * sin($angle); $inner[] = [$ix, $iy]; } $outerPoints = implode(' ', array_map(fn ($p) => round($p[0], 2).','.round($p[1], 2), $outer)); $innerPoints = implode(' ', array_map(fn ($p) => round($p[0], 2).','.round($p[1], 2), $inner)); $insightMap = []; foreach (($question_insights ?? []) as $insight) { $no = $insight['question_number'] ?? $insight['question_id'] ?? null; if ($no !== null) { $insightMap[$no] = $insight; } } $analysisWrongMap = []; foreach (($analysis_data['question_analysis'] ?? []) as $qa) { $qid = $qa['question_bank_id'] ?? $qa['question_id'] ?? null; if ($qid === null || $qid === '') { continue; } $rawCorrect = $qa['is_correct'] ?? null; $isWrongFromAnalysis = false; if (is_array($rawCorrect)) { $isWrongFromAnalysis = in_array(0, $rawCorrect, true); } elseif ($rawCorrect !== null) { $isWrongFromAnalysis = !boolval($rawCorrect); } if ($isWrongFromAnalysis) { $analysisWrongMap[(string) $qid] = true; } } $wrongQuestions = []; foreach (($questions ?? []) as $qItem) { $isCorrectProbe = $qItem['is_correct'] ?? null; $studentAnswerProbe = $qItem['student_answer'] ?? null; $correctAnswerProbe = $qItem['answer'] ?? ($qItem['correct_answer'] ?? null); if ($isCorrectProbe === null && !empty($studentAnswerProbe) && !empty($correctAnswerProbe)) { $isCorrectProbe = (trim((string) $studentAnswerProbe) === trim((string) $correctAnswerProbe)) ? 1 : 0; } $normalizedCorrect = $isCorrectProbe; if ($isCorrectProbe !== null) { $normalizedCorrect = is_bool($isCorrectProbe) ? ($isCorrectProbe ? 1 : 0) : intval($isCorrectProbe); } $qidProbe = (string) ($qItem['question_bank_id'] ?? $qItem['question_id'] ?? ''); $isWrongByAnalysis = ($qidProbe !== '' && isset($analysisWrongMap[$qidProbe])); if ($normalizedCorrect === 0 || $isWrongByAnalysis) { $wrongQuestions[] = $qItem; } } $kpStats = []; foreach (($questions ?? []) as $qItem) { $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点')); $kpName = $kpName === '' ? '未标注知识点' : $kpName; if (!isset($kpStats[$kpName])) { $kpStats[$kpName] = ['total' => 0, 'wrong' => 0]; } $kpStats[$kpName]['total']++; } foreach ($wrongQuestions as $qItem) { $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点')); $kpName = $kpName === '' ? '未标注知识点' : $kpName; if (!isset($kpStats[$kpName])) { $kpStats[$kpName] = ['total' => 0, 'wrong' => 0]; } $kpStats[$kpName]['wrong']++; } $kpWrongStats = []; foreach ($kpStats as $kpName => $stat) { if (($stat['wrong'] ?? 0) <= 0) { continue; } $total = max(1, intval($stat['total'] ?? 0)); $wrong = intval($stat['wrong'] ?? 0); $kpWrongStats[] = [ 'kp_name' => $kpName, 'wrong' => $wrong, 'total' => $total, 'rate' => $wrong / $total, ]; } usort($kpWrongStats, function ($a, $b) { if ($a['rate'] === $b['rate']) { return $b['wrong'] <=> $a['wrong']; } return $b['rate'] <=> $a['rate']; }); $childMasteryStatus = function ($mastery): string { if ($mastery === null) { return '未学习'; } $m = (float) $mastery * 100; // 与 math.client-pc 统一:0-100 阈值(85/60) if ($m >= 85) { return '已掌握'; } if ($m >= 60) { return '薄弱'; } return '未入门'; }; $childStatusColor = function ($status): string { return match ($status) { '已掌握' => '#52c41a', '薄弱' => '#faad14', '未入门' => '#f5222d', default => '#d9d9d9', }; }; $calcStats = function (array $points): array { $total = count($points); $learned = 0; $mastered = 0; $weak = 0; $beginner = 0; $unlearned = 0; foreach ($points as $p) { if (($p['mastery_level'] ?? null) !== null) { $learned++; } $status = (string) ($p['status'] ?? '未学习'); if ($status === '已掌握') { $mastered++; } elseif ($status === '薄弱') { $weak++; } elseif ($status === '未入门') { $beginner++; } else { $unlearned++; } } return [ 'total' => $total, 'learned' => $learned, 'mastered' => $mastered, 'weak' => $weak, 'beginner' => $beginner, 'unlearned' => $unlearned, ]; }; $clusterCards = []; $allClusterPoints = []; foreach ($radar as $moduleItem) { $children = is_array($moduleItem['children'] ?? null) ? $moduleItem['children'] : []; $greatMap = []; foreach ($children as $child) { $greatKey = trim((string) ($child['great_grand_parent_name'] ?? '')); $greatKey = $greatKey !== '' ? $greatKey : '未分组'; $grandKey = trim((string) ($child['grand_parent_name'] ?? '')); $grandKey = $grandKey !== '' ? $grandKey : '未分组'; $parentName = trim((string) ($child['parent_name'] ?? '')); if ($parentName === '') { $parentCode = trim((string) ($child['parent_code'] ?? '')); $parentName = $parentCode !== '' ? $parentCode : '未分组'; } $mastery = isset($child['mastery_level']) ? (float) $child['mastery_level'] : null; $status = $childMasteryStatus($mastery); if (!isset($greatMap[$greatKey])) { $greatMap[$greatKey] = []; } if (!isset($greatMap[$greatKey][$grandKey])) { $greatMap[$greatKey][$grandKey] = []; } if (!isset($greatMap[$greatKey][$grandKey][$parentName])) { $greatMap[$greatKey][$grandKey][$parentName] = []; } $greatMap[$greatKey][$grandKey][$parentName][] = [ 'code' => (string) ($child['code'] ?? ''), 'name' => (string) ($child['name'] ?? '未命名知识点'), 'path' => (string) ($child['path'] ?? ''), 'mastery_level' => $mastery, 'change' => isset($child['change']) ? (float) $child['change'] : null, 'status' => $status, 'color' => $childStatusColor($status), 'is_hit' => !empty($child['is_hit']), ]; } $greatGroups = []; foreach ($greatMap as $greatName => $grandMap) { $grandGroups = []; foreach ($grandMap as $grandName => $parentMap) { $parentGroups = []; foreach ($parentMap as $parentName => $points) { usort($points, function ($a, $b) { $am = $a['mastery_level'] ?? -1; $bm = $b['mastery_level'] ?? -1; if ($am === $bm) { return strcmp((string) ($a['name'] ?? ''), (string) ($b['name'] ?? '')); } return $bm <=> $am; }); $parentGroups[] = [ 'parent_name' => $parentName, 'points' => $points, 'stats' => $calcStats($points), ]; } // 子模块级过滤:整行没有任何掌握度数字则不显示 $parentGroups = array_values(array_filter($parentGroups, function ($pg) { return (($pg['stats']['learned'] ?? 0) > 0); })); if (empty($parentGroups)) { continue; } usort($parentGroups, function ($a, $b) { $sa = $a['stats']; $sb = $b['stats']; return ($sb['learned'] <=> $sa['learned']) ?: ($sb['total'] <=> $sa['total']); }); $allGrandPoints = []; foreach ($parentGroups as $pg) { $allGrandPoints = array_merge($allGrandPoints, $pg['points']); } $grandGroups[] = [ 'grand_name' => $grandName, 'parent_groups' => $parentGroups, 'stats' => $calcStats($allGrandPoints), ]; } // 大块级过滤:整块没有任何掌握度数字则不显示 $grandGroups = array_values(array_filter($grandGroups, function ($gg) { return (($gg['stats']['learned'] ?? 0) > 0); })); if (empty($grandGroups)) { continue; } usort($grandGroups, function ($a, $b) { $sa = $a['stats']; $sb = $b['stats']; return ($sb['learned'] <=> $sa['learned']) ?: ($sb['total'] <=> $sa['total']); }); $allGreatPoints = []; foreach ($grandGroups as $gg) { foreach ($gg['parent_groups'] as $pg) { $allGreatPoints = array_merge($allGreatPoints, $pg['points']); } } $greatGroups[] = [ 'great_name' => $greatName, 'grand_groups' => $grandGroups, 'stats' => $calcStats($allGreatPoints), ]; } usort($greatGroups, function ($a, $b) { $sa = $a['stats']; $sb = $b['stats']; return ($sb['learned'] <=> $sa['learned']) ?: ($sb['total'] <=> $sa['total']); }); // 严格参考 math.client-pc:扁平化为“grand 层卡片”(展示大块) foreach ($greatGroups as $great) { foreach (($great['grand_groups'] ?? []) as $grand) { $gStats = $grand['stats'] ?? ['learned' => 0, 'total' => 0]; $clusterCards[] = [ 'great_name' => $great['great_name'] ?? '未分组', 'grand_name' => $grand['grand_name'] ?? '未分组', 'parent_groups' => $grand['parent_groups'] ?? [], 'stats' => $gStats, ]; } } } usort($clusterCards, function ($a, $b) { $sa = $a['stats'] ?? ['learned' => 0, 'total' => 0]; $sb = $b['stats'] ?? ['learned' => 0, 'total' => 0]; return (($sb['learned'] ?? 0) <=> ($sa['learned'] ?? 0)) ?: (($sb['total'] ?? 0) <=> ($sa['total'] ?? 0)); }); foreach ($clusterCards as $card) { foreach (($card['parent_groups'] ?? []) as $pg) { foreach (($pg['points'] ?? []) as $p) { $allClusterPoints[] = $p; } } } $kpStatsTotal = [ 'total' => count($allClusterPoints), 'mastered' => 0, 'weak' => 0, 'beginner' => 0, 'unlearned' => 0, ]; foreach ($allClusterPoints as $p) { $st = (string) ($p['status'] ?? '未学习'); if ($st === '已掌握') { $kpStatsTotal['mastered']++; } elseif ($st === '薄弱') { $kpStatsTotal['weak']++; } elseif ($st === '未入门') { $kpStatsTotal['beginner']++; } else { $kpStatsTotal['unlearned']++; } } $moduleRowsWithStatus = array_values(array_filter($modules, function ($m) { $status = trim((string) ($m['status'] ?? '')); $masteryLevel = $m['mastery_level'] ?? null; if ($masteryLevel !== null) { return true; } return $status !== '' && ! in_array($status, ['暂无', '-', '未涉及'], true); })); $pathTagByModuleName = []; foreach (['keep' => '保分不错', 'boost' => '需要加强', 'key' => '优先加强'] as $bucket => $tagName) { foreach (($paths[$bucket] ?? []) as $item) { $n = trim((string) ($item['name'] ?? '')); if ($n === '') { continue; } $pathTagByModuleName[$n] = $tagName; } } $impactedModules = array_values(array_filter($moduleRowsWithStatus, function ($m) { return ((int) ($m['question_count'] ?? 0)) > 0; })); $radarModuleMap = []; foreach ($radar as $moduleItem) { $code = (string) ($moduleItem['code'] ?? ''); if ($code !== '') { $radarModuleMap[$code] = $moduleItem; } } $moduleImpactChangeMap = []; foreach ($radarModuleMap as $moduleCode => $moduleItem) { $hitChanges = []; foreach (($moduleItem['children'] ?? []) as $child) { if (empty($child['is_hit'])) { continue; } $change = $child['change'] ?? null; if ($change === null || ! is_numeric($change)) { continue; } $hitChanges[] = (float) $change; } if (empty($hitChanges)) { continue; } $moduleImpactChangeMap[$moduleCode] = array_sum($hitChanges) / count($hitChanges); } $questionTypeLabelMap = [ 'choice' => '选择题', 'multiple_choice' => '选择题', 'single_choice' => '选择题', 'select' => '选择题', 'fill' => '填空题', 'blank' => '填空题', 'answer' => '解答题', 'solution' => '解答题', ]; $kpQuestionTypeMap = []; foreach (($questions ?? []) as $qItem) { $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '')); if ($kpName === '') { continue; } $rawType = strtolower(trim((string) ($qItem['question_type'] ?? ''))); $typeLabel = $questionTypeLabelMap[$rawType] ?? ((string) ($qItem['question_type'] ?? '未知题型')); if ($typeLabel === '') { $typeLabel = '未知题型'; } if (! isset($kpQuestionTypeMap[$kpName])) { $kpQuestionTypeMap[$kpName] = []; } $kpQuestionTypeMap[$kpName][$typeLabel] = true; } $moduleKpSuggestions = []; foreach ($moduleRowsWithStatus as $m) { $moduleCode = (string) ($m['module_code'] ?? ''); $moduleName = (string) ($m['module_name'] ?? '-'); $moduleChildren = $radarModuleMap[$moduleCode]['children'] ?? []; if (! is_array($moduleChildren) || empty($moduleChildren)) { continue; } $started = array_values(array_filter($moduleChildren, function ($c) { return isset($c['mastery_level']) && $c['mastery_level'] !== null; })); usort($started, function ($a, $b) { $am = (float) ($a['mastery_level'] ?? 0); $bm = (float) ($b['mastery_level'] ?? 0); if ($am === $bm) { return strcmp((string) ($a['name'] ?? ''), (string) ($b['name'] ?? '')); } return $am <=> $bm; }); $weakest = null; if (! empty($started)) { $lowestStarted = $started[0]; $lowestStartedLevel = isset($lowestStarted['mastery_level']) ? (float) $lowestStarted['mastery_level'] : null; if ($lowestStartedLevel !== null && $lowestStartedLevel < 0.85) { // 规则1:已开始学习中掌握度最低 $weakest = $lowestStarted; } else { // 规则2:若已开始学习均达标(>=85%),取“最近的未学习” $unlearned = array_values(array_filter($moduleChildren, function ($c) { return !isset($c['mastery_level']) || $c['mastery_level'] === null; })); if (! empty($unlearned)) { $anchorParent = (string) ($lowestStarted['parent_name'] ?? ''); $anchorGrand = (string) ($lowestStarted['grand_parent_name'] ?? ''); usort($unlearned, function ($a, $b) use ($anchorParent, $anchorGrand) { $score = function ($node) use ($anchorParent, $anchorGrand) { $parent = (string) ($node['parent_name'] ?? ''); $grand = (string) ($node['grand_parent_name'] ?? ''); if ($anchorParent !== '' && $parent === $anchorParent) { return 0; } if ($anchorGrand !== '' && $grand === $anchorGrand) { return 1; } return 2; }; $sa = $score($a); $sb = $score($b); if ($sa === $sb) { return strcmp((string) ($a['name'] ?? ''), (string) ($b['name'] ?? '')); } return $sa <=> $sb; }); $weakest = $unlearned[0]; } else { $weakest = $lowestStarted; } } } else { // 没有已开始学习数据时,回退到模块内任一未学习点 $unlearned = array_values(array_filter($moduleChildren, function ($c) { return !isset($c['mastery_level']) || $c['mastery_level'] === null; })); if (! empty($unlearned)) { usort($unlearned, fn ($a, $b) => strcmp((string) ($a['name'] ?? ''), (string) ($b['name'] ?? ''))); $weakest = $unlearned[0]; } } if (! is_array($weakest)) { continue; } $kpName = (string) ($weakest['name'] ?? ''); if ($kpName === '') { continue; } $types = array_keys($kpQuestionTypeMap[$kpName] ?? []); $moduleKpSuggestions[] = [ 'module_name' => $moduleName, 'path_tag' => $pathTagByModuleName[$moduleName] ?? '待观察', 'kp_name' => $kpName, 'mastery_level' => $weakest['mastery_level'] ?? null, 'status' => $childMasteryStatus($weakest['mastery_level'] ?? null), 'question_types' => $types, ]; } $moduleSuggestionByName = []; foreach ($moduleKpSuggestions as $sug) { $name = trim((string) ($sug['module_name'] ?? '')); if ($name !== '') { $moduleSuggestionByName[$name] = $sug; } } $kpChangeItems = array_values(array_filter($allClusterPoints, function ($p) { $change = $p['change'] ?? null; return $change !== null && is_numeric($change) && !empty($p['is_hit']); })); if (empty($kpChangeItems)) { $kpChangeItems = array_values(array_filter($allClusterPoints, function ($p) { $change = $p['change'] ?? null; return $change !== null && is_numeric($change); })); } usort($kpChangeItems, function ($a, $b) { return abs((float) ($b['change'] ?? 0)) <=> abs((float) ($a['change'] ?? 0)); }); $kpPct = function (int $count, int $total): string { if ($total <= 0) { return '0.0%'; } return number_format(($count * 100.0) / $total, 1) . '%'; }; @endphp
| 模块 | 本次影响 | 掌握度 (学案影响) |
掌握状态 | 题目数 | 得分率 | 路径建议 | 关注知识点 |
|---|---|---|---|---|---|---|---|
| {{ $m['module_name'] ?? '-' }} | @if($isImpacted) 是 @else 否 @endif | {{ isset($m['mastery_level']) && $m['mastery_level'] !== null ? number_format((float) $m['mastery_level'] * 100, 1) . '%' : '-' }} @if($impactArrow !== '') {{ $impactArrow }}{{ $impactSuffix }} @endif | {{ $status }} | {{ $m['question_count'] ?? 0 }} | {{ $rate !== null ? number_format((float) $rate * 100, 1) . '%' : '-' }} | {{ $pathTag }} | {{ $focusText }} |
| 暂无掌握状态数据 | |||||||