ExamAnalysisDataDto.php 3.0 KB

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