| 1 | import type { PracticeSessionStats } from '@/client' |
| 2 | |
| 3 | export const calculateAverageAccuracy = ( |
| 4 | sessions: PracticeSessionStats[] | undefined, |
| 5 | ): number | null => { |
| 6 | if (!sessions || sessions.length === 0) return null |
| 7 | |
| 8 | const totalCorrect = sessions.reduce((sum, session) => sum + session.correct_answers, 0) |
| 9 | const totalPracticed = sessions.reduce((sum, session) => sum + session.cards_practiced, 0) |
| 10 | |
| 11 | return totalPracticed > 0 ? Math.round((totalCorrect / totalPracticed) * 100) : null |
| 12 | } |
| 13 | |
| 14 | export const calculateSessionSuccessRate = ( |
| 15 | session: PracticeSessionStats | null, |