Anki/ts/routes/card-info/CardInfo.svelte
Jarrett Ye e096c462fa
Feat/FSRS-6 (#3929)
* Feat/FSRS-6

* update comment

* add decay to Card

* ./ninja fix:minilints

* pass check

* fix NaN in evaluation

* remove console

* decay should fallback to 0.5 when it's None.

* Update SimulatorModal.svelte

* Update a few comments

* Update FSRS decay defaults to use constants for better maintainability and clarity

* Update rslib/src/storage/card/data.rs
2025-04-25 16:44:34 +10:00

52 lines
1.6 KiB
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import type { CardStatsResponse } from "@generated/anki/stats_pb";
import Container from "$lib/components/Container.svelte";
import Row from "$lib/components/Row.svelte";
import CardInfoPlaceholder from "./CardInfoPlaceholder.svelte";
import CardStats from "./CardStats.svelte";
import Revlog from "./Revlog.svelte";
import ForgettingCurve from "./ForgettingCurve.svelte";
export let stats: CardStatsResponse | null = null;
export let showRevlog: boolean = true;
$: fsrsEnabled = stats?.memoryState != null;
$: desiredRetention = stats?.desiredRetention ?? 0.9;
$: decay = (() => {
const paramsLength = stats?.fsrsParams?.length ?? 0;
if (paramsLength === 0) {
return 0.2; // default decay for FSRS-6
}
if (paramsLength < 21) {
return 0.5; // default decay for FSRS-4.5 and FSRS-5
}
return stats?.fsrsParams?.[20] ?? 0.2;
})();
</script>
<Container breakpoint="md" --gutter-inline="1rem" --gutter-block="0.5rem">
{#if stats}
<Row>
<CardStats {stats} />
</Row>
{#if showRevlog}
<Row>
<Revlog revlog={stats.revlog} {fsrsEnabled} />
</Row>
{/if}
{#if fsrsEnabled}
<Row>
<ForgettingCurve revlog={stats.revlog} {desiredRetention} {decay} />
</Row>
{/if}
{:else}
<CardInfoPlaceholder />
{/if}
</Container>