34 lines
644 B
PHP
34 lines
644 B
PHP
<?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")
|
|
);
|
|
} |