2023-09-05 10:45:05 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
|
|
|
import {
|
2023-09-16 08:09:26 +02:00
|
|
|
ComputeRetentionProgress,
|
|
|
|
type ComputeWeightsProgress,
|
2023-09-05 10:45:05 +02:00
|
|
|
} from "@tslib/anki/collection_pb";
|
2023-09-18 08:43:12 +02:00
|
|
|
import { ComputeOptimalRetentionRequest } from "@tslib/anki/scheduler_pb";
|
2023-09-05 10:45:05 +02:00
|
|
|
import {
|
|
|
|
computeFsrsWeights,
|
|
|
|
computeOptimalRetention,
|
|
|
|
evaluateWeights,
|
|
|
|
setWantsAbort,
|
|
|
|
} from "@tslib/backend";
|
2023-09-16 08:09:26 +02:00
|
|
|
import * as tr from "@tslib/ftl";
|
2023-09-05 10:45:05 +02:00
|
|
|
import { runWithBackendProgress } from "@tslib/progress";
|
|
|
|
|
2023-09-09 01:00:55 +02:00
|
|
|
import SettingTitle from "../components/SettingTitle.svelte";
|
2023-09-05 10:45:05 +02:00
|
|
|
import type { DeckOptionsState } from "./lib";
|
2023-09-16 08:09:26 +02:00
|
|
|
import SpinBoxFloatRow from "./SpinBoxFloatRow.svelte";
|
2023-09-05 10:45:05 +02:00
|
|
|
import WeightsInputRow from "./WeightsInputRow.svelte";
|
|
|
|
|
|
|
|
export let state: DeckOptionsState;
|
|
|
|
|
2023-09-25 07:54:18 +02:00
|
|
|
const presetName = state.currentPresetName;
|
|
|
|
|
2023-09-05 10:45:05 +02:00
|
|
|
const config = state.currentConfig;
|
2023-09-16 08:09:26 +02:00
|
|
|
const defaults = state.defaults;
|
2023-09-05 10:45:05 +02:00
|
|
|
|
2023-09-16 08:09:26 +02:00
|
|
|
let computeWeightsProgress: ComputeWeightsProgress | undefined;
|
2023-09-25 08:40:11 +02:00
|
|
|
let computingWeights = false;
|
|
|
|
let checkingWeights = false;
|
|
|
|
let computingRetention = false;
|
2023-09-27 08:12:49 +02:00
|
|
|
let optimalRetention = 0;
|
|
|
|
$: if ($presetName) {
|
|
|
|
optimalRetention = 0;
|
|
|
|
}
|
2023-09-25 08:40:11 +02:00
|
|
|
$: computing = computingWeights || checkingWeights || computingRetention;
|
2023-09-25 07:54:18 +02:00
|
|
|
$: customSearch = `preset:"${$presetName}"`;
|
2023-09-05 10:45:05 +02:00
|
|
|
|
|
|
|
let computeRetentionProgress:
|
2023-09-16 08:09:26 +02:00
|
|
|
| ComputeWeightsProgress
|
|
|
|
| ComputeRetentionProgress
|
2023-09-05 10:45:05 +02:00
|
|
|
| undefined;
|
|
|
|
|
2023-09-18 08:43:12 +02:00
|
|
|
const optimalRetentionRequest = new ComputeOptimalRetentionRequest({
|
|
|
|
deckSize: 10000,
|
|
|
|
daysToSimulate: 365,
|
2023-09-25 07:54:18 +02:00
|
|
|
maxMinutesOfStudyPerDay: 30,
|
2023-09-18 08:43:12 +02:00
|
|
|
});
|
2023-09-25 06:34:26 +02:00
|
|
|
$: if (optimalRetentionRequest.daysToSimulate > 3650) {
|
|
|
|
optimalRetentionRequest.daysToSimulate = 3650;
|
|
|
|
}
|
2023-09-05 10:45:05 +02:00
|
|
|
async function computeWeights(): Promise<void> {
|
2023-09-25 08:40:11 +02:00
|
|
|
if (computingWeights) {
|
2023-09-05 10:45:05 +02:00
|
|
|
await setWantsAbort({});
|
|
|
|
return;
|
|
|
|
}
|
2023-09-25 08:40:11 +02:00
|
|
|
computingWeights = true;
|
2023-09-05 10:45:05 +02:00
|
|
|
try {
|
|
|
|
await runWithBackendProgress(
|
|
|
|
async () => {
|
|
|
|
const resp = await computeFsrsWeights({
|
2023-09-25 07:54:18 +02:00
|
|
|
search: customSearch,
|
2023-09-05 10:45:05 +02:00
|
|
|
});
|
|
|
|
if (computeWeightsProgress) {
|
|
|
|
computeWeightsProgress.current = computeWeightsProgress.total;
|
|
|
|
}
|
2023-09-16 08:09:26 +02:00
|
|
|
if (resp.fsrsItems < 1000) {
|
2023-09-25 08:17:00 +02:00
|
|
|
alert(
|
|
|
|
tr.deckConfigMustHave1000Reviews({ count: resp.fsrsItems }),
|
|
|
|
);
|
2023-09-16 08:09:26 +02:00
|
|
|
} else {
|
2023-09-25 08:17:00 +02:00
|
|
|
$config.fsrsWeights = resp.weights;
|
2023-09-16 08:09:26 +02:00
|
|
|
}
|
2023-09-05 10:45:05 +02:00
|
|
|
},
|
|
|
|
(progress) => {
|
|
|
|
if (progress.value.case === "computeWeights") {
|
|
|
|
computeWeightsProgress = progress.value.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} finally {
|
2023-09-25 08:40:11 +02:00
|
|
|
computingWeights = false;
|
2023-09-05 10:45:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkWeights(): Promise<void> {
|
2023-09-25 08:40:11 +02:00
|
|
|
if (checkingWeights) {
|
2023-09-05 10:45:05 +02:00
|
|
|
await setWantsAbort({});
|
|
|
|
return;
|
|
|
|
}
|
2023-09-25 08:40:11 +02:00
|
|
|
checkingWeights = true;
|
2023-09-05 10:45:05 +02:00
|
|
|
try {
|
|
|
|
await runWithBackendProgress(
|
|
|
|
async () => {
|
|
|
|
const search = customSearch ?? `preset:"${state.getCurrentName()}"`;
|
|
|
|
const resp = await evaluateWeights({
|
|
|
|
weights: $config.fsrsWeights,
|
|
|
|
search,
|
|
|
|
});
|
|
|
|
if (computeWeightsProgress) {
|
|
|
|
computeWeightsProgress.current = computeWeightsProgress.total;
|
|
|
|
}
|
|
|
|
setTimeout(
|
|
|
|
() =>
|
|
|
|
alert(
|
|
|
|
`Log loss: ${resp.logLoss.toFixed(
|
|
|
|
3,
|
2023-09-16 08:09:26 +02:00
|
|
|
)}, RMSE(bins): ${resp.rmseBins.toFixed(
|
|
|
|
3,
|
|
|
|
)}. ${tr.deckConfigSmallerIsBetter()}`,
|
2023-09-05 10:45:05 +02:00
|
|
|
),
|
|
|
|
200,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
(progress) => {
|
|
|
|
if (progress.value.case === "computeWeights") {
|
|
|
|
computeWeightsProgress = progress.value.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} finally {
|
2023-09-25 08:40:11 +02:00
|
|
|
checkingWeights = false;
|
2023-09-05 10:45:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function computeRetention(): Promise<void> {
|
2023-09-25 08:40:11 +02:00
|
|
|
if (computingRetention) {
|
2023-09-05 10:45:05 +02:00
|
|
|
await setWantsAbort({});
|
|
|
|
return;
|
|
|
|
}
|
2023-09-25 08:40:11 +02:00
|
|
|
computingRetention = true;
|
2023-09-05 10:45:05 +02:00
|
|
|
try {
|
|
|
|
await runWithBackendProgress(
|
|
|
|
async () => {
|
2023-09-18 08:43:12 +02:00
|
|
|
optimalRetentionRequest.maxInterval = $config.maximumReviewInterval;
|
|
|
|
optimalRetentionRequest.weights = $config.fsrsWeights;
|
|
|
|
optimalRetentionRequest.search = `preset:"${state.getCurrentName()}"`;
|
|
|
|
const resp = await computeOptimalRetention(optimalRetentionRequest);
|
2023-09-27 08:12:49 +02:00
|
|
|
optimalRetention = resp.optimalRetention;
|
2023-09-05 10:45:05 +02:00
|
|
|
if (computeRetentionProgress) {
|
|
|
|
computeRetentionProgress.current =
|
|
|
|
computeRetentionProgress.total;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(progress) => {
|
|
|
|
if (progress.value.case === "computeRetention") {
|
|
|
|
computeRetentionProgress = progress.value.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} finally {
|
2023-09-25 08:40:11 +02:00
|
|
|
computingRetention = false;
|
2023-09-05 10:45:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$: computeWeightsProgressString = renderWeightProgress(computeWeightsProgress);
|
|
|
|
$: computeRetentionProgressString = renderRetentionProgress(
|
|
|
|
computeRetentionProgress,
|
|
|
|
);
|
|
|
|
|
2023-09-16 08:09:26 +02:00
|
|
|
function renderWeightProgress(val: ComputeWeightsProgress | undefined): String {
|
2023-09-05 10:45:05 +02:00
|
|
|
if (!val || !val.total) {
|
|
|
|
return "";
|
|
|
|
}
|
2023-09-26 06:01:05 +02:00
|
|
|
let pct = ((val.current / val.total) * 100).toFixed(1);
|
2023-09-05 10:45:05 +02:00
|
|
|
pct = `${pct}%`;
|
2023-09-16 08:09:26 +02:00
|
|
|
if (val instanceof ComputeRetentionProgress) {
|
2023-09-05 10:45:05 +02:00
|
|
|
return pct;
|
|
|
|
} else {
|
2023-09-16 08:09:26 +02:00
|
|
|
return `${pct} of ${val.fsrsItems} reviews`;
|
2023-09-05 10:45:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderRetentionProgress(
|
2023-09-16 08:09:26 +02:00
|
|
|
val: ComputeRetentionProgress | undefined,
|
2023-09-05 10:45:05 +02:00
|
|
|
): String {
|
|
|
|
if (!val || !val.total) {
|
|
|
|
return "";
|
|
|
|
}
|
2023-09-26 06:01:05 +02:00
|
|
|
const pct = ((val.current / val.total) * 100).toFixed(0);
|
2023-09-05 10:45:05 +02:00
|
|
|
return `${pct}%`;
|
|
|
|
}
|
2023-09-27 08:12:49 +02:00
|
|
|
|
|
|
|
function stringForSetOptimalRetention(retention: number): String {
|
|
|
|
if (!retention) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return tr.deckConfigSetOptimalRetention({ num: retention.toFixed(2) });
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDesiredRetentionToOptimal() {
|
|
|
|
if (!optimalRetention) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$config.desiredRetention = optimalRetention;
|
|
|
|
}
|
2023-09-05 10:45:05 +02:00
|
|
|
</script>
|
|
|
|
|
2023-09-16 08:09:26 +02:00
|
|
|
<SpinBoxFloatRow
|
|
|
|
bind:value={$config.desiredRetention}
|
|
|
|
defaultValue={defaults.desiredRetention}
|
2023-09-26 05:03:49 +02:00
|
|
|
min={0.7}
|
2023-09-16 08:09:26 +02:00
|
|
|
max={0.97}
|
|
|
|
>
|
|
|
|
<SettingTitle>
|
|
|
|
{tr.deckConfigDesiredRetention()}
|
|
|
|
</SettingTitle>
|
|
|
|
</SpinBoxFloatRow>
|
2023-09-05 10:45:05 +02:00
|
|
|
|
2023-09-16 08:09:26 +02:00
|
|
|
<div class="ms-1 me-1">
|
|
|
|
<WeightsInputRow bind:value={$config.fsrsWeights} defaultValue={[]}>
|
|
|
|
<SettingTitle>{tr.deckConfigWeights()}</SettingTitle>
|
|
|
|
</WeightsInputRow>
|
|
|
|
</div>
|
2023-09-05 10:45:05 +02:00
|
|
|
|
2023-09-16 08:09:26 +02:00
|
|
|
<div class="m-2">
|
|
|
|
<details>
|
|
|
|
<summary>{tr.deckConfigComputeOptimalWeights()}</summary>
|
2023-09-25 07:54:18 +02:00
|
|
|
<input bind:value={customSearch} class="w-100 mb-1" />
|
2023-09-05 10:45:05 +02:00
|
|
|
<button
|
2023-09-25 08:40:11 +02:00
|
|
|
class="btn {computingWeights ? 'btn-warning' : 'btn-primary'}"
|
|
|
|
disabled={!computingWeights && computing}
|
2023-09-05 10:45:05 +02:00
|
|
|
on:click={() => computeWeights()}
|
|
|
|
>
|
2023-09-25 08:40:11 +02:00
|
|
|
{#if computingWeights}
|
2023-09-16 08:09:26 +02:00
|
|
|
{tr.actionsCancel()}
|
2023-09-05 10:45:05 +02:00
|
|
|
{:else}
|
2023-09-16 08:09:26 +02:00
|
|
|
{tr.deckConfigComputeButton()}
|
2023-09-05 10:45:05 +02:00
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
<button
|
2023-09-25 08:40:11 +02:00
|
|
|
class="btn {checkingWeights ? 'btn-warning' : 'btn-primary'}"
|
|
|
|
disabled={!checkingWeights && computing}
|
2023-09-05 10:45:05 +02:00
|
|
|
on:click={() => checkWeights()}
|
|
|
|
>
|
2023-09-25 08:40:11 +02:00
|
|
|
{#if checkingWeights}
|
2023-09-16 08:09:26 +02:00
|
|
|
{tr.actionsCancel()}
|
2023-09-05 10:45:05 +02:00
|
|
|
{:else}
|
2023-09-16 08:09:26 +02:00
|
|
|
{tr.deckConfigAnalyzeButton()}
|
2023-09-05 10:45:05 +02:00
|
|
|
{/if}
|
|
|
|
</button>
|
2023-09-26 06:02:12 +02:00
|
|
|
{#if computingWeights || checkingWeights}<div>
|
|
|
|
{computeWeightsProgressString}
|
|
|
|
</div>{/if}
|
2023-09-16 08:09:26 +02:00
|
|
|
</details>
|
|
|
|
</div>
|
2023-09-05 10:45:05 +02:00
|
|
|
|
2023-09-16 08:09:26 +02:00
|
|
|
<div class="m-2">
|
|
|
|
<details>
|
|
|
|
<summary>{tr.deckConfigComputeOptimalRetention()}</summary>
|
2023-09-05 10:45:05 +02:00
|
|
|
|
|
|
|
Deck size:
|
|
|
|
<br />
|
2023-09-18 08:43:12 +02:00
|
|
|
<input type="number" bind:value={optimalRetentionRequest.deckSize} />
|
2023-09-05 10:45:05 +02:00
|
|
|
<br />
|
|
|
|
|
|
|
|
Days to simulate
|
|
|
|
<br />
|
2023-09-18 08:43:12 +02:00
|
|
|
<input type="number" bind:value={optimalRetentionRequest.daysToSimulate} />
|
2023-09-05 10:45:05 +02:00
|
|
|
<br />
|
|
|
|
|
2023-09-25 07:54:18 +02:00
|
|
|
Target minutes of study per day:
|
2023-09-05 10:45:05 +02:00
|
|
|
<br />
|
2023-09-18 08:43:12 +02:00
|
|
|
<input
|
|
|
|
type="number"
|
2023-09-25 07:54:18 +02:00
|
|
|
bind:value={optimalRetentionRequest.maxMinutesOfStudyPerDay}
|
2023-09-18 08:43:12 +02:00
|
|
|
/>
|
2023-09-16 08:09:26 +02:00
|
|
|
<br />
|
|
|
|
|
2023-09-05 10:45:05 +02:00
|
|
|
<button
|
2023-09-25 08:40:11 +02:00
|
|
|
class="btn {computingRetention ? 'btn-warning' : 'btn-primary'}"
|
|
|
|
disabled={!computingRetention && computing}
|
2023-09-05 10:45:05 +02:00
|
|
|
on:click={() => computeRetention()}
|
|
|
|
>
|
2023-09-25 08:40:11 +02:00
|
|
|
{#if computingRetention}
|
2023-09-16 08:09:26 +02:00
|
|
|
{tr.actionsCancel()}
|
2023-09-05 10:45:05 +02:00
|
|
|
{:else}
|
2023-09-16 08:09:26 +02:00
|
|
|
{tr.deckConfigComputeButton()}
|
2023-09-05 10:45:05 +02:00
|
|
|
{/if}
|
|
|
|
</button>
|
2023-09-27 08:12:49 +02:00
|
|
|
|
|
|
|
{#if optimalRetention}
|
|
|
|
<button
|
|
|
|
class="btn {'btn-primary'}"
|
|
|
|
disabled={!optimalRetention ||
|
|
|
|
optimalRetention === $config.desiredRetention}
|
|
|
|
on:click={() => setDesiredRetentionToOptimal()}
|
|
|
|
>
|
|
|
|
{stringForSetOptimalRetention(optimalRetention)}
|
|
|
|
</button>
|
|
|
|
{/if}
|
2023-09-05 10:45:05 +02:00
|
|
|
<div>{computeRetentionProgressString}</div>
|
2023-09-16 08:09:26 +02:00
|
|
|
</details>
|
|
|
|
</div>
|
2023-09-05 10:45:05 +02:00
|
|
|
|
|
|
|
<style>
|
|
|
|
</style>
|