ExamAnalysisDataDto.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\DTO;
  3. /**
  4. * 学情分析数据传输对象
  5. * 封装学情分析所需的所有数据
  6. */
  7. class ExamAnalysisDataDto
  8. {
  9. public function __construct(
  10. public readonly array $paper,
  11. public readonly array $student,
  12. public readonly array $questions,
  13. public readonly array $mastery,
  14. public readonly array $insights,
  15. public readonly array $recommendations,
  16. public readonly ?string $analysisId = null
  17. ) {}
  18. /**
  19. * 从数组创建DTO
  20. */
  21. public static function fromArray(array $data): self
  22. {
  23. return new self(
  24. paper: $data['paper'] ?? [],
  25. student: $data['student'] ?? [],
  26. questions: $data['questions'] ?? [],
  27. mastery: $data['mastery'] ?? [],
  28. insights: $data['insights'] ?? [],
  29. recommendations: $data['recommendations'] ?? [],
  30. analysisId: $data['analysis_id'] ?? $data['analysisId'] ?? null,
  31. );
  32. }
  33. /**
  34. * 转换为数组
  35. */
  36. public function toArray(): array
  37. {
  38. return [
  39. 'paper' => $this->paper,
  40. 'student' => $this->student,
  41. 'questions' => $this->questions,
  42. 'mastery' => $this->mastery,
  43. 'insights' => $this->insights,
  44. 'recommendations' => $this->recommendations,
  45. 'analysis_id' => $this->analysisId,
  46. ];
  47. }
  48. /**
  49. * 获取试卷信息
  50. */
  51. public function getPaperInfo(): array
  52. {
  53. return [
  54. 'id' => $this->paper['id'] ?? null,
  55. 'name' => $this->paper['name'] ?? '',
  56. 'total_questions' => $this->paper['total_questions'] ?? 0,
  57. 'total_score' => $this->paper['total_score'] ?? 0,
  58. ];
  59. }
  60. /**
  61. * 获取学生信息
  62. */
  63. public function getStudentInfo(): array
  64. {
  65. return [
  66. 'id' => $this->student['id'] ?? '',
  67. 'name' => $this->student['name'] ?? '',
  68. 'grade' => $this->student['grade'] ?? '',
  69. 'class' => $this->student['class'] ?? '',
  70. ];
  71. }
  72. /**
  73. * 获取整体掌握度
  74. */
  75. public function getOverallMastery(): float
  76. {
  77. return $this->mastery['average'] ?? 0.0;
  78. }
  79. /**
  80. * 获取薄弱知识点
  81. */
  82. public function getWeakKnowledgePoints(): array
  83. {
  84. return $this->mastery['weak_list'] ?? [];
  85. }
  86. /**
  87. * 获取题目数量
  88. */
  89. public function getQuestionCount(): int
  90. {
  91. return count($this->questions);
  92. }
  93. /**
  94. * 判断是否有分析数据
  95. */
  96. public function hasAnalysisData(): bool
  97. {
  98. return !empty($this->insights) || !empty($this->mastery['items']);
  99. }
  100. }