mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00

* Update to latest Node LTS * Add sveltekit * Split tslib into separate @generated and @tslib components SvelteKit's path aliases don't support multiple locations, so our old approach of using @tslib to refer to both ts/lib and out/ts/lib will no longer work. Instead, all generated sources and their includes are placed in a separate out/ts/generated folder, and imported via @generated instead. This also allows us to generate .ts files, instead of needing to output separate .d.ts and .js files. * Switch package.json to module type * Avoid usage of baseUrl Incompatible with SvelteKit * Move sass into ts; use relative links SvelteKit's default sass support doesn't allow overriding loadPaths * jest->vitest, graphs example working with yarn dev * most pages working in dev mode * Some fixes after rebasing * Fix/silence some svelte-check errors * Get image-occlusion working with Fabric types * Post-rebase lock changes * Editor is now checked * SvelteKit build integrated into ninja * Use the new SvelteKit entrypoint for pages like congrats/deck options/etc * Run eslint once for ts/**; fix some tests * Fix a bunch of issues introduced when rebasing over latest main * Run eslint fix * Fix remaining eslint+pylint issues; tests now all pass * Fix some issues with a clean build * Latest bufbuild no longer requires @__PURE__ hack * Add a few missed dependencies * Add yarn.bat to fix Windows build * Fix pages failing to show when ANKI_API_PORT not defined * Fix svelte-check and vitest on Windows * Set node path in ./yarn * Move svelte-kit output to ts/.svelte-kit Sadly, I couldn't figure out a way to store it in out/ if out/ is a symlink, as it breaks module resolution when SvelteKit is run. * Allow HMR inside Anki * Skip SvelteKit build when HMR is defined * Fix some post-rebase issues I should have done a normal merge instead.
162 lines
5.1 KiB
Svelte
162 lines
5.1 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 * as tr2 from "@generated/ftl";
|
|
import { DAY, timeSpan, Timestamp } from "@tslib/time";
|
|
|
|
export let stats: CardStatsResponse;
|
|
|
|
function dateString(timestamp: bigint): string {
|
|
return new Timestamp(Number(timestamp)).dateString();
|
|
}
|
|
|
|
interface StatsRow {
|
|
label: string;
|
|
value: string | number | bigint;
|
|
}
|
|
|
|
function rowsFromStats(stats: CardStatsResponse): StatsRow[] {
|
|
const statsRows: StatsRow[] = [];
|
|
|
|
statsRows.push({ label: tr2.cardStatsAdded(), value: dateString(stats.added) });
|
|
|
|
if (stats.firstReview != null) {
|
|
statsRows.push({
|
|
label: tr2.cardStatsFirstReview(),
|
|
value: dateString(stats.firstReview),
|
|
});
|
|
}
|
|
if (stats.latestReview != null) {
|
|
statsRows.push({
|
|
label: tr2.cardStatsLatestReview(),
|
|
value: dateString(stats.latestReview),
|
|
});
|
|
}
|
|
|
|
if (stats.dueDate != null) {
|
|
statsRows.push({
|
|
label: tr2.statisticsDueDate(),
|
|
value: dateString(stats.dueDate),
|
|
});
|
|
}
|
|
if (stats.duePosition != null) {
|
|
statsRows.push({
|
|
label: tr2.cardStatsNewCardPosition(),
|
|
value: stats.duePosition,
|
|
});
|
|
}
|
|
|
|
if (stats.interval) {
|
|
statsRows.push({
|
|
label: tr2.cardStatsInterval(),
|
|
value: timeSpan(stats.interval * DAY),
|
|
});
|
|
}
|
|
if (stats.memoryState) {
|
|
let stability = timeSpan(stats.memoryState.stability * 86400, false, false);
|
|
if (stats.memoryState.stability > 31) {
|
|
const nativeStability = stats.memoryState.stability.toFixed(0);
|
|
stability += ` (${nativeStability})`;
|
|
}
|
|
statsRows.push({
|
|
label: tr2.cardStatsFsrsStability(),
|
|
value: stability,
|
|
});
|
|
const difficulty = (
|
|
((stats.memoryState.difficulty - 1.0) / 9.0) *
|
|
100.0
|
|
).toFixed(0);
|
|
statsRows.push({
|
|
label: tr2.cardStatsFsrsDifficulty(),
|
|
value: `${difficulty}%`,
|
|
});
|
|
if (stats.fsrsRetrievability) {
|
|
const retrievability = (stats.fsrsRetrievability * 100).toFixed(0);
|
|
statsRows.push({
|
|
label: tr2.cardStatsFsrsRetrievability(),
|
|
value: `${retrievability}%`,
|
|
});
|
|
}
|
|
} else {
|
|
if (stats.ease) {
|
|
statsRows.push({
|
|
label: tr2.cardStatsEase(),
|
|
value: `${stats.ease / 10}%`,
|
|
});
|
|
}
|
|
}
|
|
|
|
statsRows.push({ label: tr2.cardStatsReviewCount(), value: stats.reviews });
|
|
statsRows.push({ label: tr2.cardStatsLapseCount(), value: stats.lapses });
|
|
|
|
if (stats.totalSecs) {
|
|
statsRows.push({
|
|
label: tr2.cardStatsAverageTime(),
|
|
value: timeSpan(stats.averageSecs),
|
|
});
|
|
statsRows.push({
|
|
label: tr2.cardStatsTotalTime(),
|
|
value: timeSpan(stats.totalSecs),
|
|
});
|
|
}
|
|
|
|
statsRows.push({ label: tr2.cardStatsCardTemplate(), value: stats.cardType });
|
|
statsRows.push({ label: tr2.cardStatsNoteType(), value: stats.notetype });
|
|
let deck: string;
|
|
if (stats.originalDeck) {
|
|
deck = `${stats.deck} (${stats.originalDeck})`;
|
|
} else {
|
|
deck = stats.deck;
|
|
}
|
|
statsRows.push({ label: tr2.cardStatsDeckName(), value: deck });
|
|
statsRows.push({ label: tr2.cardStatsPreset(), value: stats.preset });
|
|
|
|
statsRows.push({ label: tr2.cardStatsCardId(), value: stats.cardId });
|
|
statsRows.push({ label: tr2.cardStatsNoteId(), value: stats.noteId });
|
|
|
|
if (stats.customData) {
|
|
let value: string;
|
|
try {
|
|
const obj = JSON.parse(stats.customData);
|
|
value = Object.entries(obj)
|
|
.map(([k, v]) => `${k}=${v}`)
|
|
.join(" ");
|
|
} catch (exc) {
|
|
value = stats.customData;
|
|
}
|
|
statsRows.push({
|
|
label: tr2.cardStatsCustomData(),
|
|
value: value,
|
|
});
|
|
}
|
|
|
|
return statsRows;
|
|
}
|
|
|
|
let statsRows: StatsRow[];
|
|
$: statsRows = rowsFromStats(stats);
|
|
</script>
|
|
|
|
<table class="stats-table align-start">
|
|
{#each statsRows as row}
|
|
<tr>
|
|
<th class="align-start">{row.label}</th>
|
|
<td>{row.value}</td>
|
|
</tr>
|
|
{/each}
|
|
</table>
|
|
|
|
<style>
|
|
.stats-table {
|
|
width: 100%;
|
|
border-spacing: 1em 0;
|
|
border-collapse: collapse;
|
|
}
|
|
|
|
.align-start {
|
|
text-align: start;
|
|
}
|
|
</style>
|