ocr-paper-analysis.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <x-filament-panels::page>
  2. <div class="space-y-6">
  3. <!-- 页面标题 -->
  4. <div class="flex items-center justify-between">
  5. <h1 class="text-2xl font-bold text-gray-900">试卷答题分析</h1>
  6. @if($this->ocrRecord && $this->paper)
  7. <div class="flex gap-3">
  8. <button
  9. wire:click="rematchQuestions"
  10. wire:loading.attr="disabled"
  11. class="btn btn-outline btn-info gap-2"
  12. >
  13. <x-filament::icon icon="heroicon-o-arrow-path" class="w-4 h-4" />
  14. 重新匹配
  15. </button>
  16. <button
  17. wire:click="submitForAiAnalysis"
  18. wire:loading.attr="disabled"
  19. class="btn btn-primary gap-2"
  20. >
  21. <x-filament::icon icon="heroicon-o-cpu-chip" class="w-4 h-4" />
  22. AI 分析
  23. </button>
  24. </div>
  25. @endif
  26. </div>
  27. @if($this->ocrRecord && $this->paper)
  28. <!-- 试卷信息 -->
  29. <x-filament::section>
  30. <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
  31. <div>
  32. <p class="text-sm text-gray-500">试卷名称</p>
  33. <p class="font-semibold">{{ $this->paperInfo()['paper_name'] }}</p>
  34. </div>
  35. <div>
  36. <p class="text-sm text-gray-500">学生信息</p>
  37. <p class="font-semibold">
  38. {{ $this->studentInfo()['name'] ?? '未知' }}
  39. ({{ $this->studentInfo()['grade'] ?? '' }}{{ $this->studentInfo()['class'] ?? '' }})
  40. </p>
  41. </div>
  42. <div>
  43. <p class="text-sm text-gray-500">试卷概况</p>
  44. <p class="font-semibold">
  45. {{ $this->paperInfo()['total_questions'] }}题
  46. / {{ $this->paperInfo()['total_score'] }}分
  47. </p>
  48. </div>
  49. </div>
  50. </x-filament::section>
  51. <!-- 匹配状态 -->
  52. <x-filament::section>
  53. <h3 class="text-lg font-semibold mb-4">题目匹配情况</h3>
  54. <div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
  55. <div class="flex items-center text-blue-800">
  56. <x-filament::icon icon="heroicon-o-puzzle-piece" class="mr-2" />
  57. <span class="font-medium">OCR识别与系统试卷匹配</span>
  58. </div>
  59. <div class="mt-2 text-sm text-blue-700">
  60. <p>系统试卷共 <span class="font-bold">{{ $this->paper->total_questions ?? count($matchedQuestions) }}</span> 道题</p>
  61. <p>当前匹配 <span class="font-bold">{{ count($matchedQuestions) }}</span> 道题</p>
  62. @php
  63. $matchedCount = collect($matchedQuestions)->whereNotNull('ocr_id')->count();
  64. $unmatchedCount = collect($matchedQuestions)->whereNull('ocr_id')->count();
  65. @endphp
  66. <p class="mt-1">
  67. <span class="text-green-700">{{ $matchedCount }} 道已识别</span> |
  68. <span class="text-orange-700">{{ $unmatchedCount }} 道未识别</span>
  69. </p>
  70. </div>
  71. </div>
  72. </x-filament::section>
  73. <!-- 试卷图片与标注 -->
  74. <x-filament::section>
  75. <h3 class="text-lg font-semibold mb-4">试卷原图与识别区域</h3>
  76. <div class="relative w-full overflow-x-auto">
  77. <div class="relative inline-block min-w-full">
  78. @if($this->ocrRecord->image_path)
  79. <img
  80. src="{{ Storage::url($this->ocrRecord->image_path) }}"
  81. alt="Exam Paper"
  82. class="max-w-full h-auto border rounded-lg"
  83. style="min-width: 800px;"
  84. >
  85. @foreach($matchedQuestions as $question)
  86. @if(isset($question['bbox']) && is_array($question['bbox']))
  87. @php
  88. $yMin = $question['bbox']['y_min'] ?? 0;
  89. $yMax = $question['bbox']['y_max'] ?? 0;
  90. $height = $yMax - $yMin;
  91. // Assuming width is full width for now, or we can use a fixed percentage if we don't have x-coordinates
  92. // Since we only have Y-range, we'll draw a full-width box
  93. @endphp
  94. <div
  95. class="absolute left-0 right-0 border-2 border-red-500 bg-transparent hover:bg-red-50 hover:bg-opacity-10 transition-all cursor-pointer group"
  96. style="top: {{ $yMin }}px; height: {{ $height }}px;"
  97. title="题目 {{ $question['question_number'] }}"
  98. >
  99. <span class="absolute top-0 left-0 bg-red-500 text-white text-xs px-1 rounded-br opacity-75 group-hover:opacity-100">
  100. Q{{ $question['question_number'] }}
  101. </span>
  102. </div>
  103. @endif
  104. @endforeach
  105. @else
  106. <div class="text-center py-8 bg-gray-50 rounded-lg">
  107. <p class="text-gray-500">图片未找到</p>
  108. </div>
  109. @endif
  110. </div>
  111. </div>
  112. </x-filament::section>
  113. <!-- 题目列表 -->
  114. @if(count($matchedQuestions) > 0)
  115. <x-filament::section>
  116. <h3 class="text-lg font-semibold mb-4">答题详情</h3>
  117. <div class="overflow-x-auto">
  118. <table class="min-w-full divide-y divide-gray-200">
  119. <thead class="bg-gray-50">
  120. <tr>
  121. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  122. 题号
  123. </th>
  124. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  125. 知识点
  126. </th>
  127. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  128. 学生答案
  129. </th>
  130. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  131. 正确答案
  132. </th>
  133. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  134. 得分
  135. </th>
  136. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  137. OCR状态
  138. </th>
  139. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  140. 评分状态
  141. </th>
  142. </tr>
  143. </thead>
  144. <tbody class="bg-white divide-y divide-gray-200">
  145. @foreach($matchedQuestions as $index => $question)
  146. <tr>
  147. <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
  148. {{ $index + 1 }}
  149. </td>
  150. <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
  151. {{ $question['knowledge_point'] }}
  152. </td>
  153. <td class="px-6 py-4 text-sm text-gray-500">
  154. <span class="{{ $question['student_answer'] ? 'text-gray-900' : 'text-gray-400 italic' }}">
  155. {{ $question['student_answer'] ?: '未作答' }}
  156. </span>
  157. </td>
  158. <td class="px-6 py-4 text-sm text-gray-900 font-medium">
  159. {{ $question['correct_answer'] }}
  160. </td>
  161. <td class="px-6 py-4 whitespace-nowrap text-sm">
  162. @if($question['score'] !== null)
  163. <span class="{{ $question['is_correct'] ? 'text-green-600' : 'text-red-600' }} font-semibold">
  164. {{ $question['score'] }}分
  165. </span>
  166. <span class="text-gray-500">/ {{ $question['full_score'] }}分</span>
  167. @else
  168. <span class="text-gray-400">未评分</span>
  169. @endif
  170. </td>
  171. <td class="px-6 py-4 whitespace-nowrap">
  172. @if($question['ocr_id'])
  173. <x-filament::badge color="success">
  174. <x-filament::icon icon="heroicon-o-camera" class="mr-1" />
  175. 已识别
  176. </x-filament::badge>
  177. @if(isset($question['ocr_confidence']))
  178. <span class="ml-1 text-xs text-gray-500">
  179. {{ round($question['ocr_confidence'] * 100, 1) }}%
  180. </span>
  181. @endif
  182. @else
  183. <x-filament::badge color="warning">
  184. <x-filament::icon icon="heroicon-o-eye-slash" class="mr-1" />
  185. 未识别
  186. </x-filament::badge>
  187. @endif
  188. </td>
  189. <td class="px-6 py-4 whitespace-nowrap">
  190. @if($question['is_correct'] !== null)
  191. @if($question['is_correct'])
  192. <x-filament::badge color="success">
  193. <x-filament::icon icon="heroicon-o-check" class="mr-1" />
  194. 正确
  195. </x-filament::badge>
  196. @else
  197. <x-filament::badge color="danger">
  198. <x-filament::icon icon="heroicon-o-x-mark" class="mr-1" />
  199. 错误
  200. </x-filament::badge>
  201. @endif
  202. @else
  203. <x-filament::badge color="gray">待分析</x-filament::badge>
  204. @endif
  205. </td>
  206. </tr>
  207. @endforeach
  208. </tbody>
  209. </table>
  210. </div>
  211. </x-filament::section>
  212. @endif
  213. <!-- 分析结果统计 -->
  214. @if($this->hasAnalysis())
  215. <x-filament::section>
  216. <h3 class="text-lg font-semibold mb-4">分析结果统计</h3>
  217. <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
  218. <div class="bg-blue-50 rounded-lg p-4">
  219. <p class="text-sm text-blue-600 font-medium">题目总数</p>
  220. <p class="text-2xl font-bold text-blue-900">{{ $this->getAnalysisStats()['total'] }}</p>
  221. </div>
  222. <div class="bg-green-50 rounded-lg p-4">
  223. <p class="text-sm text-green-600 font-medium">正确题数</p>
  224. <p class="text-2xl font-bold text-green-900">{{ $this->getAnalysisStats()['correct'] }}</p>
  225. </div>
  226. <div class="bg-purple-50 rounded-lg p-4">
  227. <p class="text-sm text-purple-600 font-medium">正确率</p>
  228. <p class="text-2xl font-bold text-purple-900">{{ $this->getAnalysisStats()['accuracy'] }}%</p>
  229. </div>
  230. <div class="bg-yellow-50 rounded-lg p-4">
  231. <p class="text-sm text-yellow-600 font-medium">得分率</p>
  232. <p class="text-2xl font-bold text-yellow-900">{{ $this->getAnalysisStats()['score_rate'] }}%</p>
  233. </div>
  234. </div>
  235. <div class="mt-4 flex justify-between items-center">
  236. <p class="text-sm text-gray-600">
  237. 总分:<span class="font-semibold">{{ $this->getAnalysisStats()['score'] }}</span> /
  238. <span class="font-semibold">{{ $this->getAnalysisStats()['full_score'] }}</span> 分
  239. </p>
  240. <x-filament::button
  241. wire:click="$dispatch('openModal', {
  242. component: 'app.filament.modals.analysis-report-modal',
  243. arguments: {
  244. recordId: '{{ $this->recordId }}',
  245. stats: @json($this->getAnalysisStats()),
  246. questions: @json($matchedQuestions)
  247. }
  248. })"
  249. >
  250. 生成详细报告
  251. </x-filament::button>
  252. </div>
  253. </x-filament::section>
  254. @endif
  255. @else
  256. <x-filament::section>
  257. <div class="text-center py-8">
  258. <x-filament::icon icon="heroicon-o-exclamation-triangle" class="mx-auto h-12 w-12 text-gray-400" />
  259. <h3 class="mt-2 text-sm font-medium text-gray-900">无法加载试卷信息</h3>
  260. <p class="mt-1 text-sm text-gray-500">
  261. 请确保OCR记录存在且已关联到系统生成的试卷
  262. </p>
  263. </div>
  264. </x-filament::section>
  265. @endif
  266. </div>
  267. </x-filament-panels::page>