import { QuizAnswer } from '../types/quiz-answer'; /** * Example total questions per round (Adjust to your logic) */ export const totalQuestionsPerRound = { 1: 10, 2: 10, 3: 10, 4: 5 }; /** * Determine which round a given question belongs to. * 1..10 => Round 1 * 11..20 => Round 2 * 21..30 => Round 3 * 31.. => Round 4 */ export function getCurrentRound(question: number) { if (question >= 1 && question <= 10) return 1; if (question >= 11 && question <= 20) return 2; if (question >= 21 && question <= 30) return 3; return 4; } /** * Maps slide number to question number (reverse of questionToSlideNumber) * Based on the presentation structure: * - slide 1: prizes for 1-3 place (no question) * - slide 2: instructions for 1st round (no question) * - slides 3-12: q1 to q10 * - slide 13: answers for round 1 (no question) * - slide 14: instructions for round 2 (no question) * - slides 15-24: q11 to q20 * - slide 25: answers for round 2 (no question) * - slide 26: instructions for round 3 (no question) * - slides 27-36: q21-q30 * - slide 37: answers round 3 (no question) * - slide 38: instructions for round 4 (no question) * - slides 39-43: q31 to q35 * - slide 44: answers to round 4 (no question) * * @returns The question number or null if the slide doesn't correspond to a question */ export function slideToQuestionNumber(slideNumber: number): number | null { // Round 1: slides 3-12 are q1-q10 if (slideNumber >= 3 && slideNumber <= 12) { return slideNumber - 2; } // Round 2: slides 15-24 are q11-q20 if (slideNumber >= 15 && slideNumber <= 24) { return slideNumber - 4; } // Round 3: slides 27-36 are q21-q30 if (slideNumber >= 27 && slideNumber <= 36) { return slideNumber - 6; } // Round 4: slides 39-43 are q31-q35 if (slideNumber >= 39 && slideNumber <= 43) { return slideNumber - 8; } // If the slide doesn't correspond to a question (instructions or answers slides) return null; } /** * Converts absolute question number to the question index within the round. * e.g. questionNumber=11 => 'Въпрос 1 от Кръг 2'. */ export function questionToRoundQuestion(question: number) { if (question >= 1 && question <= 10) return question; if (question >= 11 && question <= 20) return question - 10; if (question >= 21 && question <= 30) return question - 20; return question - 30; } export function groupByRound(answers: QuizAnswer[]) { const rounds = { '1-10': [] as QuizAnswer[], '11-20': [] as QuizAnswer[], '21-30': [] as QuizAnswer[], '31-35': [] as QuizAnswer[] }; answers.forEach((answer) => { const q = answer.question_number; if (q >= 1 && q <= 10) { rounds['1-10'].push(answer); } else if (q >= 11 && q <= 20) { rounds['11-20'].push(answer); } else if (q >= 21 && q <= 30) { rounds['21-30'].push(answer); } else if (q >= 31 && q <= 35) { rounds['31-35'].push(answer); } }); return rounds; } export function getRound(questionNumber: number): number { if (questionNumber >= 1 && questionNumber <= 10) return 1; if (questionNumber >= 11 && questionNumber <= 20) return 2; if (questionNumber >= 21 && questionNumber <= 30) return 3; return 4; }