pdf-report-v3.blade.php 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. @php
  2. $v3 = $v3 ?? [];
  3. $summary = $v3['summary'] ?? [];
  4. $radar = $v3['radar'] ?? [];
  5. $modules = $v3['modules'] ?? [];
  6. $paths = $v3['paths'] ?? ['keep' => [], 'boost' => [], 'key' => []];
  7. $rawPaperId = $paper['id'] ?? $paper['paper_id'] ?? 'unknown';
  8. preg_match('/paper_(\d{15})/', $rawPaperId, $matches);
  9. $reportCode = $matches[1] ?? preg_replace('/[^0-9]/', '', (string) $rawPaperId);
  10. $generateDateTime = now()->format('Y年m月d日 H:i:s');
  11. $scoreObtained = $summary['score_obtained'] ?? null;
  12. $scoreTotal = $summary['score_total'] ?? null;
  13. $scoreRate = $summary['score_rate'] ?? null;
  14. $averageMastery = $summary['average_mastery'] ?? null;
  15. $examHitKpSet = array_fill_keys(array_map('strval', $exam_hit_kp_codes ?? []), true);
  16. $difficultySummary = is_array($summary['difficulty'] ?? null) ? $summary['difficulty'] : [];
  17. $difficultyExplain = trim((string) ($difficultySummary['explain'] ?? ''));
  18. if ($difficultyExplain === '') {
  19. $difficultyExplain = '暂无足够数据评估难度匹配。';
  20. }
  21. $comparisonSummary = $summary['comparison'] ?? [];
  22. $overallLabelDetail = $summary['overall_label_detail'] ?? [];
  23. $historySummary = $comparisonSummary['history'] ?? [];
  24. $peerSummary = $comparisonSummary['peers'] ?? [];
  25. $overallScore = isset($overallLabelDetail['composite_score']) ? (float) $overallLabelDetail['composite_score'] : null;
  26. $overallGrade = (string) ($overallLabelDetail['grade'] ?? 'D');
  27. $currentPart = (float) ($overallLabelDetail['current_score'] ?? 0);
  28. $historyPart = (float) ($overallLabelDetail['history_score'] ?? 0);
  29. $peerPart = (float) ($overallLabelDetail['peer_score'] ?? 0);
  30. $adjustPart = (float) ($overallLabelDetail['difficulty_adjust'] ?? 0);
  31. $compositeFormulaResult = (0.50 * $currentPart) + (0.25 * $historyPart) + (0.25 * $peerPart) + $adjustPart;
  32. $overallBadge = function (string $grade): array {
  33. return match ($grade) {
  34. 'S' => ['bg' => '#f5f3ff', 'border' => '#6d28d9', 'text' => '#6d28d9', 'class' => 'badge-s'],
  35. 'A' => ['bg' => '#ecfdf3', 'border' => '#22c55e', 'text' => '#166534', 'class' => 'badge-excellent'],
  36. 'B' => ['bg' => '#eff6ff', 'border' => '#3b82f6', 'text' => '#1d4ed8', 'class' => 'badge-good'],
  37. 'C' => ['bg' => '#fff7ed', 'border' => '#f59e0b', 'text' => '#b45309', 'class' => 'badge-average'],
  38. default => ['bg' => '#fef2f2', 'border' => '#ef4444', 'text' => '#b91c1c', 'class' => 'badge-weak'],
  39. };
  40. };
  41. $overallVisual = $overallBadge((string) $overallGrade);
  42. $trendVisual = function (string $trend): array {
  43. return match ($trend) {
  44. '显著提升' => ['icon' => '▲', 'color' => '#16a34a'],
  45. '小幅提升' => ['icon' => '↗', 'color' => '#0ea5e9'],
  46. '基本持平' => ['icon' => '•', 'color' => '#64748b'],
  47. '小幅回落' => ['icon' => '↘', 'color' => '#f59e0b'],
  48. '明显回落' => ['icon' => '▼', 'color' => '#ef4444'],
  49. default => ['icon' => '•', 'color' => '#64748b'],
  50. };
  51. };
  52. $statusColor = function (string $status): string {
  53. return match ($status) {
  54. '已掌握' => '#16a34a',
  55. '薄弱' => '#f59e0b',
  56. '未入门' => '#ef4444',
  57. default => '#64748b',
  58. };
  59. };
  60. $analysisWrongMap = [];
  61. foreach (($analysis_data['question_analysis'] ?? []) as $qa) {
  62. $qid = $qa['question_bank_id'] ?? $qa['question_id'] ?? null;
  63. if ($qid === null || $qid === '') {
  64. continue;
  65. }
  66. $rawCorrect = $qa['is_correct'] ?? null;
  67. $isWrongFromAnalysis = false;
  68. if (is_array($rawCorrect)) {
  69. $isWrongFromAnalysis = in_array(0, $rawCorrect, true);
  70. } elseif ($rawCorrect !== null) {
  71. $isWrongFromAnalysis = !boolval($rawCorrect);
  72. }
  73. if ($isWrongFromAnalysis) {
  74. $analysisWrongMap[(string) $qid] = true;
  75. }
  76. }
  77. $wrongQuestions = [];
  78. foreach (($questions ?? []) as $qItem) {
  79. $isCorrectProbe = $qItem['is_correct'] ?? null;
  80. $studentAnswerProbe = $qItem['student_answer'] ?? null;
  81. $correctAnswerProbe = $qItem['answer'] ?? ($qItem['correct_answer'] ?? null);
  82. if ($isCorrectProbe === null && !empty($studentAnswerProbe) && !empty($correctAnswerProbe)) {
  83. $isCorrectProbe = (trim((string) $studentAnswerProbe) === trim((string) $correctAnswerProbe)) ? 1 : 0;
  84. }
  85. $normalizedCorrect = $isCorrectProbe;
  86. if ($isCorrectProbe !== null) {
  87. $normalizedCorrect = is_bool($isCorrectProbe) ? ($isCorrectProbe ? 1 : 0) : intval($isCorrectProbe);
  88. }
  89. $qidProbe = (string) ($qItem['question_bank_id'] ?? $qItem['question_id'] ?? '');
  90. $isWrongByAnalysis = ($qidProbe !== '' && isset($analysisWrongMap[$qidProbe]));
  91. if ($normalizedCorrect === 0 || $isWrongByAnalysis) {
  92. $wrongQuestions[] = $qItem;
  93. }
  94. }
  95. $kpStats = [];
  96. foreach (($questions ?? []) as $qItem) {
  97. $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
  98. $kpName = $kpName === '' ? '未标注知识点' : $kpName;
  99. if (!isset($kpStats[$kpName])) {
  100. $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
  101. }
  102. $kpStats[$kpName]['total']++;
  103. }
  104. foreach ($wrongQuestions as $qItem) {
  105. $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
  106. $kpName = $kpName === '' ? '未标注知识点' : $kpName;
  107. if (!isset($kpStats[$kpName])) {
  108. $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
  109. }
  110. $kpStats[$kpName]['wrong']++;
  111. }
  112. $kpWrongStats = [];
  113. foreach ($kpStats as $kpName => $stat) {
  114. if (($stat['wrong'] ?? 0) <= 0) {
  115. continue;
  116. }
  117. $total = max(1, intval($stat['total'] ?? 0));
  118. $wrong = intval($stat['wrong'] ?? 0);
  119. $kpWrongStats[] = [
  120. 'kp_name' => $kpName,
  121. 'wrong' => $wrong,
  122. 'total' => $total,
  123. 'rate' => $wrong / $total,
  124. ];
  125. }
  126. usort($kpWrongStats, function ($a, $b) {
  127. if ($a['rate'] === $b['rate']) {
  128. return $b['wrong'] <=> $a['wrong'];
  129. }
  130. return $b['rate'] <=> $a['rate'];
  131. });
  132. $pcMasteryPercent = function ($mastery): ?int {
  133. if ($mastery === null) {
  134. return null;
  135. }
  136. // 与 PC 保持一致:API 先保留 2 位小数,前端再 Math.round 到 0-100。
  137. return (int) round(round((float) $mastery, 2) * 100);
  138. };
  139. $formatMasteryPct = function ($mastery) use ($pcMasteryPercent): string {
  140. $percent = $pcMasteryPercent($mastery);
  141. return $percent === null ? '-' : ($percent . '%');
  142. };
  143. $childMasteryStatus = function ($mastery) use ($pcMasteryPercent): string {
  144. $m = $pcMasteryPercent($mastery);
  145. if ($m === null) {
  146. return '未学习';
  147. }
  148. if ($m >= 85) {
  149. return '已掌握';
  150. }
  151. if ($m >= 60) {
  152. return '薄弱';
  153. }
  154. return '未入门';
  155. };
  156. $childStatusColor = function ($status): string {
  157. return match ($status) {
  158. '已掌握' => '#52c41a',
  159. '薄弱' => '#faad14',
  160. '未入门' => '#f5222d',
  161. default => '#d9d9d9',
  162. };
  163. };
  164. $calcStats = function (array $points): array {
  165. $total = count($points);
  166. $learned = 0;
  167. $mastered = 0;
  168. $weak = 0;
  169. $beginner = 0;
  170. $unlearned = 0;
  171. $hit = 0;
  172. foreach ($points as $p) {
  173. if (($p['mastery_level'] ?? null) !== null) {
  174. $learned++;
  175. }
  176. if (! empty($p['is_hit'])) {
  177. $hit++;
  178. }
  179. $status = (string) ($p['status'] ?? '未学习');
  180. if ($status === '已掌握') {
  181. $mastered++;
  182. } elseif ($status === '薄弱') {
  183. $weak++;
  184. } elseif ($status === '未入门') {
  185. $beginner++;
  186. } else {
  187. $unlearned++;
  188. }
  189. }
  190. return [
  191. 'total' => $total,
  192. 'learned' => $learned,
  193. 'mastered' => $mastered,
  194. 'weak' => $weak,
  195. 'beginner' => $beginner,
  196. 'unlearned' => $unlearned,
  197. 'hit' => $hit,
  198. ];
  199. };
  200. $clusterCards = [];
  201. $allStagePoints = [];
  202. foreach ($radar as $moduleItem) {
  203. $children = is_array($moduleItem['children'] ?? null) ? $moduleItem['children'] : [];
  204. $greatMap = [];
  205. foreach ($children as $child) {
  206. $greatKey = trim((string) ($child['great_grand_parent_name'] ?? ''));
  207. $greatKey = $greatKey !== '' ? $greatKey : '未分组';
  208. $grandKey = trim((string) ($child['grand_parent_name'] ?? ''));
  209. $grandKey = $grandKey !== '' ? $grandKey : '未分组';
  210. $parentName = trim((string) ($child['parent_name'] ?? ''));
  211. if ($parentName === '') {
  212. $parentCode = trim((string) ($child['parent_code'] ?? ''));
  213. $parentName = $parentCode !== '' ? $parentCode : '未分组';
  214. }
  215. $childMasteryLevel = isset($child['mastery_level']) ? (float) $child['mastery_level'] : null;
  216. $status = $childMasteryStatus($childMasteryLevel);
  217. if (!isset($greatMap[$greatKey])) {
  218. $greatMap[$greatKey] = [];
  219. }
  220. if (!isset($greatMap[$greatKey][$grandKey])) {
  221. $greatMap[$greatKey][$grandKey] = [];
  222. }
  223. if (!isset($greatMap[$greatKey][$grandKey][$parentName])) {
  224. $greatMap[$greatKey][$grandKey][$parentName] = [];
  225. }
  226. $childCode = (string) ($child['code'] ?? '');
  227. $childParentCode = (string) ($child['parent_code'] ?? '');
  228. $isHit = !empty($child['is_hit'])
  229. || ($childCode !== '' && isset($examHitKpSet[$childCode]))
  230. || ($childParentCode !== '' && isset($examHitKpSet[$childParentCode]));
  231. $greatMap[$greatKey][$grandKey][$parentName][] = [
  232. 'code' => $childCode,
  233. 'name' => (string) ($child['name'] ?? '未命名知识点'),
  234. 'parent_code' => $childParentCode,
  235. 'path' => (string) ($child['path'] ?? ''),
  236. 'mastery_level' => $childMasteryLevel,
  237. 'change' => isset($child['change']) ? (float) $child['change'] : null,
  238. 'status' => $status,
  239. 'color' => $childStatusColor($status),
  240. 'is_hit' => $isHit,
  241. ];
  242. $allStagePoints[] = [
  243. 'code' => $childCode,
  244. 'name' => (string) ($child['name'] ?? '未命名知识点'),
  245. 'parent_code' => $childParentCode,
  246. 'mastery_level' => $childMasteryLevel,
  247. 'status' => $status,
  248. 'change' => isset($child['change']) ? (float) $child['change'] : null,
  249. 'is_hit' => $isHit,
  250. ];
  251. }
  252. $greatGroups = [];
  253. foreach ($greatMap as $greatName => $grandMap) {
  254. $grandGroups = [];
  255. foreach ($grandMap as $grandName => $parentMap) {
  256. $parentGroups = [];
  257. foreach ($parentMap as $parentName => $points) {
  258. usort($points, function ($a, $b) {
  259. $am = $a['mastery_level'] ?? -1;
  260. $bm = $b['mastery_level'] ?? -1;
  261. if ($am === $bm) {
  262. return strcmp((string) ($a['name'] ?? ''), (string) ($b['name'] ?? ''));
  263. }
  264. return $bm <=> $am;
  265. });
  266. $parentGroups[] = [
  267. 'parent_name' => $parentName,
  268. 'points' => $points,
  269. 'stats' => $calcStats($points),
  270. ];
  271. }
  272. // 子模块级过滤:整行没有任何掌握度数字则不显示
  273. $parentGroups = array_values(array_filter($parentGroups, function ($pg) {
  274. return (($pg['stats']['learned'] ?? 0) > 0) || (($pg['stats']['hit'] ?? 0) > 0);
  275. }));
  276. if (empty($parentGroups)) {
  277. continue;
  278. }
  279. usort($parentGroups, function ($a, $b) {
  280. $sa = $a['stats'];
  281. $sb = $b['stats'];
  282. return ($sb['learned'] <=> $sa['learned']) ?: ($sb['total'] <=> $sa['total']);
  283. });
  284. $allGrandPoints = [];
  285. foreach ($parentGroups as $pg) {
  286. $allGrandPoints = array_merge($allGrandPoints, $pg['points']);
  287. }
  288. $grandGroups[] = [
  289. 'grand_name' => $grandName,
  290. 'parent_groups' => $parentGroups,
  291. 'stats' => $calcStats($allGrandPoints),
  292. ];
  293. }
  294. // 大块级过滤:整块没有任何掌握度数字则不显示
  295. $grandGroups = array_values(array_filter($grandGroups, function ($gg) {
  296. return (($gg['stats']['learned'] ?? 0) > 0) || (($gg['stats']['hit'] ?? 0) > 0);
  297. }));
  298. if (empty($grandGroups)) {
  299. continue;
  300. }
  301. usort($grandGroups, function ($a, $b) {
  302. $sa = $a['stats'];
  303. $sb = $b['stats'];
  304. return ($sb['learned'] <=> $sa['learned']) ?: ($sb['total'] <=> $sa['total']);
  305. });
  306. $allGreatPoints = [];
  307. foreach ($grandGroups as $gg) {
  308. foreach ($gg['parent_groups'] as $pg) {
  309. $allGreatPoints = array_merge($allGreatPoints, $pg['points']);
  310. }
  311. }
  312. $greatGroups[] = [
  313. 'great_name' => $greatName,
  314. 'grand_groups' => $grandGroups,
  315. 'stats' => $calcStats($allGreatPoints),
  316. ];
  317. }
  318. usort($greatGroups, function ($a, $b) {
  319. $sa = $a['stats'];
  320. $sb = $b['stats'];
  321. return ($sb['learned'] <=> $sa['learned']) ?: ($sb['total'] <=> $sa['total']);
  322. });
  323. // 严格参考 math.client-pc:扁平化为“grand 层卡片”(展示大块)
  324. foreach ($greatGroups as $great) {
  325. foreach (($great['grand_groups'] ?? []) as $grand) {
  326. $gStats = $grand['stats'] ?? ['learned' => 0, 'total' => 0];
  327. $clusterCards[] = [
  328. 'module_name' => (string) ($moduleItem['name'] ?? '未分组'),
  329. 'great_name' => $great['great_name'] ?? '未分组',
  330. 'grand_name' => $grand['grand_name'] ?? '未分组',
  331. 'parent_groups' => $grand['parent_groups'] ?? [],
  332. 'stats' => $gStats,
  333. ];
  334. }
  335. }
  336. }
  337. usort($clusterCards, function ($a, $b) {
  338. $sa = $a['stats'] ?? ['learned' => 0, 'total' => 0];
  339. $sb = $b['stats'] ?? ['learned' => 0, 'total' => 0];
  340. return (($sb['learned'] ?? 0) <=> ($sa['learned'] ?? 0))
  341. ?: (($sb['total'] ?? 0) <=> ($sa['total'] ?? 0));
  342. });
  343. $kpStatsTotal = [
  344. 'total' => count($allStagePoints),
  345. 'mastered' => 0,
  346. 'weak' => 0,
  347. 'beginner' => 0,
  348. 'unlearned' => 0,
  349. ];
  350. foreach ($allStagePoints as $p) {
  351. $st = (string) ($p['status'] ?? '未学习');
  352. if ($st === '已掌握') {
  353. $kpStatsTotal['mastered']++;
  354. } elseif ($st === '薄弱') {
  355. $kpStatsTotal['weak']++;
  356. } elseif ($st === '未入门') {
  357. $kpStatsTotal['beginner']++;
  358. } else {
  359. $kpStatsTotal['unlearned']++;
  360. }
  361. }
  362. $moduleRowsWithStatus = array_values(array_filter($modules, function ($m) {
  363. $status = trim((string) ($m['status'] ?? ''));
  364. $masteryLevel = $m['mastery_level'] ?? null;
  365. $questionCount = (int) ($m['question_count'] ?? 0);
  366. if ($masteryLevel !== null) {
  367. return true;
  368. }
  369. return $questionCount > 0 && $status !== '' && ! in_array($status, ['暂无', '-', '未涉及', '未学习'], true);
  370. }));
  371. $pathTagByModuleName = [];
  372. foreach (['keep' => '保分不错', 'boost' => '需要加强', 'key' => '优先加强'] as $bucket => $tagName) {
  373. foreach (($paths[$bucket] ?? []) as $item) {
  374. $n = trim((string) ($item['name'] ?? ''));
  375. if ($n === '') {
  376. continue;
  377. }
  378. $pathTagByModuleName[$n] = $tagName;
  379. }
  380. }
  381. $globalPathTagByMastery = function ($mastery) use ($pcMasteryPercent): string {
  382. if ($mastery === null || ! is_numeric($mastery)) {
  383. return '待观察';
  384. }
  385. $m = $pcMasteryPercent($mastery);
  386. if ($m >= 85) {
  387. return '保分不错';
  388. }
  389. if ($m >= 60) {
  390. return '需要加强';
  391. }
  392. return '优先加强';
  393. };
  394. $overallPathTag = function (string $tag): string {
  395. return match ($tag) {
  396. '优先加强' => '整体优先',
  397. '需要加强' => '整体加强',
  398. '保分不错' => '整体巩固',
  399. default => $tag,
  400. };
  401. };
  402. $impactedModules = array_values(array_filter($moduleRowsWithStatus, function ($m) {
  403. return ((int) ($m['question_count'] ?? 0)) > 0;
  404. }));
  405. $radarModuleMap = [];
  406. foreach ($radar as $moduleItem) {
  407. $code = (string) ($moduleItem['code'] ?? '');
  408. if ($code !== '') {
  409. $radarModuleMap[$code] = $moduleItem;
  410. }
  411. }
  412. $moduleKpSuggestions = [];
  413. foreach ($moduleRowsWithStatus as $m) {
  414. $moduleCode = (string) ($m['module_code'] ?? '');
  415. $moduleName = (string) ($m['module_name'] ?? '-');
  416. $moduleChildren = $radarModuleMap[$moduleCode]['children'] ?? [];
  417. if (! is_array($moduleChildren) || empty($moduleChildren)) {
  418. continue;
  419. }
  420. $moduleHitCandidates = [];
  421. foreach (($mastery['items'] ?? []) as $item) {
  422. $hitCode = trim((string) ($item['kp_code'] ?? $item['code'] ?? ''));
  423. if ($hitCode === '') {
  424. continue;
  425. }
  426. if (! empty($examHitKpSet) && ! isset($examHitKpSet[$hitCode])) {
  427. continue;
  428. }
  429. $hitLevel = $item['mastery_level'] ?? null;
  430. if ($hitLevel === null || ! is_numeric($hitLevel)) {
  431. continue;
  432. }
  433. $matchedChild = null;
  434. foreach ($moduleChildren as $child) {
  435. $childCode = trim((string) ($child['code'] ?? ''));
  436. $parentCode = trim((string) ($child['parent_code'] ?? ''));
  437. if ($childCode === $hitCode || $parentCode === $hitCode) {
  438. $matchedChild = $child;
  439. break;
  440. }
  441. }
  442. if (! is_array($matchedChild)) {
  443. continue;
  444. }
  445. $moduleHitCandidates[$hitCode] = [
  446. 'code' => $hitCode,
  447. 'name' => (string) ($item['kp_name'] ?? $item['name'] ?? ($matchedChild['parent_name'] ?? $matchedChild['name'] ?? $hitCode)),
  448. 'parent_code' => (string) ($matchedChild['parent_code'] ?? ''),
  449. 'parent_name' => (string) ($matchedChild['parent_name'] ?? ''),
  450. 'grand_parent_name' => (string) ($matchedChild['grand_parent_name'] ?? ''),
  451. 'mastery_level' => (float) $hitLevel,
  452. 'is_hit' => true,
  453. ];
  454. }
  455. $startedByCode = $moduleHitCandidates;
  456. foreach (array_values(array_filter($moduleChildren, function ($c) {
  457. return isset($c['mastery_level']) && $c['mastery_level'] !== null;
  458. })) as $child) {
  459. $childCode = trim((string) ($child['code'] ?? ''));
  460. if ($childCode !== '' && ! isset($startedByCode[$childCode])) {
  461. $startedByCode[$childCode] = $child;
  462. }
  463. }
  464. $started = array_values($startedByCode);
  465. usort($started, function ($a, $b) {
  466. $am = (float) ($a['mastery_level'] ?? 0);
  467. $bm = (float) ($b['mastery_level'] ?? 0);
  468. if ($am === $bm) {
  469. $ah = !empty($a['is_hit']) ? 0 : 1;
  470. $bh = !empty($b['is_hit']) ? 0 : 1;
  471. if ($ah !== $bh) {
  472. return $ah <=> $bh;
  473. }
  474. return strcmp((string) ($a['name'] ?? ''), (string) ($b['name'] ?? ''));
  475. }
  476. return $am <=> $bm;
  477. });
  478. $weakest = null;
  479. if (! empty($started)) {
  480. $lowestStarted = $started[0];
  481. $lowestStartedLevel = isset($lowestStarted['mastery_level']) ? (float) $lowestStarted['mastery_level'] : null;
  482. if ($lowestStartedLevel !== null && ($pcMasteryPercent($lowestStartedLevel) ?? 0) < 85) {
  483. // 规则1:已开始学习中掌握度最低
  484. $weakest = $lowestStarted;
  485. } else {
  486. // 规则2:若已开始学习均达标(>=85%),取“最近的未学习”
  487. $unlearned = array_values(array_filter($moduleChildren, function ($c) {
  488. return !isset($c['mastery_level']) || $c['mastery_level'] === null;
  489. }));
  490. if (! empty($unlearned)) {
  491. $anchorParent = (string) ($lowestStarted['parent_name'] ?? '');
  492. $anchorGrand = (string) ($lowestStarted['grand_parent_name'] ?? '');
  493. usort($unlearned, function ($a, $b) use ($anchorParent, $anchorGrand) {
  494. $score = function ($node) use ($anchorParent, $anchorGrand) {
  495. $parent = (string) ($node['parent_name'] ?? '');
  496. $grand = (string) ($node['grand_parent_name'] ?? '');
  497. if ($anchorParent !== '' && $parent === $anchorParent) {
  498. return 0;
  499. }
  500. if ($anchorGrand !== '' && $grand === $anchorGrand) {
  501. return 1;
  502. }
  503. return 2;
  504. };
  505. $sa = $score($a);
  506. $sb = $score($b);
  507. if ($sa === $sb) {
  508. return strcmp((string) ($a['name'] ?? ''), (string) ($b['name'] ?? ''));
  509. }
  510. return $sa <=> $sb;
  511. });
  512. $weakest = $unlearned[0];
  513. }
  514. }
  515. } else {
  516. // 没有已开始学习数据时,回退到模块内任一未学习点
  517. $unlearned = array_values(array_filter($moduleChildren, function ($c) {
  518. return !isset($c['mastery_level']) || $c['mastery_level'] === null;
  519. }));
  520. if (! empty($unlearned)) {
  521. usort($unlearned, fn ($a, $b) => strcmp((string) ($a['name'] ?? ''), (string) ($b['name'] ?? '')));
  522. $weakest = $unlearned[0];
  523. }
  524. }
  525. if (! is_array($weakest)) {
  526. $moduleKpSuggestions[] = [
  527. 'module_name' => $moduleName,
  528. 'path_tag' => $pathTagByModuleName[$moduleName] ?? '待观察',
  529. 'kp_name' => '',
  530. 'kp_code' => '',
  531. 'mastery_level' => null,
  532. 'status' => '当前模块暂无需额外关注知识点',
  533. 'is_empty' => true,
  534. ];
  535. continue;
  536. }
  537. $kpName = (string) ($weakest['name'] ?? '');
  538. if ($kpName === '') {
  539. continue;
  540. }
  541. $kpCode = (string) ($weakest['code'] ?? '');
  542. $moduleKpSuggestions[] = [
  543. 'module_name' => $moduleName,
  544. 'path_tag' => $pathTagByModuleName[$moduleName] ?? '待观察',
  545. 'kp_name' => $kpName,
  546. 'kp_code' => $kpCode,
  547. 'mastery_level' => $weakest['mastery_level'] ?? null,
  548. 'status' => $childMasteryStatus($weakest['mastery_level'] ?? null),
  549. 'is_empty' => false,
  550. ];
  551. }
  552. $moduleSuggestionByName = [];
  553. foreach ($moduleKpSuggestions as $sug) {
  554. $name = trim((string) ($sug['module_name'] ?? ''));
  555. if ($name !== '') {
  556. $moduleSuggestionByName[$name] = $sug;
  557. }
  558. }
  559. $focusMarkerByCode = [];
  560. foreach ($moduleKpSuggestions as $sug) {
  561. if (! empty($sug['is_empty'])) {
  562. continue;
  563. }
  564. $code = trim((string) ($sug['kp_code'] ?? ''));
  565. $name = trim((string) ($sug['kp_name'] ?? ''));
  566. if ($code === '' || $name === '') {
  567. continue;
  568. }
  569. $focusMarkerByCode[$code] = [
  570. 'name' => $name,
  571. 'module_name' => (string) ($sug['module_name'] ?? ''),
  572. 'mastery_level' => $sug['mastery_level'] ?? null,
  573. ];
  574. }
  575. $renderedFocusMarkerCodes = [];
  576. $kpChangeItems = [];
  577. foreach (($mastery['items'] ?? []) as $item) {
  578. $code = trim((string) ($item['kp_code'] ?? $item['code'] ?? ''));
  579. if ($code !== '' && ! empty($examHitKpSet) && ! isset($examHitKpSet[$code])) {
  580. continue;
  581. }
  582. $level = $item['mastery_level'] ?? null;
  583. if ($level === null || ! is_numeric($level)) {
  584. continue;
  585. }
  586. $change = $item['mastery_change'] ?? $item['change'] ?? 0.0;
  587. $kpChangeItems[] = [
  588. 'code' => $code,
  589. 'name' => (string) ($item['kp_name'] ?? $item['name'] ?? ($code !== '' ? $code : '-')),
  590. 'mastery_level' => (float) $level,
  591. 'change' => is_numeric($change) ? (float) $change : 0.0,
  592. 'status' => $childMasteryStatus((float) $level),
  593. 'is_hit' => true,
  594. ];
  595. }
  596. usort($kpChangeItems, function ($a, $b) {
  597. return abs((float) ($b['change'] ?? 0)) <=> abs((float) ($a['change'] ?? 0));
  598. });
  599. $kpPct = function (int $count, int $total): string {
  600. if ($total <= 0) {
  601. return '0.0%';
  602. }
  603. return number_format(($count * 100.0) / $total, 1) . '%';
  604. };
  605. $changeText = function ($change): string {
  606. if ($change === null || ! is_numeric($change)) {
  607. return '';
  608. }
  609. $delta = (float) $change;
  610. $points = number_format(abs($delta) * 100, 1);
  611. if ($delta > 0.0005) {
  612. return '较上次提升' . $points . '个百分点';
  613. }
  614. if ($delta < -0.0005) {
  615. return '较上次下降' . $points . '个百分点';
  616. }
  617. return '较上次基本持平';
  618. };
  619. @endphp
  620. <!DOCTYPE html>
  621. <html lang="zh-CN">
  622. <head>
  623. <meta charset="UTF-8">
  624. <title>学情分析报告</title>
  625. <link rel="stylesheet" href="/css/katex/katex.min.css">
  626. <style>
  627. @page {
  628. size: A4;
  629. margin: 2.2cm 2cm 2.3cm 2cm;
  630. @top-left { content: "知了数学·{{ $generateDateTime }}"; font-size: 13px; color: #666; }
  631. @top-center { content: "{{ $student['name'] ?? '-' }}"; font-size: 13px; color: #666; }
  632. @top-right {
  633. content: "{{ $reportCode }}";
  634. font-size: 19px;
  635. font-weight: 600;
  636. font-family: "Noto Sans", "Liberation Sans", "Nimbus Sans", sans-serif;
  637. color: #222;
  638. }
  639. @bottom-left { content: "{{ $reportCode }}"; font-size: 11px; color: #666; }
  640. @bottom-right { content: counter(page) "/" counter(pages); font-size: 13px; color: #666; }
  641. }
  642. * { box-sizing: border-box; }
  643. body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; margin: 0; color: #0f172a; font-size: 13px; line-height: 1.65; }
  644. .page { page-break-after: auto; }
  645. .header { text-align: left; margin-bottom: 16px; }
  646. .paper-title { font-size: 30px; font-weight: 700; margin-bottom: 8px; color: #0b3a75; letter-spacing: 1px; }
  647. .section { margin-bottom: 14px; page-break-inside: auto; break-inside: auto; }
  648. .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; }
  649. .card { border: 1px solid #dbeafe; border-radius: 12px; padding: 14px; background: #f8fbff; position: relative; }
  650. .summary-list { margin: 0; padding-left: 18px; }
  651. .summary-list li { margin: 6px 0; font-size: 13px; }
  652. .overall-badge {
  653. position: absolute;
  654. right: 14px;
  655. top: 12px;
  656. border-radius: 12px;
  657. border: 0;
  658. padding: 9px 16px;
  659. min-width: 0;
  660. width: auto;
  661. text-align: center;
  662. position: absolute;
  663. overflow: hidden;
  664. display: inline-block;
  665. white-space: nowrap;
  666. background: transparent !important;
  667. }
  668. .overall-badge .level { font-size: 28px; font-weight: 800; line-height: 1.05; letter-spacing: 1px; }
  669. .overall-badge .score { font-size: 13px; margin-top: 3px; }
  670. .overall-badge.badge-s {
  671. border: 5px solid #6d28d9;
  672. border-radius: 14px;
  673. box-shadow: none;
  674. transform: rotate(-7deg);
  675. }
  676. .overall-badge.badge-s::before {
  677. content: "";
  678. position: absolute;
  679. inset: 4px;
  680. border: 2px dashed rgba(109, 40, 217, 0.65);
  681. border-radius: 10px;
  682. pointer-events: none;
  683. }
  684. .overall-badge.badge-s .level {
  685. letter-spacing: 2px;
  686. text-shadow: 0 1px 0 rgba(109, 40, 217, 0.24);
  687. }
  688. .overall-badge.badge-excellent {
  689. border: 3px double #16a34a;
  690. border-radius: 999px;
  691. box-shadow: none;
  692. }
  693. .overall-badge.badge-good {
  694. border: 2px solid #2563eb;
  695. border-radius: 10px;
  696. clip-path: polygon(6% 0, 94% 0, 100% 50%, 94% 100%, 6% 100%, 0 50%);
  697. box-shadow: none;
  698. }
  699. .overall-badge.badge-average {
  700. border: 2px dashed #d97706;
  701. border-radius: 14px;
  702. box-shadow: none;
  703. }
  704. .overall-badge.badge-weak {
  705. border-left: 3px solid #ef4444;
  706. border-right: 0;
  707. border-top: 0;
  708. border-bottom: 2px solid #ef4444;
  709. border-radius: 0 10px 10px 0;
  710. box-shadow: none;
  711. }
  712. .overall-meta { margin-top: 8px; font-size: 9px; color: #64748b; line-height: 1.6; white-space: nowrap; }
  713. .dot {
  714. display: inline-block;
  715. width: 10px;
  716. height: 10px;
  717. border-radius: 2px;
  718. margin-right: 4px;
  719. vertical-align: middle;
  720. border: 1px solid #374151;
  721. background: #fff;
  722. }
  723. .dot-mastered {
  724. background: #111827;
  725. border-style: solid;
  726. }
  727. .dot-weak {
  728. background: #9ca3af;
  729. border-style: solid;
  730. }
  731. .dot-beginner {
  732. background: #e5e7eb;
  733. border: 1px dashed #6b7280;
  734. }
  735. .dot-unlearned {
  736. background: #ffffff;
  737. border-style: solid;
  738. border-color: #9ca3af;
  739. }
  740. .cluster-toolbar {
  741. margin-bottom: 8px;
  742. font-size: 11px;
  743. color: #475569;
  744. white-space: nowrap;
  745. }
  746. .cluster-legend { display: inline-block; margin-right: 12px; }
  747. .cluster-grid {
  748. display: grid;
  749. grid-template-columns: 1fr 1fr;
  750. gap: 10px;
  751. }
  752. .cluster-card {
  753. border: 1px solid #e2e8f0;
  754. border-radius: 10px;
  755. padding: 10px;
  756. background: #fff;
  757. position: relative;
  758. overflow: visible;
  759. }
  760. .cluster-card-title {
  761. font-size: 14px;
  762. font-weight: 700;
  763. color: #0f172a;
  764. margin-bottom: 8px;
  765. }
  766. .cluster-subgroup {
  767. border-left: 2px solid #e5e7eb;
  768. padding-left: 8px;
  769. padding-right: 128px; /* 右侧空白区域再缩小 */
  770. margin-bottom: 8px;
  771. position: relative;
  772. }
  773. .cluster-subgroup:last-child { margin-bottom: 0; }
  774. .cluster-subgroup-title {
  775. font-size: 12px;
  776. font-weight: 600;
  777. color: #334155;
  778. margin-bottom: 4px;
  779. }
  780. .cluster-points {
  781. display: flex;
  782. flex-wrap: wrap;
  783. gap: 4px;
  784. }
  785. .cluster-point {
  786. width: 10px;
  787. height: 10px;
  788. border-radius: 2px;
  789. display: inline-block;
  790. border: 1px solid rgba(148, 163, 184, 0.35);
  791. position: relative;
  792. }
  793. .cluster-point.status-mastered {
  794. background: #111827;
  795. border: 1px solid #1f2937;
  796. }
  797. .cluster-point.status-weak {
  798. background: #9ca3af;
  799. border: 1px solid #1f2937;
  800. }
  801. .cluster-point.status-beginner {
  802. background: #e5e7eb !important;
  803. border: 1px dashed #6b7280;
  804. }
  805. .cluster-point.status-unlearned {
  806. background: #ffffff !important;
  807. border: 1px solid #9ca3af;
  808. }
  809. .cluster-point.focus-source {
  810. border-color: rgba(148, 163, 184, 0.35);
  811. box-shadow: 0 0 0 2px #fde68a, 0 0 0 4px rgba(251, 191, 36, 0.18);
  812. margin-right: 4px;
  813. margin-bottom: 4px;
  814. z-index: 2;
  815. overflow: visible;
  816. }
  817. .cluster-focus-connector {
  818. position: absolute;
  819. left: 0;
  820. top: -12px;
  821. width: 112px;
  822. height: 46px;
  823. overflow: visible;
  824. pointer-events: none;
  825. z-index: 2;
  826. }
  827. .cluster-focus-connector path {
  828. fill: none;
  829. stroke: #0f172a;
  830. stroke-width: 1;
  831. stroke-linecap: round;
  832. }
  833. .cluster-focus-connector.dense {
  834. width: 128px;
  835. height: 46px;
  836. }
  837. .cluster-focus-connector.bottom {
  838. width: 118px;
  839. height: 46px;
  840. }
  841. .cluster-point-focus-label {
  842. position: absolute;
  843. left: 102px; /* 放到右侧空白区,并远离最右侧方块 */
  844. top: 50%; /* 与点位在同一水平带,避免压住文字 */
  845. transform: translateY(-50%);
  846. display: inline-block;
  847. max-width: none;
  848. border: 1px solid #0f172a;
  849. border-radius: 6px;
  850. background: #fffbeb;
  851. color: #92400e;
  852. font-size: 9px;
  853. font-weight: 700;
  854. padding: 1px 6px;
  855. line-height: 1.25;
  856. white-space: nowrap;
  857. z-index: 3;
  858. overflow: visible;
  859. }
  860. .cluster-point-focus-label.focus-offset-a { top: 50%; left: 102px; transform: translateY(-50%); }
  861. .cluster-point-focus-label.focus-offset-b { top: 42%; left: 102px; transform: translateY(-50%); }
  862. .cluster-point-focus-label.focus-offset-c { top: 58%; left: 102px; transform: translateY(-50%); }
  863. .cluster-point-focus-label.dense { left: 116px; top: 50%; transform: translateY(-50%); }
  864. .cluster-point-focus-label.bottom { left: 108px; top: 44%; transform: translateY(-50%); }
  865. .cluster-empty {
  866. font-size: 12px;
  867. color: #64748b;
  868. background: #f8fafc;
  869. border: 1px dashed #cbd5e1;
  870. border-radius: 8px;
  871. padding: 10px;
  872. }
  873. .kp-stats-grid {
  874. display: grid;
  875. grid-template-columns: repeat(5, 1fr);
  876. border: 1px solid #e5e7eb;
  877. border-radius: 10px;
  878. overflow: hidden;
  879. margin-bottom: 10px;
  880. }
  881. .kp-stat-item {
  882. padding: 8px 10px;
  883. border-right: 1px solid #e5e7eb;
  884. background: #fff;
  885. }
  886. .kp-stat-item:last-child { border-right: none; }
  887. .kp-stat-label { font-size: 11px; color: #64748b; }
  888. .kp-stat-value { font-size: 18px; font-weight: 700; color: #111827; line-height: 1.2; margin-top: 2px; }
  889. .kp-stat-rate { font-size: 11px; margin-left: 4px; font-weight: 600; }
  890. .kp-change-box { margin-bottom: 10px; border: 1px solid #e5e7eb; border-radius: 10px; background: #f8fafc; padding: 10px 12px; }
  891. .kp-change-list { margin: 4px 0 0 16px; padding: 0; }
  892. .kp-change-list li { margin: 2px 0; color: #334155; }
  893. .kp-burst-card { margin-top: 10px; border: 1px solid #dbeafe; border-radius: 12px; padding: 10px; background: #fff; }
  894. .kp-burst-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; color: #0b3a75; }
  895. .kp-burst-meta { font-size: 12px; color: #334155; margin-top: 6px; line-height: 1.6; }
  896. .kp-burst-list { margin-top: 6px; font-size: 11px; color: #334155; line-height: 1.5; }
  897. .kp-burst-list span { display: inline-block; margin-right: 10px; margin-bottom: 3px; }
  898. table { width: 100%; border-collapse: collapse; font-size: 12px; background: #fff; }
  899. th, td { border: 1px solid #d0d7e2; padding: 8px 10px; text-align: left; vertical-align: top; }
  900. th { background: #f1f5f9; color: #1e293b; font-weight: 700; }
  901. .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; color: #fff; font-size: 11px; font-weight: 600; }
  902. .module-table th { background: #edf2ff; color: #0f172a; }
  903. .module-table th { text-align: center; }
  904. .module-table td { line-height: 1.45; }
  905. .module-table th,
  906. .module-table td { vertical-align: middle; }
  907. .module-table th:nth-child(6) { vertical-align: middle; }
  908. .module-table td:nth-child(6) { vertical-align: middle; text-align: center; }
  909. .module-table th:nth-child(1),
  910. .module-table td:nth-child(1) { text-align: center; }
  911. .module-table td:nth-child(2),
  912. .module-table td:nth-child(3),
  913. .module-table td:nth-child(4),
  914. .module-table td:nth-child(5) { text-align: center; white-space: nowrap; }
  915. .module-table td:nth-child(6) { font-size: 11px; color: #334155; }
  916. .module-table tbody tr:nth-child(even) td { background: #fcfdff; }
  917. .module-name { font-weight: 600; color: #0f172a; }
  918. .impact-yes { color:#2563eb; font-weight:600; }
  919. .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; color: #334155; background: #e5e7eb; }
  920. .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; }
  921. .error-kp-tag.high-risk { color: #b91c1c; border-color: #fca5a5; background: #fff; font-weight: 600; }
  922. .muted { color: #6b7280; font-size: 12px; }
  923. </style>
  924. </head>
  925. <body>
  926. <div class="page">
  927. <div class="header">
  928. <h1 class="paper-title">学情分析报告</h1>
  929. </div>
  930. <div class="section">
  931. <div class="section-title">一、总体评估</div>
  932. <div class="card">
  933. <div class="overall-badge {{ $overallVisual['class'] ?? '' }}"
  934. style="border-color:{{ $overallVisual['border'] }}; color:{{ $overallVisual['text'] }};">
  935. <div class="level">{{ $overallGrade }}</div>
  936. </div>
  937. <ul class="summary-list">
  938. <li>本次诊断得分:
  939. @if($scoreObtained !== null && $scoreTotal !== null && $scoreTotal > 0)
  940. {{ rtrim(rtrim(number_format((float) $scoreObtained, 1), '0'), '.') }}/{{ rtrim(rtrim(number_format((float) $scoreTotal, 1), '0'), '.') }}
  941. @else
  942. 暂无得分数据
  943. @endif
  944. </li>
  945. <li>平均掌握度:{{ $averageMastery !== null ? number_format((float) $averageMastery * 100, 1) . '%' : '暂无掌握度' }}</li>
  946. <li>
  947. 难度匹配:
  948. @if(!empty($difficultySummary['target_label']) && isset($difficultySummary['actual_average_difficulty']))
  949. 目标 {{ $difficultySummary['target_label'] }}
  950. @if(!empty($difficultySummary['target_range']))
  951. ({{ number_format((float)($difficultySummary['target_range']['min'] ?? 0), 2) }}~{{ number_format((float)($difficultySummary['target_range']['max'] ?? 0), 2) }})
  952. @endif
  953. ,实际 {{ number_format((float)($difficultySummary['actual_average_difficulty'] ?? 0), 3) }}
  954. ({{ $difficultySummary['status'] ?? '暂无' }})
  955. @else
  956. 暂无难度匹配数据
  957. @endif
  958. </li>
  959. <li>难度说明:{{ $difficultyExplain }}</li>
  960. <li>
  961. 与历史自己对比:
  962. @if(!empty($historySummary['is_first_exam']))
  963. {{ $historySummary['message'] ?? '这是你的第一次分析报告,先积累样本再看趋势。' }}
  964. @elseif(!empty($historySummary['low_baseline_guard']))
  965. {{ $historySummary['message'] ?? '历史基线偏低,建议看连续趋势。' }}
  966. @elseif(!empty($historySummary['has_data']))
  967. @php
  968. $trendText = (string)($historySummary['trend'] ?? '—');
  969. $tVisual = $trendVisual($trendText);
  970. @endphp
  971. 近几次均值对比:
  972. {{ number_format((float)($historySummary['baseline_score_rate'] ?? 0) * 100, 1) }}%,
  973. 本次{{ ($historySummary['delta_score_rate'] ?? 0) >= 0 ? '提升' : '回落' }}
  974. {{ number_format(abs((float)($historySummary['delta_score_rate'] ?? 0)) * 100, 1) }}%
  975. (<span style="color:{{ $tVisual['color'] ?? '#64748b' }}; font-weight:600;">{{ $tVisual['icon'] ?? '•' }} {{ $trendText }}</span>)
  976. @else
  977. {{ $historySummary['message'] ?? '历史样本不足' }}
  978. @endif
  979. </li>
  980. @if(!empty($peerSummary['show_line']))
  981. <li>
  982. 与同群体对比:
  983. {{ $peerSummary['message'] ?? '' }}
  984. (<span style="color:{{ $peerSummary['band_color'] ?? '#64748b' }}; font-weight:600;">{{ $peerSummary['band_icon'] ?? '•' }} {{ $peerSummary['band'] ?? '—' }}</span>)
  985. </li>
  986. @endif
  987. <li>
  988. 整体水平:
  989. @if($overallScore !== null)
  990. {{ number_format($overallScore, 1) }} 分({{ $overallGrade }})
  991. @else
  992. 待计算
  993. @endif
  994. </li>
  995. </ul>
  996. <div class="overall-meta">
  997. 规则:综合分 = 当前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) }}
  998. </div>
  999. </div>
  1000. </div>
  1001. <div class="section">
  1002. <div class="section-title">二、知识点掌握聚类视图</div>
  1003. <div class="cluster-toolbar">
  1004. <span class="cluster-legend"><i class="dot dot-mastered"></i>已掌握(深色实心)</span>
  1005. <span class="cluster-legend"><i class="dot dot-weak"></i>薄弱(浅灰实心)</span>
  1006. <span class="cluster-legend"><i class="dot dot-beginner"></i>未入门(浅灰虚线框)</span>
  1007. <span class="cluster-legend"><i class="dot dot-unlearned"></i>未学习(白色)</span>
  1008. <span>按“模块 → 子模块 → 知识点”聚类展示</span>
  1009. </div>
  1010. <div class="cluster-grid">
  1011. @foreach($clusterCards as $cluster)
  1012. <div class="cluster-card">
  1013. @php
  1014. $clusterModuleName = trim((string) ($cluster['module_name'] ?? '未分组'));
  1015. $clusterGrandName = trim((string) ($cluster['grand_name'] ?? ''));
  1016. $clusterTitle = ($clusterGrandName !== '' && $clusterGrandName !== $clusterModuleName)
  1017. ? ($clusterModuleName . ' / ' . $clusterGrandName)
  1018. : $clusterModuleName;
  1019. @endphp
  1020. <div class="cluster-card-title">
  1021. {{ $clusterTitle }}
  1022. </div>
  1023. @if(!empty($cluster['parent_groups']))
  1024. @foreach($cluster['parent_groups'] as $parent)
  1025. <div class="cluster-subgroup">
  1026. <div class="cluster-subgroup-title">{{ $parent['parent_name'] }}</div>
  1027. <div class="cluster-points">
  1028. @foreach($parent['points'] as $point)
  1029. @php
  1030. $pointCode = trim((string) ($point['code'] ?? ''));
  1031. $pointParentCode = trim((string) ($point['parent_code'] ?? ''));
  1032. $focusMarker = null;
  1033. $focusMarkerCode = '';
  1034. if ($pointCode !== '' && isset($focusMarkerByCode[$pointCode]) && empty($renderedFocusMarkerCodes[$pointCode])) {
  1035. $focusMarker = $focusMarkerByCode[$pointCode];
  1036. $focusMarkerCode = $pointCode;
  1037. } elseif ($pointParentCode !== '' && isset($focusMarkerByCode[$pointParentCode]) && empty($renderedFocusMarkerCodes[$pointParentCode])) {
  1038. $focusMarker = $focusMarkerByCode[$pointParentCode];
  1039. $focusMarkerCode = $pointParentCode;
  1040. }
  1041. if ($focusMarkerCode !== '') {
  1042. $renderedFocusMarkerCodes[$focusMarkerCode] = true;
  1043. }
  1044. $focusName = is_array($focusMarker) ? (string) ($focusMarker['name'] ?? '') : '';
  1045. $pointStatusClass = match ((string) ($point['status'] ?? '')) {
  1046. '已掌握' => 'status-mastered',
  1047. '薄弱' => 'status-weak',
  1048. '未入门' => 'status-beginner',
  1049. default => 'status-unlearned',
  1050. };
  1051. $focusLayoutClass = '';
  1052. if ($focusName === '幂与指数') {
  1053. $focusLayoutClass = 'dense';
  1054. } elseif (str_contains($clusterModuleName, '图形变化') || str_contains($clusterModuleName, '图形度量')) {
  1055. $focusLayoutClass = 'bottom';
  1056. }
  1057. @endphp
  1058. <span class="cluster-point {{ $pointStatusClass }}{{ $focusName !== '' ? ' focus-source' : '' }}"
  1059. title="{{ $point['name'] }} · {{ $point['status'] }}{{ $point['mastery_level'] !== null ? '(' . $formatMasteryPct($point['mastery_level']) . ')' : '' }}{{ $point['path'] !== '' ? ' · ' . $point['path'] : '' }}">
  1060. @if($focusName !== '')
  1061. @php
  1062. $focusOffsetClass = match ($loop->index % 3) {
  1063. 1 => 'focus-offset-b',
  1064. 2 => 'focus-offset-c',
  1065. default => 'focus-offset-a',
  1066. };
  1067. @endphp
  1068. <svg class="cluster-focus-connector {{ $focusLayoutClass }}" viewBox="0 0 150 64" preserveAspectRatio="none" aria-hidden="true">
  1069. @if($focusLayoutClass === 'dense')
  1070. <path d="M8,24 C18,24 24,18 38,16 C84,14 124,20 138,23 L146,24" />
  1071. @elseif($focusLayoutClass === 'bottom')
  1072. <path d="M8,23 C18,23 24,16 42,13 C86,11 114,20 132,23 L140,23" />
  1073. @else
  1074. <path d="M8,24 C18,24 24,18 42,15 C86,13 114,21 132,24 L142,24" />
  1075. @endif
  1076. </svg>
  1077. <span class="cluster-point-focus-label {{ $focusOffsetClass }} {{ $focusLayoutClass }}">{{ $focusName }}</span>
  1078. @endif
  1079. </span>
  1080. @endforeach
  1081. </div>
  1082. </div>
  1083. @endforeach
  1084. @else
  1085. <div class="cluster-empty">当前模块暂无可展示的子知识点。</div>
  1086. @endif
  1087. </div>
  1088. @endforeach
  1089. </div>
  1090. <div style="margin-top:10px;">
  1091. <div class="kp-stats-grid">
  1092. <div class="kp-stat-item">
  1093. <div class="kp-stat-label">总知识点数</div>
  1094. <div class="kp-stat-value">{{ $kpStatsTotal['total'] }}</div>
  1095. </div>
  1096. <div class="kp-stat-item">
  1097. <div class="kp-stat-label">已掌握</div>
  1098. <div class="kp-stat-value" style="color:#52c41a;">
  1099. {{ $kpStatsTotal['mastered'] }}<span class="kp-stat-rate" style="color:#52c41a;">({{ $kpPct($kpStatsTotal['mastered'], $kpStatsTotal['total']) }})</span>
  1100. </div>
  1101. </div>
  1102. <div class="kp-stat-item">
  1103. <div class="kp-stat-label">薄弱</div>
  1104. <div class="kp-stat-value" style="color:#faad14;">
  1105. {{ $kpStatsTotal['weak'] }}<span class="kp-stat-rate" style="color:#faad14;">({{ $kpPct($kpStatsTotal['weak'], $kpStatsTotal['total']) }})</span>
  1106. </div>
  1107. </div>
  1108. <div class="kp-stat-item">
  1109. <div class="kp-stat-label">未入门</div>
  1110. <div class="kp-stat-value" style="color:#f5222d;">
  1111. {{ $kpStatsTotal['beginner'] }}<span class="kp-stat-rate" style="color:#f5222d;">({{ $kpPct($kpStatsTotal['beginner'], $kpStatsTotal['total']) }})</span>
  1112. </div>
  1113. </div>
  1114. <div class="kp-stat-item">
  1115. <div class="kp-stat-label">未学习</div>
  1116. <div class="kp-stat-value" style="color:#9ca3af;">
  1117. {{ $kpStatsTotal['unlearned'] }}<span class="kp-stat-rate" style="color:#9ca3af;">({{ $kpPct($kpStatsTotal['unlearned'], $kpStatsTotal['total']) }})</span>
  1118. </div>
  1119. </div>
  1120. </div>
  1121. </div>
  1122. </div>
  1123. <div class="section">
  1124. <div class="section-title">三、模块现状与提分路径(全局+本学案影响)</div>
  1125. <div class="kp-change-box">
  1126. <div style="font-size:12px;font-weight:700;color:#0f172a;">本学案知识点变化情况</div>
  1127. @if(!empty($kpChangeItems))
  1128. <ul class="kp-change-list">
  1129. @foreach($kpChangeItems as $item)
  1130. @php
  1131. $delta = (float) ($item['change'] ?? 0);
  1132. $deltaColor = $delta > 0 ? '#16a34a' : ($delta < 0 ? '#dc2626' : '#64748b');
  1133. $deltaText = $changeText($delta);
  1134. $masteryText = isset($item['mastery_level']) && $item['mastery_level'] !== null
  1135. ? $formatMasteryPct($item['mastery_level'])
  1136. : '--';
  1137. @endphp
  1138. <li>
  1139. {{ $item['name'] ?? '-' }}:
  1140. 当前掌握度{{ $masteryText }}({{ $item['status'] ?? '未学习' }})
  1141. @if($deltaText !== '')
  1142. ,<span style="color:{{ $deltaColor }};font-weight:600;">{{ $deltaText }}</span>
  1143. @endif
  1144. </li>
  1145. @endforeach
  1146. </ul>
  1147. @else
  1148. <div class="muted" style="margin-top:4px;">
  1149. @if(!empty($kpWrongStats))
  1150. 暂无本学案命中知识点的掌握度数据,以下方知识点错误率作为本学案影响依据。
  1151. @else
  1152. 暂无可用的知识点变化数据
  1153. @endif
  1154. </div>
  1155. @endif
  1156. </div>
  1157. @if(!empty($kpWrongStats))
  1158. <div style="margin-bottom:8px; padding:8px 10px; border:1px solid #e5e7eb; border-radius:8px; background:#fff7ed;">
  1159. <div style="font-size:12px; font-weight:700; color:#9a3412; margin-bottom:6px;">知识点错误率</div>
  1160. <div style="font-size:12px; color:#475569; line-height:1.7;">
  1161. @foreach($kpWrongStats as $item)
  1162. <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>
  1163. @endforeach
  1164. </div>
  1165. </div>
  1166. @endif
  1167. <div style="margin-bottom:8px; padding:8px 10px; border:1px solid #e5e7eb; border-radius:8px; background:#fff;">
  1168. <div style="font-size:12px;color:#334155;">
  1169. 本次学案影响模块:
  1170. @if(!empty($impactedModules))
  1171. @foreach($impactedModules as $idx => $im)
  1172. @php
  1173. $mName = $im['module_name'] ?? '-';
  1174. $mQuestionCount = (int) ($im['question_count'] ?? 0);
  1175. $mScore = $im['exam_obtained_score'] ?? null;
  1176. @endphp
  1177. <span style="display:inline-block;padding:2px 8px;border-radius:999px;background:#eef2ff;color:#3730a3;margin-right:4px;">
  1178. {{ $mName }}({{ $mQuestionCount }}题,得分{{ $mScore !== null ? number_format((float) $mScore, 1) : '-' }})
  1179. </span>
  1180. @endforeach
  1181. @else
  1182. <span class="muted">暂无命中模块</span>
  1183. @endif
  1184. </div>
  1185. </div>
  1186. <table class="module-table">
  1187. <thead>
  1188. <tr>
  1189. <th style="width: 18%;">模块</th>
  1190. <th style="width: 12%; white-space: nowrap;">本次影响</th>
  1191. <th style="width: 18%;">当前掌握度</th>
  1192. <th style="width: 14%;">掌握状态</th>
  1193. <th style="width: 14%;">路径建议</th>
  1194. <th style="width: 24%;">关注知识点</th>
  1195. </tr>
  1196. </thead>
  1197. <tbody>
  1198. @forelse($moduleRowsWithStatus as $m)
  1199. @php
  1200. $status = (string) ($m['status'] ?? '暂无');
  1201. $color = $statusColor($status);
  1202. $qCount = (int) ($m['question_count'] ?? 0);
  1203. $isImpacted = $qCount > 0;
  1204. $basePathTag = $pathTagByModuleName[(string) ($m['module_name'] ?? '')]
  1205. ?? $globalPathTagByMastery($m['mastery_level'] ?? null);
  1206. $pathTag = $isImpacted ? $basePathTag : $overallPathTag($basePathTag);
  1207. $pathColor = match ($pathTag) {
  1208. '优先加强', '整体优先' => '#ef4444',
  1209. '需要加强', '整体加强' => '#f59e0b',
  1210. '保分不错', '整体巩固' => '#16a34a',
  1211. default => '#64748b',
  1212. };
  1213. $moduleName = (string) ($m['module_name'] ?? '');
  1214. $focus = $moduleSuggestionByName[$moduleName] ?? null;
  1215. $focusText = '-';
  1216. if (is_array($focus)) {
  1217. if (!empty($focus['is_empty'])) {
  1218. $focusText = (string) ($focus['status'] ?? '当前模块暂无需额外关注知识点');
  1219. } else {
  1220. $focusName = (string) ($focus['kp_name'] ?? '');
  1221. $focusMastery = isset($focus['mastery_level']) && $focus['mastery_level'] !== null
  1222. ? $formatMasteryPct($focus['mastery_level'])
  1223. : '--';
  1224. $focusText = $focusName !== ''
  1225. ? ($focusName . '(' . $focusMastery . ')')
  1226. : '当前模块暂无需额外关注知识点';
  1227. }
  1228. }
  1229. @endphp
  1230. <tr>
  1231. <td><span class="module-name">{{ $m['module_name'] ?? '-' }}</span></td>
  1232. <td>
  1233. @if($isImpacted)
  1234. <span class="impact-yes">是</span>
  1235. @else
  1236. <span class="muted">否</span>
  1237. @endif
  1238. </td>
  1239. <td>{{ isset($m['mastery_level']) && $m['mastery_level'] !== null ? $formatMasteryPct($m['mastery_level']) : '-' }}</td>
  1240. <td><span class="badge" style="background:{{ $color }}">{{ $status }}</span></td>
  1241. <td><span style="color:{{ $pathColor }}; font-weight:700;">{{ $pathTag }}</span></td>
  1242. <td>{{ $focusText }}</td>
  1243. </tr>
  1244. @empty
  1245. <tr>
  1246. <td colspan="6" class="muted">暂无掌握状态数据</td>
  1247. </tr>
  1248. @endforelse
  1249. </tbody>
  1250. </table>
  1251. </div>
  1252. </div>
  1253. <script src="/js/katex.min.js"></script>
  1254. <script src="/js/auto-render.min.js"></script>
  1255. <script>
  1256. document.addEventListener('DOMContentLoaded', function() {
  1257. try {
  1258. renderMathInElement(document.body, {
  1259. delimiters: [
  1260. {left: "$$", right: "$$", display: true},
  1261. {left: "$", right: "$", display: false},
  1262. {left: "\\(", right: "\\)", display: false},
  1263. {left: "\\[", right: "\\]", display: true}
  1264. ],
  1265. throwOnError: false,
  1266. strict: false,
  1267. trust: true
  1268. });
  1269. } catch (e) {}
  1270. });
  1271. </script>
  1272. </body>
  1273. </html>