dont clear points on mode swap

This commit is contained in:
Luc Mcgrady 2025-07-13 21:04:54 +01:00
parent b9b39452cb
commit fc89efb1d9
No known key found for this signature in database
GPG key ID: 4F3D7A0B17CC3D9C

View file

@ -64,7 +64,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let svg: HTMLElement | SVGElement | null = null; let svg: HTMLElement | SVGElement | null = null;
let simulationNumber = 0; let simulationNumber = 0;
let workloadSimulationNumber = 0;
let points: Point[] = []; let points: Point[] = [];
let workloadPoints: Point[] = [];
const newCardsIgnoreReviewLimit = state.newCardsIgnoreReviewLimit; const newCardsIgnoreReviewLimit = state.newCardsIgnoreReviewLimit;
let smooth = true; let smooth = true;
let suspendLeeches = $config.leechAction == DeckConfig_Config_LeechAction.SUSPEND; let suspendLeeches = $config.leechAction == DeckConfig_Config_LeechAction.SUSPEND;
@ -78,6 +80,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: deckSize = 0; $: deckSize = 0;
$: windowSize = Math.ceil(daysToSimulate / 365); $: windowSize = Math.ceil(daysToSimulate / 365);
$: processing = simulating || computingRetention; $: processing = simulating || computingRetention;
$: currentPoints = workload ? workloadPoints : points;
$: currentSimulationNumber = workload ? workloadSimulationNumber : simulationNumber;
function movingAverage(y: number[], windowSize: number): number[] { function movingAverage(y: number[], windowSize: number): number[] {
const result: number[] = []; const result: number[] = [];
@ -163,8 +167,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} finally { } finally {
simulating = false; simulating = false;
if (resp) { if (resp) {
// Clear the graph if transitioning from workload to simulation
simulationNumber += 1; simulationNumber += 1;
const dailyTotalCount = addArrays( const dailyTotalCount = addArrays(
resp.dailyReviewCount, resp.dailyReviewCount,
@ -207,22 +209,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} finally { } finally {
simulating = false; simulating = false;
if (resp) { if (resp) {
simulationNumber += 1; workloadSimulationNumber += 1;
points = points.concat( workloadPoints = workloadPoints.concat(
Object.entries(resp.memorized).map(([dr, v]) => ({ Object.entries(resp.memorized).map(([dr, v]) => ({
x: parseInt(dr), x: parseInt(dr),
timeCost: resp!.cost[dr], timeCost: resp!.cost[dr],
memorized: v, memorized: v,
count: -1, count: -1,
label: simulationNumber, label: workloadSimulationNumber,
})), })),
); );
tableData = renderWorkloadChart( tableData = renderWorkloadChart(
svg as SVGElement, svg as SVGElement,
bounds, bounds,
points, workloadPoints,
simulateWorkloadSubgraph, simulateWorkloadSubgraph,
); );
} }
@ -230,12 +232,21 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
function clearSimulation() { function clearSimulation() {
points = points.filter((p) => p.label !== simulationNumber); const newPoints = currentPoints.filter(
simulationNumber = Math.max(0, simulationNumber - 1); (p) => p.label !== currentSimulationNumber,
);
const newSimulationNumber = Math.max(0, currentSimulationNumber - 1);
if (workload) {
workloadPoints = newPoints;
workloadSimulationNumber = newSimulationNumber;
} else {
points = newPoints;
simulationNumber = newSimulationNumber;
}
tableData = renderSimulationChart( tableData = renderSimulationChart(
svg as SVGElement, svg as SVGElement,
bounds, bounds,
points, newPoints,
simulateSubgraph, simulateSubgraph,
); );
} }
@ -260,16 +271,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
function switchModes() { function switchModes() {
points = [];
simulationNumber = 0;
workload = !workload; workload = !workload;
} }
$: if (svg) { $: if (svg) {
let pointsToRender = points; let pointsToRender = currentPoints;
if (smooth) { if (smooth) {
// Group points by label (simulation number) // Group points by label (simulation number)
const groupedPoints = points.reduce( const groupedPoints = currentPoints.reduce(
(acc, point) => { (acc, point) => {
acc[point.label] = acc[point.label] || []; acc[point.label] = acc[point.label] || [];
acc[point.label].push(point); acc[point.label].push(point);