| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- class OCRRecord extends Model
- {
- use HasFactory;
- protected $table = 'ocr_records';
- protected $fillable = [
- 'exam_id',
- 'student_id',
- 'image_path',
- 'image_filename',
- 'image_size',
- 'image_width',
- 'image_height',
- 'qr_code_data',
- 'paper_type',
- 'status',
- 'error_message',
- 'total_questions',
- 'processed_questions',
- 'confidence_avg',
- 'processed_at',
- 'ai_analyzed_at',
- 'ai_analysis_count',
- ];
- protected $dates = [
- 'processed_at',
- 'ai_analyzed_at',
- 'created_at',
- 'updated_at',
- ];
- protected $casts = [
- 'qr_code_data' => 'array',
- 'image_size' => 'integer',
- 'image_width' => 'integer',
- 'image_height' => 'integer',
- 'total_questions' => 'integer',
- 'processed_questions' => 'integer',
- 'confidence_avg' => 'float',
- 'processed_at' => 'datetime',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- public function questions(): HasMany
- {
- return $this->hasMany(OCRQuestionResult::class, 'ocr_record_id', 'id');
- }
- public function student()
- {
- return $this->belongsTo(Student::class, 'student_id', 'student_id');
- }
- public function getStatusBadgeAttribute(): string
- {
- return match ($this->status) {
- 'pending' => '<span class="px-2 py-1 text-xs rounded bg-gray-100 text-gray-800">待处理</span>',
- 'processing' => '<span class="px-2 py-1 text-xs rounded bg-blue-100 text-blue-800">处理中</span>',
- 'completed' => '<span class="px-2 py-1 text-xs rounded bg-green-100 text-green-800">已完成</span>',
- 'failed' => '<span class="px-2 py-1 text-xs rounded bg-red-100 text-red-800">失败</span>',
- default => '<span class="px-2 py-1 text-xs rounded bg-gray-100 text-gray-800">未知</span>',
- };
- }
- public function getImageUrlAttribute(): string
- {
- if ($this->image_path && file_exists(public_path($this->image_path))) {
- return asset($this->image_path);
- }
- return '';
- }
- public function getProgressPercentageAttribute(): int
- {
- if ($this->total_questions === 0) {
- return 0;
- }
- return intval(($this->processed_questions / $this->total_questions) * 100);
- }
- public function getPaperTypeLabelAttribute(): string
- {
- return match($this->paper_type) {
- 'unit_test' => '单元测试',
- 'midterm' => '期中考试',
- 'final' => '期末考试',
- 'homework' => '家庭作业',
- 'quiz' => '随堂测验',
- 'other' => '其他',
- default => '未分类',
- };
- }
- }
|