MistakeStatsOverview.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Livewire\MistakeBook;
  3. use App\Services\MistakeBookService;
  4. use Filament\Widgets\StatsOverviewWidget as BaseStatsOverviewWidget;
  5. class MistakeStatsOverview extends BaseStatsOverviewWidget
  6. {
  7. public ?string $studentId;
  8. protected static ?int $sort = 0;
  9. public function mount(?string $studentId = null): void
  10. {
  11. $this->studentId = $studentId;
  12. }
  13. protected function getCards(): array
  14. {
  15. if (!$this->studentId) {
  16. return [];
  17. }
  18. $service = app(MistakeBookService::class);
  19. $summary = $service->summarize($this->studentId);
  20. return [
  21. \Filament\Widgets\StatsOverviewWidget\Stat::make('总错题数', $summary['total'] ?? 0)
  22. ->description('累计错题数量')
  23. ->descriptionIcon('heroicon-m-arrow-trending-up')
  24. ->chart([7, 3, 4, 5, 6, 3, 5, 3])
  25. ->color('primary'),
  26. \Filament\Widgets\StatsOverviewWidget\Stat::make('本周新增', $summary['this_week'] ?? 0)
  27. ->description('本周新增错题')
  28. ->descriptionIcon('heroicon-m-arrow-trending-up')
  29. ->chart([4, 5, 6, 3, 4, 5, 6])
  30. ->color('success'),
  31. \Filament\Widgets\StatsOverviewWidget\Stat::make('待复习', $summary['pending'] ?? 0)
  32. ->description('需要复习的错题')
  33. ->descriptionIcon('heroicon-m-exclamation-triangle')
  34. ->chart([7, 3, 4, 5, 6, 3, 5])
  35. ->color('warning'),
  36. \Filament\Widgets\StatsOverviewWidget\Stat::make('掌握率', ($summary['mastery_rate'] ?? 0) . '%')
  37. ->description('已掌握错题比例')
  38. ->descriptionIcon('heroicon-m-check-circle')
  39. ->chart([7, 3, 4, 5, 6, 3, 5])
  40. ->color($summary['mastery_rate'] >= 80 ? 'success' : ($summary['mastery_rate'] >= 50 ? 'warning' : 'danger')),
  41. ];
  42. }
  43. }