/// <summary> /// Gets the level that will be associated to the SRS entry matching the /// given group in the current state. /// </summary> /// <returns>New level for the entity.</returns> private SrsLevel GetUpdatedLevel(SrsQuestionGroup group) { // Take the upper/lower level depending on the success state. int modifier = group.IsWrong ? -1 : 1; SrsLevel newLevel = newLevel = SrsLevelStore.Instance.GetLevelByValue( group.Reference.CurrentGrade + modifier); // If the upper/lower level could not be obtained, (as this may // be the case when at max/min level), use the current one. // Note that this still may return a null value if the levels // were not loaded correctly or if the configuration has changed. return newLevel ?? SrsLevelStore.Instance.GetLevelByValue( group.Reference.CurrentGrade); }
/// <summary> /// Called to update the SRS entry referred by a question group that was /// answered. /// </summary> /// <param name="group">Question group answered.</param> private void UpdateAnsweredGroup(SrsQuestionGroup group) { // Get the new level of the item. SrsLevel newLevel = GetUpdatedLevel(group); // Update its grade and next answer date. if (newLevel != null) { // Set the next answer date according to the delay of the new level. if (newLevel.Delay.HasValue) { group.Reference.NextAnswerDate = DateTime.UtcNow + newLevel.Delay.Value; } else { group.Reference.NextAnswerDate = null; } group.Reference.CurrentGrade = newLevel.Value; } else { // If there is no new level and no current level, the delay is null. group.Reference.NextAnswerDate = null; } // Update the success/failure count. if (group.IsWrong) { group.Reference.FailureCount++; } else { group.Reference.SuccessCount++; } // Update the entry in the DB. UpdateEntry(group.Reference); }