| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace App\Livewire;
- use App\Services\LearningAnalyticsService;
- use Livewire\Component;
- class SkillProficiencyRadar extends Component
- {
- public string $studentId = '';
- public array $radarData = [];
- public bool $isLoading = false;
- public string $errorMessage = '';
- public function mount(string $studentId): void
- {
- $this->studentId = $studentId;
- $this->loadRadarData();
- }
- public function loadRadarData(): void
- {
- $this->isLoading = true;
- $this->errorMessage = '';
- try {
- $service = app(LearningAnalyticsService::class);
- $skillProficiency = $service->getStudentSkillProficiency($this->studentId);
- if ($skillProficiency && isset($skillProficiency['data'])) {
- $this->radarData = $this->processRadarData($skillProficiency['data']);
- } else {
- $this->radarData = [];
- }
- } catch (\Exception $e) {
- $this->errorMessage = '加载雷达图数据失败:' . $e->getMessage();
- $this->radarData = [];
- } finally {
- $this->isLoading = false;
- }
- }
- /**
- * 处理雷达图数据
- */
- private function processRadarData(array $skillData): array
- {
- $processedData = [];
- $maxValue = 1.0; // 技能熟练度最大值为1
- foreach ($skillData as $skill) {
- $processedData[] = [
- 'skill_name' => $skill['skill_name'],
- 'proficiency_level' => $skill['proficiency_level'],
- 'skill_level' => $skill['skill_level'],
- 'total_questions_attempted' => $skill['total_questions_attempted'],
- 'simple_accuracy' => $skill['simple_accuracy'] ?? 0,
- 'intermediate_accuracy' => $skill['intermediate_accuracy'] ?? 0,
- 'advanced_accuracy' => $skill['advanced_accuracy'] ?? 0,
- 'practice_streak' => $skill['practice_streak'] ?? 0,
- 'max_value' => $maxValue,
- ];
- }
- return [
- 'data' => $processedData,
- 'max_value' => $maxValue,
- ];
- }
- /**
- * 获取技能等级颜色
- */
- public function getSkillLevelColor(string $skillLevel): string
- {
- return match ($skillLevel) {
- 'beginner' => '#ef4444', // 红色 - 初学者
- 'elementary' => '#f97316', // 橙色 - 入门
- 'intermediate' => '#eab308', // 黄色 - 进阶
- 'advanced' => '#22c55e', // 绿色 - 熟练
- 'proficient' => '#3b82f6', // 蓝色 - 精通
- default => '#9ca3af', // 灰色 - 未知
- };
- }
- /**
- * 获取技能等级中文名称
- */
- public function getSkillLevelName(string $skillLevel): string
- {
- return match ($skillLevel) {
- 'beginner' => '初学者',
- 'elementary' => '入门',
- 'intermediate' => '进阶',
- 'advanced' => '熟练',
- 'proficient' => '精通',
- default => '未知',
- };
- }
- /**
- * 获取难度标签
- */
- public function getDifficultyLabel(string $difficulty): string
- {
- return match ($difficulty) {
- 'simple' => '简单',
- 'intermediate' => '中等',
- 'advanced' => '困难',
- default => $difficulty,
- };
- }
- public function render()
- {
- return view('livewire.skill-proficiency-radar');
- }
- }
|