| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386 |
- @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
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <title>学情分析报告</title>
- <link rel="stylesheet" href="/css/katex/katex.min.css">
- <style>
- @page {
- size: A4;
- margin: 2.2cm 2cm 2.3cm 2cm;
- @top-left { content: "知了数学·{{ $generateDateTime }}"; font-size: 13px; color: #666; }
- @top-center { content: "{{ $student['name'] ?? '-' }}"; font-size: 13px; color: #666; }
- @top-right {
- content: "{{ $reportCode }}";
- font-size: 19px;
- font-weight: 600;
- font-family: "Noto Sans", "Liberation Sans", "Nimbus Sans", sans-serif;
- color: #222;
- }
- @bottom-left { content: "{{ $reportCode }}"; font-size: 11px; color: #666; }
- @bottom-right { content: counter(page) "/" counter(pages); font-size: 13px; color: #666; }
- }
- * { box-sizing: border-box; }
- body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; margin: 0; color: #0f172a; font-size: 13px; line-height: 1.65; }
- .page { page-break-after: auto; }
- .header { text-align: left; margin-bottom: 16px; }
- .paper-title { font-size: 30px; font-weight: 700; margin-bottom: 8px; color: #0b3a75; letter-spacing: 1px; }
- .section { margin-bottom: 14px; page-break-inside: auto; break-inside: auto; }
- .section-title { font-size: 20px; margin-bottom: 10px; font-weight: 700; color: #0b3a75; border-left: 5px solid #3b82f6; padding-left: 10px; line-height: 1.3; }
- .card { border: 1px solid #dbeafe; border-radius: 12px; padding: 14px; background: #f8fbff; position: relative; }
- .summary-list { margin: 0; padding-left: 18px; }
- .summary-list li { margin: 6px 0; font-size: 13px; }
- .overall-badge {
- position: absolute;
- right: 14px;
- top: 12px;
- border-radius: 12px;
- border: 0;
- padding: 9px 16px;
- min-width: 0;
- width: auto;
- text-align: center;
- position: absolute;
- overflow: hidden;
- display: inline-block;
- white-space: nowrap;
- background: transparent !important;
- }
- .overall-badge .level { font-size: 28px; font-weight: 800; line-height: 1.05; letter-spacing: 1px; }
- .overall-badge .score { font-size: 13px; margin-top: 3px; }
- .overall-badge.badge-s {
- border: 5px solid #6d28d9;
- border-radius: 14px;
- box-shadow: none;
- transform: rotate(-7deg);
- }
- .overall-badge.badge-s::before {
- content: "";
- position: absolute;
- inset: 4px;
- border: 2px dashed rgba(109, 40, 217, 0.65);
- border-radius: 10px;
- pointer-events: none;
- }
- .overall-badge.badge-s .level {
- letter-spacing: 2px;
- text-shadow: 0 1px 0 rgba(109, 40, 217, 0.24);
- }
- .overall-badge.badge-excellent {
- border: 3px double #16a34a;
- border-radius: 999px;
- box-shadow: none;
- }
- .overall-badge.badge-good {
- border: 2px solid #2563eb;
- border-radius: 10px;
- clip-path: polygon(6% 0, 94% 0, 100% 50%, 94% 100%, 6% 100%, 0 50%);
- box-shadow: none;
- }
- .overall-badge.badge-average {
- border: 2px dashed #d97706;
- border-radius: 14px;
- box-shadow: none;
- }
- .overall-badge.badge-weak {
- border-left: 3px solid #ef4444;
- border-right: 0;
- border-top: 0;
- border-bottom: 2px solid #ef4444;
- border-radius: 0 10px 10px 0;
- box-shadow: none;
- }
- .overall-meta { margin-top: 8px; font-size: 9px; color: #64748b; line-height: 1.6; white-space: nowrap; }
- .radar-center { text-align: center; }
- .legend { margin-top: 8px; font-size: 12px; color: #475569; }
- .legend span { margin: 0 8px; }
- .dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-right: 4px; vertical-align: middle; }
- /* PDF 版优先上下结构,避免左右分栏导致拥挤 */
- .radar-split { display: block; width: 100%; }
- .radar-left { width: 100%; text-align: center; }
- .radar-right { width: 100%; padding-left: 0; margin-top: 10px; }
- .radar-desc { border: 1px solid #dbeafe; background: #f8fbff; border-radius: 12px; padding: 12px; text-align: left; }
- .radar-item { display: block; margin: 6px 0; font-size: 12px; }
- .cluster-toolbar {
- margin-bottom: 8px;
- font-size: 12px;
- color: #475569;
- }
- .cluster-legend { display: inline-block; margin-right: 12px; }
- .cluster-grid {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 10px;
- }
- .cluster-card {
- border: 1px solid #e2e8f0;
- border-radius: 10px;
- padding: 10px;
- background: #fff;
- }
- .cluster-card-title {
- font-size: 14px;
- font-weight: 700;
- color: #0f172a;
- margin-bottom: 8px;
- }
- .cluster-subgroup {
- border-left: 2px solid #e5e7eb;
- padding-left: 8px;
- margin-bottom: 8px;
- }
- .cluster-subgroup:last-child { margin-bottom: 0; }
- .cluster-subgroup-title {
- font-size: 12px;
- font-weight: 600;
- color: #334155;
- margin-bottom: 4px;
- }
- .cluster-points {
- display: flex;
- flex-wrap: wrap;
- gap: 4px;
- }
- .cluster-point {
- width: 10px;
- height: 10px;
- border-radius: 2px;
- display: inline-block;
- border: 1px solid rgba(148, 163, 184, 0.35);
- }
- .cluster-empty {
- font-size: 12px;
- color: #64748b;
- background: #f8fafc;
- border: 1px dashed #cbd5e1;
- border-radius: 8px;
- padding: 10px;
- }
- .kp-stats-grid {
- display: grid;
- grid-template-columns: repeat(5, 1fr);
- border: 1px solid #e5e7eb;
- border-radius: 10px;
- overflow: hidden;
- margin-bottom: 10px;
- }
- .kp-stat-item {
- padding: 8px 10px;
- border-right: 1px solid #e5e7eb;
- background: #fff;
- }
- .kp-stat-item:last-child { border-right: none; }
- .kp-stat-label { font-size: 11px; color: #64748b; }
- .kp-stat-value { font-size: 18px; font-weight: 700; color: #111827; line-height: 1.2; margin-top: 2px; }
- .kp-stat-rate { font-size: 11px; margin-left: 4px; font-weight: 600; }
- .kp-change-box { margin-bottom: 10px; border: 1px solid #e5e7eb; border-radius: 10px; background: #f8fafc; padding: 10px 12px; }
- .kp-change-list { margin: 4px 0 0 16px; padding: 0; }
- .kp-change-list li { margin: 2px 0; color: #334155; }
- .kp-burst-card { margin-top: 10px; border: 1px solid #dbeafe; border-radius: 12px; padding: 10px; background: #fff; }
- .kp-burst-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; color: #0b3a75; }
- .kp-burst-meta { font-size: 12px; color: #334155; margin-top: 6px; line-height: 1.6; }
- .kp-burst-list { margin-top: 6px; font-size: 11px; color: #334155; line-height: 1.5; }
- .kp-burst-list span { display: inline-block; margin-right: 10px; margin-bottom: 3px; }
- table { width: 100%; border-collapse: collapse; font-size: 12px; background: #fff; }
- th, td { border: 1px solid #d0d7e2; padding: 8px 10px; text-align: left; vertical-align: top; }
- th { background: #f1f5f9; color: #1e293b; font-weight: 700; }
- .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; color: #fff; font-size: 11px; font-weight: 600; }
- .module-table th { background: #edf2ff; color: #0f172a; }
- .module-table th { text-align: center; }
- .module-table td { line-height: 1.45; }
- .module-table th,
- .module-table td { vertical-align: middle; }
- .module-table th:nth-child(8),
- .module-table td:nth-child(8) { vertical-align: top; }
- .module-table th:nth-child(1),
- .module-table td:nth-child(1) { text-align: center; }
- .module-table td:nth-child(2),
- .module-table td:nth-child(3),
- .module-table td:nth-child(5),
- .module-table td:nth-child(6),
- .module-table td:nth-child(7) { text-align: center; white-space: nowrap; }
- .module-table td:nth-child(8) { font-size: 11px; color: #334155; }
- .module-table tbody tr:nth-child(even) td { background: #fcfdff; }
- .module-name { font-weight: 600; color: #0f172a; }
- .impact-yes { color:#2563eb; font-weight:600; }
- .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; color: #334155; background: #e5e7eb; }
- .error-kp-tag { display: inline-block; margin: 0 6px 6px 0; padding: 1px 7px; border-radius: 999px; font-size: 10px; color: #334155; background: #f8fafc; border: 1px solid #d1d5db; }
- .error-kp-tag.high-risk { color: #b91c1c; border-color: #fca5a5; background: #fff; font-weight: 600; }
- .question-card { border:1px solid #e5e7eb; border-radius:8px; padding:6px 9px; margin-bottom:5px; background:#fff; page-break-inside:auto; break-inside:auto; }
- .question-block { margin-bottom: 5px; padding: 5px; border-radius: 4px; page-break-inside: auto; break-inside: auto; }
- .question-card,
- .question-card .math-content,
- .question-card .solution-content { font-size: 12px; line-height: 1.7; }
- .question-card .question-stem svg,
- .question-card .math-content svg { max-width: 100%; height: auto; display: block; shape-rendering: geometricPrecision; text-rendering: geometricPrecision; }
- .question-card .question-stem svg text {
- font-family: "Noto Serif", "Noto Serif CJK SC", "Noto Sans CJK SC", "Noto Sans", "STSongti-SC", "PingFang SC", "Songti SC", serif !important;
- font-size: 13px !important;
- font-weight: bold;
- dominant-baseline: middle;
- text-anchor: middle;
- }
- .question-card .question-stem svg circle,
- .question-card .question-stem svg line,
- .question-card .question-stem svg polygon,
- .question-card .question-stem svg polyline { shape-rendering: geometricPrecision; }
- .question-card .question-stem img,
- .question-card .question-main img {
- display: block;
- max-width: 220px;
- max-height: 60mm;
- width: auto;
- height: auto;
- margin: 6px auto;
- box-sizing: border-box;
- object-fit: contain;
- -webkit-print-color-adjust: exact;
- print-color-adjust: exact;
- image-rendering: -webkit-optimize-contrast;
- }
- .question-card .question-stem .katex { font-size: 1em !important; vertical-align: 0; }
- .question-card .question-stem .katex-display { margin: 0.35em 0 !important; }
- .question-card .solution-content img,
- .question-card .report-answer-meta img {
- display: block;
- max-width: 220px;
- max-height: 60mm;
- width: auto;
- height: auto;
- margin: 6px auto;
- object-fit: contain;
- -webkit-print-color-adjust: exact;
- print-color-adjust: exact;
- }
- .solution-content {
- display: block;
- line-height: 1.75;
- white-space: normal;
- word-break: break-word;
- overflow-wrap: anywhere;
- page-break-inside: auto;
- break-inside: auto;
- }
- .report-options { margin-top: 6px; page-break-inside: auto; break-inside: auto; }
- .report-options.options-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 12px; }
- .report-options.options-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; }
- .report-options.options-grid-1 { display: grid; grid-template-columns: 1fr; gap: 8px; }
- .report-options .option { display: flex; align-items: baseline; font-size: 12px; line-height: 1.6; page-break-inside: auto; break-inside: auto; }
- .report-options .option strong { margin-right: 4px; flex: 0 0 auto; }
- .report-options .option-value.option-short { white-space: nowrap; }
- .report-options .option-value.option-long { white-space: normal; word-break: break-word; }
- .report-options .option p, .report-options .option div { margin: 0; display: inline; }
- .report-options .option img { max-width: 100%; height: auto; vertical-align: middle; }
- .report-answer-meta { font-size: 12px; color: #2f2f2f; line-height: 1.75; margin-top: 6px; page-break-inside: auto; break-inside: auto; }
- .report-answer-meta .answer-line + .answer-line { margin-top: 4px; }
- .report-answer-meta .solution-content { display: inline; line-height: 1.75; }
- .muted { color: #6b7280; font-size: 12px; }
- </style>
- </head>
- <body>
- <div class="page">
- <div class="header">
- <h1 class="paper-title">学情分析报告</h1>
- </div>
- <div class="section">
- <div class="section-title">一、总体评估</div>
- <div class="card">
- <div class="overall-badge {{ $overallVisual['class'] ?? '' }}"
- style="border-color:{{ $overallVisual['border'] }}; color:{{ $overallVisual['text'] }};">
- <div class="level">{{ $overallGrade }}</div>
- </div>
- <ul class="summary-list">
- <li>本次诊断得分:
- @if($scoreObtained !== null && $scoreTotal !== null && $scoreTotal > 0)
- {{ rtrim(rtrim(number_format((float) $scoreObtained, 1), '0'), '.') }}/{{ rtrim(rtrim(number_format((float) $scoreTotal, 1), '0'), '.') }}
- @else
- 暂无得分数据
- @endif
- </li>
- <li>得分率:{{ $scoreRate !== null ? number_format((float) $scoreRate * 100, 1) . '%' : '暂无得分率' }}</li>
- <li>平均掌握度:{{ $averageMastery !== null ? number_format((float) $averageMastery * 100, 1) . '%' : '暂无掌握度' }}</li>
- <li>
- 难度匹配:
- @if(!empty($difficultySummary['target_label']) && isset($difficultySummary['actual_average_difficulty']))
- 目标 {{ $difficultySummary['target_label'] }}
- @if(!empty($difficultySummary['target_range']))
- ({{ number_format((float)($difficultySummary['target_range']['min'] ?? 0), 2) }}~{{ number_format((float)($difficultySummary['target_range']['max'] ?? 0), 2) }})
- @endif
- ,实际 {{ number_format((float)($difficultySummary['actual_average_difficulty'] ?? 0), 3) }}
- ({{ $difficultySummary['status'] ?? '暂无' }})
- @else
- 暂无难度匹配数据
- @endif
- </li>
- @if(!empty($difficultySummary['explain']))
- <li>难度说明:{{ $difficultySummary['explain'] }}</li>
- @endif
- <li>
- 与历史自己对比:
- @if(!empty($historySummary['is_first_exam']))
- {{ $historySummary['message'] ?? '这是你的第一次分析报告,先积累样本再看趋势。' }}
- @elseif(!empty($historySummary['low_baseline_guard']))
- {{ $historySummary['message'] ?? '历史基线偏低,建议看连续趋势。' }}
- @elseif(!empty($historySummary['has_data']))
- @php
- $trendText = (string)($historySummary['trend'] ?? '—');
- $tVisual = $trendVisual($trendText);
- @endphp
- 近几次均值对比:
- {{ number_format((float)($historySummary['baseline_score_rate'] ?? 0) * 100, 1) }}%,
- 本次{{ ($historySummary['delta_score_rate'] ?? 0) >= 0 ? '提升' : '回落' }}
- {{ number_format(abs((float)($historySummary['delta_score_rate'] ?? 0)) * 100, 1) }}%
- (<span style="color:{{ $tVisual['color'] ?? '#64748b' }}; font-weight:600;">{{ $tVisual['icon'] ?? '•' }} {{ $trendText }}</span>)
- @else
- {{ $historySummary['message'] ?? '历史样本不足' }}
- @endif
- </li>
- @if(!empty($peerSummary['show_line']))
- <li>
- 与同群体对比:
- {{ $peerSummary['message'] ?? '' }}
- (<span style="color:{{ $peerSummary['band_color'] ?? '#64748b' }}; font-weight:600;">{{ $peerSummary['band_icon'] ?? '•' }} {{ $peerSummary['band'] ?? '—' }}</span>)
- </li>
- @endif
- <li>
- 整体水平:
- @if($overallScore !== null)
- {{ number_format($overallScore, 1) }} 分({{ $overallGrade }})
- @else
- 待计算
- @endif
- </li>
- </ul>
- <div class="overall-meta">
- 规则:综合分 = 当前50% + 历史25% + 同群体25% + 难度校正,即:(({{ number_format($scoreRate !== null ? (float)$scoreRate * 100 : 0, 1) }}×70% + {{ number_format($averageMastery !== null ? (float)$averageMastery * 100 : 0, 1) }}×30%)×50%) + {{ number_format($historyPart, 1) }}×25% + {{ number_format($peerPart, 1) }}×25% + {{ number_format($adjustPart, 1) }} = {{ number_format($overallScore ?? $compositeFormulaResult, 1) }}
- </div>
- </div>
- </div>
- <div class="section">
- <div class="section-title">二、知识点掌握聚类视图</div>
- <div class="cluster-toolbar">
- <span class="cluster-legend"><i class="dot" style="background:#52c41a"></i>已掌握</span>
- <span class="cluster-legend"><i class="dot" style="background:#faad14"></i>薄弱</span>
- <span class="cluster-legend"><i class="dot" style="background:#f5222d"></i>未入门</span>
- <span class="cluster-legend"><i class="dot" style="background:#d9d9d9"></i>未学习</span>
- <span>按“模块 → 子模块 → 知识点”聚类展示</span>
- </div>
- <div class="cluster-grid">
- @foreach($clusterCards as $cluster)
- <div class="cluster-card">
- <div class="cluster-card-title">
- {{ $cluster['grand_name'] }}
- </div>
- @if(!empty($cluster['parent_groups']))
- @foreach($cluster['parent_groups'] as $parent)
- <div class="cluster-subgroup">
- <div class="cluster-subgroup-title">{{ $parent['parent_name'] }}</div>
- <div class="cluster-points">
- @foreach($parent['points'] as $point)
- <span class="cluster-point"
- style="background:{{ $point['color'] }}"
- title="{{ $point['name'] }} · {{ $point['status'] }}{{ $point['mastery_level'] !== null ? '(' . number_format((float)$point['mastery_level'] * 100, 1) . '%)' : '' }}{{ $point['path'] !== '' ? ' · ' . $point['path'] : '' }}"></span>
- @endforeach
- </div>
- </div>
- @endforeach
- @else
- <div class="cluster-empty">当前模块暂无可展示的子知识点。</div>
- @endif
- </div>
- @endforeach
- </div>
- <div style="margin-top:10px;">
- <div class="kp-stats-grid">
- <div class="kp-stat-item">
- <div class="kp-stat-label">总知识点数</div>
- <div class="kp-stat-value">{{ $kpStatsTotal['total'] }}</div>
- </div>
- <div class="kp-stat-item">
- <div class="kp-stat-label">已掌握</div>
- <div class="kp-stat-value" style="color:#52c41a;">
- {{ $kpStatsTotal['mastered'] }}<span class="kp-stat-rate" style="color:#52c41a;">({{ $kpPct($kpStatsTotal['mastered'], $kpStatsTotal['total']) }})</span>
- </div>
- </div>
- <div class="kp-stat-item">
- <div class="kp-stat-label">薄弱</div>
- <div class="kp-stat-value" style="color:#faad14;">
- {{ $kpStatsTotal['weak'] }}<span class="kp-stat-rate" style="color:#faad14;">({{ $kpPct($kpStatsTotal['weak'], $kpStatsTotal['total']) }})</span>
- </div>
- </div>
- <div class="kp-stat-item">
- <div class="kp-stat-label">未入门</div>
- <div class="kp-stat-value" style="color:#f5222d;">
- {{ $kpStatsTotal['beginner'] }}<span class="kp-stat-rate" style="color:#f5222d;">({{ $kpPct($kpStatsTotal['beginner'], $kpStatsTotal['total']) }})</span>
- </div>
- </div>
- <div class="kp-stat-item">
- <div class="kp-stat-label">未学习</div>
- <div class="kp-stat-value" style="color:#9ca3af;">
- {{ $kpStatsTotal['unlearned'] }}<span class="kp-stat-rate" style="color:#9ca3af;">({{ $kpPct($kpStatsTotal['unlearned'], $kpStatsTotal['total']) }})</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="section">
- <div class="section-title">三、模块现状与提分路径(全局+本学案影响)</div>
- <div class="kp-change-box">
- <div style="font-size:12px;font-weight:700;color:#0f172a;">本学案知识点变化情况</div>
- @if(!empty($kpChangeItems))
- <ul class="kp-change-list">
- @foreach($kpChangeItems as $item)
- @php
- $delta = (float) ($item['change'] ?? 0);
- $deltaText = ($delta >= 0 ? '+' : '') . number_format($delta * 100, 1) . '%';
- $deltaColor = $delta > 0 ? '#16a34a' : ($delta < 0 ? '#dc2626' : '#64748b');
- $masteryText = isset($item['mastery_level']) && $item['mastery_level'] !== null
- ? number_format((float) $item['mastery_level'] * 100, 1) . '%'
- : '--';
- @endphp
- <li>
- {{ $item['name'] ?? '-' }}:
- <span style="color:{{ $deltaColor }};font-weight:600;">{{ $deltaText }}</span>
- (掌握度{{ $masteryText }},{{ $item['status'] ?? '未学习' }})
- </li>
- @endforeach
- </ul>
- @else
- <div class="muted" style="margin-top:4px;">暂无可用的知识点变化数据</div>
- @endif
- </div>
- <div style="margin-bottom:8px; padding:8px 10px; border:1px solid #e5e7eb; border-radius:8px; background:#fff;">
- <div style="font-size:12px;color:#334155;">
- 本次学案影响模块:
- @if(!empty($impactedModules))
- @foreach($impactedModules as $idx => $im)
- @php $mName = $im['module_name'] ?? '-'; @endphp
- <span style="display:inline-block;padding:2px 8px;border-radius:999px;background:#eef2ff;color:#3730a3;margin-right:4px;">
- {{ $mName }}({{ $im['question_count'] ?? 0 }}题)
- </span>
- @endforeach
- @else
- <span class="muted">暂无命中模块</span>
- @endif
- </div>
- </div>
- <table class="module-table">
- <thead>
- <tr>
- <th style="width: 14%;">模块</th>
- <th style="width: 10%; white-space: nowrap;">本次影响</th>
- <th style="width: 18%;">掌握度<br>(学案影响)</th>
- <th style="width: 12%;">掌握状态</th>
- <th style="width: 9%;">题目数</th>
- <th style="width: 11%;">得分率</th>
- <th style="width: 11%;">路径建议</th>
- <th style="width: 25%;">关注知识点</th>
- </tr>
- </thead>
- <tbody>
- @forelse($moduleRowsWithStatus as $m)
- @php
- $status = (string) ($m['status'] ?? '暂无');
- $color = $statusColor($status);
- $rate = $m['exam_score_rate'] ?? null;
- $qCount = (int) ($m['question_count'] ?? 0);
- $isImpacted = $qCount > 0;
- $pathTag = $pathTagByModuleName[(string) ($m['module_name'] ?? '')] ?? '待观察';
- $pathColor = match ($pathTag) {
- '优先加强' => '#ef4444',
- '需要加强' => '#f59e0b',
- '保分不错' => '#16a34a',
- default => '#64748b',
- };
- $moduleCode = (string) ($m['module_code'] ?? '');
- $impactDelta = $moduleImpactChangeMap[$moduleCode] ?? null;
- $impactArrow = $impactDelta === null
- ? ''
- : ($impactDelta > 0.0005 ? '↑' : ($impactDelta < -0.0005 ? '↓' : '→'));
- $impactColor = $impactDelta === null
- ? '#64748b'
- : ($impactDelta > 0.0005 ? '#16a34a' : ($impactDelta < -0.0005 ? '#dc2626' : '#64748b'));
- $impactText = $impactDelta === null ? '' : number_format(abs($impactDelta) * 100, 1) . '%';
- $impactSuffix = $impactArrow === '→' ? '' : $impactText;
- $moduleName = (string) ($m['module_name'] ?? '');
- $focus = $moduleSuggestionByName[$moduleName] ?? null;
- $focusText = '-';
- if (is_array($focus)) {
- $focusName = (string) ($focus['kp_name'] ?? '');
- $focusTypes = !empty($focus['question_types']) ? implode('、', $focus['question_types']) : '';
- $focusMastery = isset($focus['mastery_level']) && $focus['mastery_level'] !== null
- ? number_format((float) $focus['mastery_level'] * 100, 1) . '%'
- : '--';
- $focusSuffix = $focusTypes !== '' ? (',' . $focusTypes) : '';
- $focusText = $focusName !== ''
- ? ($focusName . '(' . $focusMastery . $focusSuffix . ')')
- : '-';
- }
- @endphp
- <tr>
- <td><span class="module-name">{{ $m['module_name'] ?? '-' }}</span></td>
- <td>
- @if($isImpacted)
- <span class="impact-yes">是</span>
- @else
- <span class="muted">否</span>
- @endif
- </td>
- <td>
- {{ isset($m['mastery_level']) && $m['mastery_level'] !== null ? number_format((float) $m['mastery_level'] * 100, 1) . '%' : '-' }}
- @if($impactArrow !== '')
- <span style="margin-left:4px;color:{{ $impactColor }};font-weight:700;">
- {{ $impactArrow }}{{ $impactSuffix }}
- </span>
- @endif
- </td>
- <td><span class="badge" style="background:{{ $color }}">{{ $status }}</span></td>
- <td>{{ $m['question_count'] ?? 0 }}</td>
- <td>{{ $rate !== null ? number_format((float) $rate * 100, 1) . '%' : '-' }}</td>
- <td><span style="color:{{ $pathColor }}; font-weight:700;">{{ $pathTag }}</span></td>
- <td>{{ $focusText }}</td>
- </tr>
- @empty
- <tr>
- <td colspan="8" class="muted">暂无掌握状态数据</td>
- </tr>
- @endforelse
- </tbody>
- </table>
- </div>
- @if(!empty($wrongQuestions))
- <div class="section" style="page-break-inside:auto; break-inside:auto;">
- <div class="section-title">四、这次错题记录</div>
- @if(!empty($kpWrongStats))
- <div style="margin-bottom:8px; padding:8px; border:1px solid #e5e7eb; border-radius:6px; background:#f8fafc;">
- <div style="font-size:12px; font-weight:600; margin-bottom:6px;">知识点错误率</div>
- <div style="font-size:12px; color:#475569; line-height:1.7;">
- @foreach($kpWrongStats as $item)
- <span class="error-kp-tag {{ $item['rate'] > 0.5 ? 'high-risk' : '' }}">{{ $item['kp_name'] }}:{{ $item['wrong'] }}/{{ $item['total'] }}({{ number_format($item['rate'] * 100, 1) }}%)</span>
- @endforeach
- </div>
- </div>
- @endif
- @foreach($wrongQuestions as $q)
- @php
- $studentAnswer = $q['student_answer'] ?? null;
- $correctAnswer = $q['answer'] ?? $q['correct_answer'] ?? null;
- $isCorrect = $q['is_correct'] ?? null;
- if ($isCorrect === null && !empty($studentAnswer) && !empty($correctAnswer)) {
- $isCorrect = (trim($studentAnswer) === trim($correctAnswer)) ? 1 : 0;
- }
- $statusText = '';
- $statusColorValue = '';
- if ($isCorrect === 1) {
- $statusText = '正确';
- $statusColorValue = '#10b981';
- } elseif ($isCorrect === 0) {
- $statusText = '错误';
- $statusColorValue = '#ef4444';
- }
- $showStatus = $statusText !== '';
- $insight = $insightMap[$q['question_number']] ?? ($insightMap[$q['display_number'] ?? null] ?? []);
- $fullScore = $insight['full_score'] ?? ($q['score'] ?? null);
- if ($isCorrect === 1) {
- $score = $fullScore;
- } elseif ($isCorrect === 0) {
- $score = $q['score_obtained'] ?? 0;
- } else {
- $score = null;
- }
- $analysisRaw = $insight['analysis']
- ?? $insight['thinking_process']
- ?? $insight['feedback']
- ?? $insight['suggestions']
- ?? $insight['reason']
- ?? ($insight['correct_solution'] ?? null);
- if (empty($analysisRaw) && !empty($insight['next_steps'])) {
- $analysisRaw = '后续建议:' . (is_array($insight['next_steps']) ? implode(';', $insight['next_steps']) : $insight['next_steps']);
- }
- $analysis = is_array($analysisRaw) ? json_encode($analysisRaw, JSON_UNESCAPED_UNICODE) : $analysisRaw;
- if ($analysis === null || $analysis === '') {
- $analysis = '暂无解题思路,待补充';
- }
- if (is_string($analysis)) {
- $analysis = preg_replace('/^【?\s*解题思路\s*】?\s*[::]?\s*/u', '', $analysis);
- }
- $formatSolutionLikeGrading = function ($text) {
- if (!is_string($text) || trim($text) === '') {
- return $text;
- }
- $normalized = preg_replace('/\s*;\s*步骤\s*(\d+)/u', ";\n步骤$1", $text);
- $normalized = preg_replace('/\s*。\s*步骤\s*(\d+)/u', "。\n步骤$1", $normalized);
- $normalized = preg_replace('/(?<!^)(步骤\s*\d+\s*[::])/u', "\n$1", $normalized);
- $normalized = preg_replace('/(?<!^)(第\s*\d+\s*步\s*[::]?)/u', "\n$1", $normalized);
- $normalized = preg_replace('/\n{3,}/u', "\n\n", $normalized);
- $normalized = preg_replace('/^[\h\x{3000}]+/mu', '', $normalized);
- return trim($normalized);
- };
- $stepsRaw = $insight['steps'] ?? $insight['solution_steps'] ?? $insight['analysis_steps'] ?? null;
- $steps = [];
- if (is_array($stepsRaw)) {
- $steps = $stepsRaw;
- } elseif (is_string($stepsRaw) && trim($stepsRaw) !== '') {
- $steps = preg_split('/[\r\n]+/', trim($stepsRaw));
- }
- $typeMap = ['choice' => '选择题', 'fill' => '填空题', 'answer' => '解答题'];
- $typeLabel = $typeMap[$q['question_type'] ?? ''] ?? ($q['question_type'] ?? '题型未标注');
- $questionText = is_string($q['question_text']) ? $q['question_text'] : json_encode($q['question_text'], JSON_UNESCAPED_UNICODE);
- $solution = $q['solution'] ?? null;
- if (is_string($solution)) {
- $solution = preg_replace('/^【?\s*解题思路\s*】?\s*[::]?\s*/u', '', $solution);
- }
- $solution = $formatSolutionLikeGrading($solution);
- $analysis = $formatSolutionLikeGrading($analysis);
- $renderLikeGrading = function ($text) {
- if (is_array($text)) {
- $text = json_encode($text, JSON_UNESCAPED_UNICODE);
- }
- $text = is_string($text) ? trim($text) : '';
- if ($text === '') {
- return '';
- }
- // 兼容题库里常见的转义写法:\$x\$、\$\frac{...}\$
- $text = preg_replace('/\\\\\\$/u', '$', $text);
- return \App\Services\MathFormulaProcessor::processFormulas($text);
- };
- $questionTextRendered = $renderLikeGrading($questionText);
- $displayCorrectAnswer = is_array($correctAnswer) ? json_encode($correctAnswer, JSON_UNESCAPED_UNICODE) : (string) $correctAnswer;
- $questionTypeRaw = strtolower(trim((string) ($q['question_type'] ?? '')));
- $isChoiceQuestion = in_array($questionTypeRaw, ['choice', 'multiple_choice', 'single_choice', '选择题', 'select'], true);
- $normalizedOptions = [];
- $correctAnswerLetters = [];
- if ($isChoiceQuestion) {
- $rawOptions = $q['options'] ?? [];
- if (is_string($rawOptions)) {
- $decodedOptions = json_decode($rawOptions, true);
- $rawOptions = is_array($decodedOptions) ? $decodedOptions : [];
- }
- if (is_array($rawOptions)) {
- foreach ($rawOptions as $optKey => $optValue) {
- $letter = null;
- if (is_string($optKey) && preg_match('/([A-H])/i', $optKey, $m)) {
- $letter = strtoupper($m[1]);
- } elseif (is_array($optValue)) {
- $candidate = $optValue['label'] ?? $optValue['key'] ?? $optValue['option'] ?? null;
- if (is_string($candidate) && preg_match('/([A-H])/i', $candidate, $m)) {
- $letter = strtoupper($m[1]);
- }
- }
- if ($letter === null) {
- continue;
- }
- $content = is_array($optValue) ? ($optValue['content'] ?? $optValue['text'] ?? $optValue['value'] ?? '') : $optValue;
- if (!is_string($content)) {
- $content = json_encode($content, JSON_UNESCAPED_UNICODE);
- }
- $content = trim((string) $content);
- if ($content !== '') {
- $normalizedOptions[$letter] = $content;
- }
- }
- }
- if (trim((string) $correctAnswer) !== '') {
- preg_match_all('/[A-H]/i', strtoupper((string) $correctAnswer), $answerMatches);
- $correctAnswerLetters = array_values(array_unique($answerMatches[0] ?? []));
- }
- if (!empty($normalizedOptions) && !empty($correctAnswerLetters)) {
- $mappedAnswers = [];
- foreach ($correctAnswerLetters as $letter) {
- if (isset($normalizedOptions[$letter])) {
- $mappedAnswers[] = $letter . '. ' . $normalizedOptions[$letter];
- }
- }
- if (!empty($mappedAnswers)) {
- $displayCorrectAnswer = implode(';', $mappedAnswers);
- }
- }
- }
- $choiceOptionLetters = !empty($normalizedOptions) ? array_keys($normalizedOptions) : [];
- sort($choiceOptionLetters);
- $choiceLayoutClass = 'options-grid-1';
- $layoutDecider = app(\App\Support\OptionLayoutDecider::class);
- if (! empty($normalizedOptions) && ! empty($choiceOptionLetters)) {
- $optValuesForLayout = [];
- foreach ($choiceOptionLetters as $L) {
- $optValuesForLayout[] = $normalizedOptions[$L];
- }
- $layoutMeta = $layoutDecider->decide($optValuesForLayout, 'grading');
- $choiceLayoutClass = $layoutMeta['class'] ?? 'options-grid-1';
- }
- @endphp
- <div class="question-card">
- <div style="display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:4px;">
- <div style="display:flex; align-items:center; gap:8px; font-weight:600;">
- <span class="tag">题号 {{ $q['display_number'] ?? $q['question_number'] }} · {{ $typeLabel }}</span>
- @php
- $kpName = $q['knowledge_point_name'] ?? $q['knowledge_point'] ?? null;
- if (!empty($kpName) && $kpName !== '-' && $kpName !== '未标注') {
- echo '<span class="tag" style="background: #eef2ff; color:#4338ca;">' . e($kpName) . '</span>';
- }
- @endphp
- @if($showStatus)
- <span class="tag" style="background: {{ $statusColorValue }}; color:#fff;">{{ $statusText }}</span>
- @endif
- </div>
- @if($score !== null && $fullScore !== null)
- <div class="muted">得分 {{ $score }} / {{ $fullScore }}</div>
- @endif
- </div>
- <div class="question-stem math-content" style="margin-bottom:6px;">{!! $questionTextRendered !!}</div>
- @if(!empty($isChoiceQuestion) && !empty($normalizedOptions))
- <div class="report-options {{ $choiceLayoutClass }}">
- @foreach($choiceOptionLetters as $optLetter)
- @php
- $isCorrectOpt = in_array($optLetter, $correctAnswerLetters ?? [], true);
- $rawOpt = (string) ($normalizedOptions[$optLetter] ?? '');
- $normalizedOpt = str_replace('\\dfrac', '\\frac', $rawOpt);
- $normalizedOpt = str_replace('\\displaystyle', '', $normalizedOpt);
- $normalizedOpt = $layoutDecider->normalizeCompactMathForDisplay($normalizedOpt);
- $rawOptPlain = html_entity_decode(strip_tags($rawOpt), ENT_QUOTES | ENT_HTML5, 'UTF-8');
- $rawOptPlain = preg_replace('/\s+/u', '', $rawOptPlain ?? '');
- $isShortOption = mb_strlen((string) $rawOptPlain, 'UTF-8') <= 8;
- $valClass = $isShortOption ? 'option-short' : 'option-long';
- $renderedOpt = $renderLikeGrading($normalizedOpt);
- @endphp
- <div class="option option-compact">
- <strong>{{ $optLetter }}.</strong>
- <span class="option-value {{ $valClass }}">{!! $renderedOpt !!}</span>
- @if($isCorrectOpt)
- <span style="margin-left:4px; font-size:13px; color:#15803d; font-weight:700;">✅</span>
- @endif
- </div>
- @endforeach
- </div>
- @endif
- @if(!empty($correctAnswer) && (!$isChoiceQuestion || empty($normalizedOptions)))
- <div class="question-block" style="background:#f0fdf4; border-left:3px solid #10b981;">
- <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:3px;">正确答案</div>
- <div class="math-content" style="line-height:1.7; color:#374151;">
- {!! $renderLikeGrading($displayCorrectAnswer) !!}
- </div>
- </div>
- @endif
- @if(!empty($solution))
- <div class="report-answer-meta">
- <div class="answer-line">
- <strong>解题思路:</strong>
- <span class="solution-content">{!! $renderLikeGrading($solution) !!}</span>
- </div>
- </div>
- @elseif(!empty($analysis) && $analysis !== '暂无解题思路记录')
- <div class="report-answer-meta">
- <div class="answer-line">
- <strong>解题思路:</strong>
- <span class="solution-content">{!! $renderLikeGrading($analysis) !!}</span>
- </div>
- </div>
- @endif
- @if(!empty($steps))
- <div style="margin-top:6px; font-size:12px;">
- <div style="font-weight:600; margin-bottom:3px;">解题步骤</div>
- <ol style="margin:0; padding-left:18px;">
- @foreach($steps as $s)
- @php
- $stepText = is_array($s) ? json_encode($s, JSON_UNESCAPED_UNICODE) : (string) $s;
- @endphp
- <li style="margin-bottom:2px;">{!! nl2br($renderLikeGrading($stepText)) !!}</li>
- @endforeach
- </ol>
- </div>
- @endif
- </div>
- @endforeach
- </div>
- @endif
- </div>
- <script src="/js/katex.min.js"></script>
- <script src="/js/auto-render.min.js"></script>
- <script>
- document.addEventListener('DOMContentLoaded', function() {
- try {
- renderMathInElement(document.body, {
- delimiters: [
- {left: "$$", right: "$$", display: true},
- {left: "$", right: "$", display: false},
- {left: "\\(", right: "\\)", display: false},
- {left: "\\[", right: "\\]", display: true}
- ],
- throwOnError: false,
- strict: false,
- trust: true
- });
- } catch (e) {}
- });
- </script>
- </body>
- </html>
|