ExamAnalysisDataDto.php 3.1 KB

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