| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace App\DTO;
- /**
- * 学情分析数据传输对象
- * 封装学情分析所需的所有数据
- */
- class ExamAnalysisDataDto
- {
- public function __construct(
- public readonly array $paper,
- public readonly array $student,
- public readonly array $questions,
- public readonly array $mastery,
- public readonly array $insights,
- public readonly array $recommendations,
- public readonly ?string $analysisId = null
- ) {}
- /**
- * 从数组创建DTO
- */
- public static function fromArray(array $data): self
- {
- return new self(
- paper: $data['paper'] ?? [],
- student: $data['student'] ?? [],
- questions: $data['questions'] ?? [],
- mastery: $data['mastery'] ?? [],
- insights: $data['insights'] ?? [],
- recommendations: $data['recommendations'] ?? [],
- analysisId: $data['analysis_id'] ?? $data['analysisId'] ?? null,
- );
- }
- /**
- * 转换为数组
- */
- public function toArray(): array
- {
- return [
- 'paper' => $this->paper,
- 'student' => $this->student,
- 'questions' => $this->questions,
- 'mastery' => $this->mastery,
- 'insights' => $this->insights,
- 'recommendations' => $this->recommendations,
- 'analysis_id' => $this->analysisId,
- ];
- }
- /**
- * 获取试卷信息
- */
- public function getPaperInfo(): array
- {
- return [
- 'id' => $this->paper['id'] ?? null,
- 'name' => $this->paper['name'] ?? '',
- 'total_questions' => $this->paper['total_questions'] ?? 0,
- 'total_score' => $this->paper['total_score'] ?? 0,
- ];
- }
- /**
- * 获取学生信息
- */
- public function getStudentInfo(): array
- {
- return [
- 'id' => $this->student['id'] ?? '',
- 'name' => $this->student['name'] ?? '',
- 'grade' => $this->student['grade'] ?? '',
- 'class' => $this->student['class'] ?? '',
- ];
- }
- /**
- * 获取整体掌握度
- */
- public function getOverallMastery(): float
- {
- return $this->mastery['average'] ?? 0.0;
- }
- /**
- * 获取薄弱知识点
- */
- public function getWeakKnowledgePoints(): array
- {
- return $this->mastery['weak_list'] ?? [];
- }
- /**
- * 获取题目数量
- */
- public function getQuestionCount(): int
- {
- return count($this->questions);
- }
- /**
- * 判断是否有分析数据
- */
- public function hasAnalysisData(): bool
- {
- return !empty($this->insights) || !empty($this->mastery['items']);
- }
- }
|