shufle order
This commit is contained in:
@@ -68,9 +68,15 @@ class AttemptService {
|
||||
final answerResults = <AnswerResult>[];
|
||||
final updatedQuestions = <Question>[];
|
||||
|
||||
// Process each question in the attempt
|
||||
for (final question in attempt.questions) {
|
||||
final userAnswer = answers[question.id];
|
||||
// Process each question in the attempt.
|
||||
// Use the deck's current question state (not the attempt snapshot) so that
|
||||
// manual "mark as known" during the attempt is preserved when applying results.
|
||||
for (final questionInAttempt in attempt.questions) {
|
||||
final currentQuestion = deck.questions
|
||||
.where((q) => q.id == questionInAttempt.id)
|
||||
.firstOrNull ?? questionInAttempt;
|
||||
|
||||
final userAnswer = answers[currentQuestion.id];
|
||||
if (userAnswer == null) {
|
||||
// Question not answered, treat as incorrect
|
||||
continue;
|
||||
@@ -89,28 +95,28 @@ class AttemptService {
|
||||
|
||||
// Check if answer is correct
|
||||
// For multiple correct answers: user must select all correct answers and no incorrect ones
|
||||
final correctIndices = question.correctIndices;
|
||||
final correctIndices = currentQuestion.correctIndices;
|
||||
final userSet = userAnswerIndices.toSet();
|
||||
final correctSet = correctIndices.toSet();
|
||||
final isCorrect = userSet.length == correctSet.length &&
|
||||
final isCorrect = userSet.length == correctSet.length &&
|
||||
userSet.every((idx) => correctSet.contains(idx));
|
||||
final userMarkedNeedsPractice = overrides[question.id] ?? false;
|
||||
final userMarkedNeedsPractice = overrides[currentQuestion.id] ?? false;
|
||||
|
||||
// Determine status change
|
||||
final oldIsKnown = question.isKnown;
|
||||
final oldStreak = question.consecutiveCorrect;
|
||||
// Determine status change (from current deck state)
|
||||
final oldIsKnown = currentQuestion.isKnown;
|
||||
final oldStreak = currentQuestion.consecutiveCorrect;
|
||||
|
||||
// Update question
|
||||
// Update question from current deck state so manual marks are preserved
|
||||
final updated = userMarkedNeedsPractice
|
||||
? DeckService.updateQuestionWithManualOverride(
|
||||
question: question,
|
||||
question: currentQuestion,
|
||||
isCorrect: isCorrect,
|
||||
userMarkedNeedsPractice: true,
|
||||
config: deck.config,
|
||||
currentAttemptIndex: deck.currentAttemptIndex,
|
||||
)
|
||||
: DeckService.updateQuestionAfterAnswer(
|
||||
question: question,
|
||||
question: currentQuestion,
|
||||
isCorrect: isCorrect,
|
||||
config: deck.config,
|
||||
currentAttemptIndex: deck.currentAttemptIndex,
|
||||
|
||||
@@ -76,6 +76,20 @@ class Deck {
|
||||
return (knownCount / questions.length) * 100.0;
|
||||
}
|
||||
|
||||
/// Progress percentage including partial credit: each question contributes
|
||||
/// 1.0 if known, otherwise (consecutiveCorrect / requiredConsecutiveCorrect)
|
||||
/// capped at 1.0. Averaged over all questions * 100.
|
||||
double get progressPercentage {
|
||||
if (questions.isEmpty) return 0.0;
|
||||
final required = config.requiredConsecutiveCorrect;
|
||||
final sum = questions.fold<double>(0.0, (sum, q) {
|
||||
if (q.isKnown) return sum + 1.0;
|
||||
final partial = (q.consecutiveCorrect / required).clamp(0.0, 1.0);
|
||||
return sum + partial;
|
||||
});
|
||||
return (sum / questions.length) * 100.0;
|
||||
}
|
||||
|
||||
/// Number of completed attempts.
|
||||
int get attemptCount => attemptHistory.length;
|
||||
|
||||
|
||||
@@ -19,6 +19,10 @@ class DeckConfig {
|
||||
/// If false, known questions will be excluded from attempts.
|
||||
final bool includeKnownInAttempts;
|
||||
|
||||
/// Whether to shuffle answer order for each question in an attempt.
|
||||
/// When true, answer options appear in random order each attempt.
|
||||
final bool shuffleAnswerOrder;
|
||||
|
||||
/// Optional time limit for attempts in seconds.
|
||||
/// If null, no time limit is enforced.
|
||||
final int? timeLimitSeconds;
|
||||
@@ -30,6 +34,7 @@ class DeckConfig {
|
||||
this.priorityDecreaseOnCorrect = 2,
|
||||
this.immediateFeedbackEnabled = true,
|
||||
this.includeKnownInAttempts = false,
|
||||
this.shuffleAnswerOrder = true,
|
||||
this.timeLimitSeconds,
|
||||
});
|
||||
|
||||
@@ -41,6 +46,7 @@ class DeckConfig {
|
||||
int? priorityDecreaseOnCorrect,
|
||||
bool? immediateFeedbackEnabled,
|
||||
bool? includeKnownInAttempts,
|
||||
bool? shuffleAnswerOrder,
|
||||
int? timeLimitSeconds,
|
||||
}) {
|
||||
return DeckConfig(
|
||||
@@ -55,6 +61,7 @@ class DeckConfig {
|
||||
immediateFeedbackEnabled ?? this.immediateFeedbackEnabled,
|
||||
includeKnownInAttempts:
|
||||
includeKnownInAttempts ?? this.includeKnownInAttempts,
|
||||
shuffleAnswerOrder: shuffleAnswerOrder ?? this.shuffleAnswerOrder,
|
||||
timeLimitSeconds: timeLimitSeconds ?? this.timeLimitSeconds,
|
||||
);
|
||||
}
|
||||
@@ -70,6 +77,7 @@ class DeckConfig {
|
||||
priorityDecreaseOnCorrect == other.priorityDecreaseOnCorrect &&
|
||||
immediateFeedbackEnabled == other.immediateFeedbackEnabled &&
|
||||
includeKnownInAttempts == other.includeKnownInAttempts &&
|
||||
shuffleAnswerOrder == other.shuffleAnswerOrder &&
|
||||
timeLimitSeconds == other.timeLimitSeconds;
|
||||
|
||||
@override
|
||||
@@ -80,6 +88,7 @@ class DeckConfig {
|
||||
priorityDecreaseOnCorrect.hashCode ^
|
||||
immediateFeedbackEnabled.hashCode ^
|
||||
includeKnownInAttempts.hashCode ^
|
||||
shuffleAnswerOrder.hashCode ^
|
||||
(timeLimitSeconds?.hashCode ?? 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user