Compare commits
2 Commits
cbb9326f84
...
7c71ffcf31
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c71ffcf31 | |||
| 4243cdc68b |
@@ -36,24 +36,24 @@ function calculateNewCardIntervals(): PreviewIntervals {
|
||||
};
|
||||
}
|
||||
|
||||
function calculateLearningIntervals(left: number): PreviewIntervals {
|
||||
const steps = SM2_CONFIG.LEARNING_STEPS;
|
||||
function calculateLearningIntervals(left: number, isRelearning: boolean): PreviewIntervals {
|
||||
const steps = isRelearning ? SM2_CONFIG.RELEARNING_STEPS : SM2_CONFIG.LEARNING_STEPS;
|
||||
const stepIndex = Math.floor(left % 1000);
|
||||
|
||||
const again = steps[0];
|
||||
const again = steps[0] ?? 1;
|
||||
|
||||
let hard: number;
|
||||
if (stepIndex === 0 && steps.length >= 2) {
|
||||
hard = (steps[0] + steps[1]) / 2;
|
||||
} else if (stepIndex < steps.length - 1) {
|
||||
hard = steps[stepIndex];
|
||||
const step0 = steps[0] ?? 1;
|
||||
const step1 = steps[1] ?? step0;
|
||||
hard = (step0 + step1) / 2;
|
||||
} else {
|
||||
hard = SM2_CONFIG.GRADUATING_INTERVAL_GOOD * 1440;
|
||||
hard = steps[stepIndex] ?? steps[0] ?? 1;
|
||||
}
|
||||
|
||||
let good: number;
|
||||
if (stepIndex < steps.length - 1) {
|
||||
good = steps[stepIndex + 1];
|
||||
good = steps[stepIndex + 1] ?? steps[0] ?? 1;
|
||||
} else {
|
||||
good = SM2_CONFIG.GRADUATING_INTERVAL_GOOD * 1440;
|
||||
}
|
||||
@@ -68,8 +68,9 @@ export function calculatePreviewIntervals(card: CardPreview): PreviewIntervals {
|
||||
case CardType.NEW:
|
||||
return calculateNewCardIntervals();
|
||||
case CardType.LEARNING:
|
||||
return calculateLearningIntervals(card.left, false);
|
||||
case CardType.RELEARNING:
|
||||
return calculateLearningIntervals(card.left);
|
||||
return calculateLearningIntervals(card.left, true);
|
||||
case CardType.REVIEW:
|
||||
default:
|
||||
return calculateReviewIntervals(card.ivl, card.factor);
|
||||
|
||||
@@ -126,7 +126,7 @@ function scheduleNewCard(ease: ReviewEase, currentFactor: number): {
|
||||
};
|
||||
}
|
||||
|
||||
function scheduleLearningCard(ease: ReviewEase, currentFactor: number, left: number): {
|
||||
function scheduleLearningCard(ease: ReviewEase, currentFactor: number, left: number, isRelearning: boolean): {
|
||||
type: CardType;
|
||||
queue: CardQueue;
|
||||
ivl: number;
|
||||
@@ -134,12 +134,13 @@ function scheduleLearningCard(ease: ReviewEase, currentFactor: number, left: num
|
||||
newFactor: number;
|
||||
newLeft: number;
|
||||
} {
|
||||
const steps = SM2_CONFIG.LEARNING_STEPS;
|
||||
const steps = isRelearning ? SM2_CONFIG.RELEARNING_STEPS : SM2_CONFIG.LEARNING_STEPS;
|
||||
const totalSteps = steps.length;
|
||||
const cardType = isRelearning ? CardType.RELEARNING : CardType.LEARNING;
|
||||
|
||||
if (ease === 1) {
|
||||
return {
|
||||
type: CardType.LEARNING,
|
||||
type: cardType,
|
||||
queue: CardQueue.LEARNING,
|
||||
ivl: 0,
|
||||
due: Math.floor(Date.now() / 1000) + steps[0] * 60,
|
||||
@@ -152,9 +153,11 @@ function scheduleLearningCard(ease: ReviewEase, currentFactor: number, left: num
|
||||
|
||||
if (ease === 2) {
|
||||
if (stepIndex === 0 && steps.length >= 2) {
|
||||
const avgStep = (steps[0] + steps[1]) / 2;
|
||||
const step0 = steps[0] ?? 1;
|
||||
const step1 = steps[1] ?? step0;
|
||||
const avgStep = (step0 + step1) / 2;
|
||||
return {
|
||||
type: CardType.LEARNING,
|
||||
type: cardType,
|
||||
queue: CardQueue.LEARNING,
|
||||
ivl: 0,
|
||||
due: Math.floor(Date.now() / 1000) + avgStep * 60,
|
||||
@@ -162,35 +165,26 @@ function scheduleLearningCard(ease: ReviewEase, currentFactor: number, left: num
|
||||
newLeft: left,
|
||||
};
|
||||
}
|
||||
if (stepIndex < steps.length - 1) {
|
||||
return {
|
||||
type: CardType.LEARNING,
|
||||
queue: CardQueue.LEARNING,
|
||||
ivl: 0,
|
||||
due: Math.floor(Date.now() / 1000) + steps[stepIndex] * 60,
|
||||
newFactor: currentFactor,
|
||||
newLeft: left,
|
||||
};
|
||||
}
|
||||
const ivl = SM2_CONFIG.GRADUATING_INTERVAL_GOOD;
|
||||
const currentStepDelay = steps[stepIndex] ?? steps[0] ?? 1;
|
||||
return {
|
||||
type: CardType.REVIEW,
|
||||
queue: CardQueue.REVIEW,
|
||||
ivl,
|
||||
due: calculateDueDate(ivl),
|
||||
newFactor: SM2_CONFIG.DEFAULT_FACTOR,
|
||||
newLeft: 0,
|
||||
type: cardType,
|
||||
queue: CardQueue.LEARNING,
|
||||
ivl: 0,
|
||||
due: Math.floor(Date.now() / 1000) + currentStepDelay * 60,
|
||||
newFactor: currentFactor,
|
||||
newLeft: left,
|
||||
};
|
||||
}
|
||||
|
||||
if (ease === 3) {
|
||||
if (stepIndex < steps.length - 1) {
|
||||
const nextStep = stepIndex + 1;
|
||||
const nextStepDelay = steps[nextStep] ?? steps[0];
|
||||
return {
|
||||
type: CardType.LEARNING,
|
||||
type: cardType,
|
||||
queue: CardQueue.LEARNING,
|
||||
ivl: 0,
|
||||
due: Math.floor(Date.now() / 1000) + steps[nextStep] * 60,
|
||||
due: Math.floor(Date.now() / 1000) + nextStepDelay * 60,
|
||||
newFactor: currentFactor,
|
||||
newLeft: nextStep * 1000 + (totalSteps - nextStep),
|
||||
};
|
||||
@@ -361,7 +355,7 @@ export async function serviceAnswerCard(
|
||||
nextReviewDate: calculateNextReviewTime(result.ivl),
|
||||
};
|
||||
} else if (card.type === CardType.LEARNING || card.type === CardType.RELEARNING) {
|
||||
const result = scheduleLearningCard(ease, card.factor, card.left);
|
||||
const result = scheduleLearningCard(ease, card.factor, card.left, card.type === CardType.RELEARNING);
|
||||
updateData = {
|
||||
type: result.type,
|
||||
queue: result.queue,
|
||||
|
||||
Reference in New Issue
Block a user