Button to set desired FSRS retention to optimal/calculated (#2685)

* Draft set optimal/calculated retention button

Temporarily save the calculated optimal retention and display it with a button
that sets the desired retention above to this value.Don't show button until
attention had been calculated. Disable button when optimal and desired
attention are equal.

I find this nicer than the current alert-popup solution, as it avoids a popup
and gives a choice to the user to accept the calculated retention or not, while
also persisting the calculated retention on the screen for a bit.

TODO: What's still missing is that the `optimalRetention` variable is global and
persists when I change presets. When changing presets the variable should reset to
`undefined`, which would also makes the button disappear. Ideally it should also
disappear when changing the FSRS parameters. So probably it should be made part
of some deck options state and subscribe to some events. But with that I might
need some help. Also I thought whether that variable should go into the deck
options schema but tbh it's not something we want to persist between sessions,
users should recalculate it.

* Add me to contributors for tests so pass

* Add formatting ant type fixes to make tests pass

* Minor fixes (dae)

* Remove the period
This commit is contained in:
Michael Eliachevitch 2023-09-27 08:12:49 +02:00 committed by GitHub
parent ab7e64865e
commit 2580399552
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -337,7 +337,7 @@ deck-config-get-params = Get Params
deck-config-fsrs-on-all-clients =
Please ensure all of your Anki clients are Anki(Mobile) 23.10+ or AnkiDroid 2.17+. FSRS will
not work correctly if one of your clients is older.
deck-config-your-optimal-retention = Your optimal retention is { $num }.
deck-config-set-optimal-retention = Set desired retention to { $num }
## NO NEED TO TRANSLATE. This text is no longer used by Anki, and will be removed in the future.

View File

@ -33,6 +33,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let computingWeights = false;
let checkingWeights = false;
let computingRetention = false;
let optimalRetention = 0;
$: if ($presetName) {
optimalRetention = 0;
}
$: computing = computingWeights || checkingWeights || computingRetention;
$: customSearch = `preset:"${$presetName}"`;
@ -136,11 +140,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
optimalRetentionRequest.weights = $config.fsrsWeights;
optimalRetentionRequest.search = `preset:"${state.getCurrentName()}"`;
const resp = await computeOptimalRetention(optimalRetentionRequest);
alert(
tr.deckConfigYourOptimalRetention({
num: resp.optimalRetention,
}),
);
optimalRetention = resp.optimalRetention;
if (computeRetentionProgress) {
computeRetentionProgress.current =
computeRetentionProgress.total;
@ -184,6 +184,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const pct = ((val.current / val.total) * 100).toFixed(0);
return `${pct}%`;
}
function stringForSetOptimalRetention(retention: number): String {
if (!retention) {
return "";
}
return tr.deckConfigSetOptimalRetention({ num: retention.toFixed(2) });
}
function setDesiredRetentionToOptimal() {
if (!optimalRetention) {
return;
}
$config.desiredRetention = optimalRetention;
}
</script>
<SpinBoxFloatRow
@ -268,6 +282,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{tr.deckConfigComputeButton()}
{/if}
</button>
{#if optimalRetention}
<button
class="btn {'btn-primary'}"
disabled={!optimalRetention ||
optimalRetention === $config.desiredRetention}
on:click={() => setDesiredRetentionToOptimal()}
>
{stringForSetOptimalRetention(optimalRetention)}
</button>
{/if}
<div>{computeRetentionProgressString}</div>
</details>
</div>