Add includes/srs.php
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
function calculateNextInterval(array $word, bool $correct): int
|
||||||
|
{
|
||||||
|
$correctCount = $word['correct'] ?? 0;
|
||||||
|
$wrongCount = $word['wrong'] ?? 0;
|
||||||
|
|
||||||
|
if (!$correct) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// simpele exponential backoff
|
||||||
|
$base = max(1, $correctCount);
|
||||||
|
|
||||||
|
return min(30, (int) pow(2, $base));
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateWordStats(array &$word, bool $correct): void
|
||||||
|
{
|
||||||
|
if ($correct) {
|
||||||
|
$word['correct']++;
|
||||||
|
} else {
|
||||||
|
$word['wrong']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$days = calculateNextInterval($word, $correct);
|
||||||
|
|
||||||
|
$word['nextReview'] = date(
|
||||||
|
'Y-m-d',
|
||||||
|
strtotime("+{$days} days")
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user