From fe36fa5fd99d1d2fc1a124f163cec1136775a132 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 21 Sep 2020 11:31:27 +1000 Subject: [PATCH] fix average added https://forums.ankiweb.net/t/statistics-bug-cards-added-average/3556 --- ts/src/stats/added.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ts/src/stats/added.ts b/ts/src/stats/added.ts index 5d868e345..881abf07f 100644 --- a/ts/src/stats/added.ts +++ b/ts/src/stats/added.ts @@ -7,7 +7,7 @@ */ import pb from "../backend/proto"; -import { extent, histogram, sum, mean } from "d3-array"; +import { extent, histogram, sum } from "d3-array"; import { scaleLinear, scaleSequential } from "d3-scale"; import { HistogramData } from "./histogram-graph"; import { interpolateBlues } from "d3-scale-chromatic"; @@ -74,7 +74,8 @@ export function buildHistogram( ).domain([xMax!, xMin!]); const totalInPeriod = sum(bins, (bin) => bin.length); - const cardsPerDay = Math.round(mean(bins, (bin) => bin.length) ?? 0); + const periodDays = Math.abs(xMin!); + const cardsPerDay = Math.round(totalInPeriod / periodDays); const tableData = [ { label: i18n.tr(i18n.TR.STATISTICS_TOTAL),