ExamAnalysisDataDto.php 3.8 KB

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