mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
Fix/dataPoint index is off by one day in simulator & remove moving average (#3645)
* Fix/dataPoint index is off by one day in simulator * remove movingAverage
This commit is contained in:
parent
69e699dc13
commit
abef3f39ca
2 changed files with 6 additions and 24 deletions
|
@ -299,20 +299,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
let points: Point[] = [];
|
let points: Point[] = [];
|
||||||
|
|
||||||
function movingAverage(y: number[], windowSize: number): number[] {
|
|
||||||
const result: number[] = [];
|
|
||||||
for (let i = 0; i < y.length; i++) {
|
|
||||||
let sum = 0;
|
|
||||||
let count = 0;
|
|
||||||
for (let j = Math.max(0, i - windowSize + 1); j <= i; j++) {
|
|
||||||
sum += y[j];
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
result.push(sum / count);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addArrays(arr1: number[], arr2: number[]): number[] {
|
function addArrays(arr1: number[], arr2: number[]): number[] {
|
||||||
return arr1.map((value, index) => value + arr2[index]);
|
return arr1.map((value, index) => value + arr2[index]);
|
||||||
}
|
}
|
||||||
|
@ -336,19 +322,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
} finally {
|
} finally {
|
||||||
simulateProgressString = "";
|
simulateProgressString = "";
|
||||||
if (resp) {
|
if (resp) {
|
||||||
const dailyTimeCost = movingAverage(
|
const dailyTotalCount = addArrays(
|
||||||
resp.dailyTimeCost,
|
resp.dailyReviewCount,
|
||||||
Math.ceil(simulateFsrsRequest.daysToSimulate / 50),
|
resp.dailyNewCount,
|
||||||
);
|
|
||||||
const dailyReviewCount = movingAverage(
|
|
||||||
addArrays(resp.dailyReviewCount, resp.dailyNewCount),
|
|
||||||
Math.ceil(simulateFsrsRequest.daysToSimulate / 50),
|
|
||||||
);
|
);
|
||||||
points = points.concat(
|
points = points.concat(
|
||||||
dailyTimeCost.map((v, i) => ({
|
resp.dailyTimeCost.map((v, i) => ({
|
||||||
x: i,
|
x: i,
|
||||||
timeCost: v,
|
timeCost: v,
|
||||||
count: dailyReviewCount[i],
|
count: dailyTotalCount[i],
|
||||||
label: simulationNumber,
|
label: simulationNumber,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
|
@ -157,7 +157,7 @@ export function renderSimulationChart(
|
||||||
groups.forEach((groupPoints, key) => {
|
groups.forEach((groupPoints, key) => {
|
||||||
const bisect = bisector((d: number[]) => x.invert(d[0])).left;
|
const bisect = bisector((d: number[]) => x.invert(d[0])).left;
|
||||||
const index = bisect(groupPoints, date);
|
const index = bisect(groupPoints, date);
|
||||||
const dataPoint = groupPoints[index - 1] || groupPoints[index];
|
const dataPoint = groupPoints[index];
|
||||||
|
|
||||||
if (dataPoint) {
|
if (dataPoint) {
|
||||||
groupData[key] = y.invert(dataPoint[1]);
|
groupData[key] = y.invert(dataPoint[1]);
|
||||||
|
|
Loading…
Reference in a new issue