mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Tweak how the True Retention stats table displays numbers (#3677)
* Tweak how the True Retention stats table displays numbers - Always show fractional parts of numbers even if they are 0 (91.0% not 91%). - Show "N/A" for percentages instead of 0% when there are 0 total reviews. * Localise percentages correctly
This commit is contained in:
parent
91b3740554
commit
9877e22fd2
3 changed files with 15 additions and 5 deletions
|
@ -106,6 +106,7 @@ statistics-true-retention-week = Last week
|
|||
statistics-true-retention-month = Last month
|
||||
statistics-true-retention-year = Last year
|
||||
statistics-true-retention-all-time = All time
|
||||
statistics-true-retention-not-applicable = N/A
|
||||
statistics-range-all-time = all
|
||||
statistics-range-1-year-history = last 12 months
|
||||
statistics-range-all-history = all history
|
||||
|
|
|
@ -55,6 +55,10 @@ export function localizedNumber(n: number, precision = 2): string {
|
|||
return rounded.toLocaleString(langs);
|
||||
}
|
||||
|
||||
export function createLocaleNumberFormat(options?: Intl.NumberFormatOptions): Intl.NumberFormat {
|
||||
return new Intl.NumberFormat(langs, options);
|
||||
}
|
||||
|
||||
export function localeCompare(
|
||||
first: string,
|
||||
second: string,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
import * as tr from "@generated/ftl";
|
||||
import { localizedNumber } from "@tslib/i18n";
|
||||
import { createLocaleNumberFormat } from "@tslib/i18n";
|
||||
import { assertUnreachable } from "@tslib/typing";
|
||||
import { RevlogRange } from "./graph-helpers";
|
||||
|
||||
|
@ -106,12 +106,17 @@ export function calculateRetentionPercentageString(
|
|||
passed: number,
|
||||
failed: number,
|
||||
): string {
|
||||
let percentage = 0;
|
||||
const total = passed + failed;
|
||||
|
||||
if (total !== 0) {
|
||||
percentage = (passed / total) * 100;
|
||||
if (total === 0) {
|
||||
return tr.statisticsTrueRetentionNotApplicable();
|
||||
}
|
||||
|
||||
return localizedNumber(percentage, 1) + "%";
|
||||
const numberFormat = createLocaleNumberFormat({
|
||||
minimumFractionDigits: 1,
|
||||
maximumFractionDigits: 1,
|
||||
style: "percent",
|
||||
});
|
||||
|
||||
return numberFormat.format(passed / total);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue