ExamAnalysisDataDto.php 3.3 KB

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