From f4e8499b5bc8ebabf2251fb8606b62ff6f096076 Mon Sep 17 00:00:00 2001 From: ClaudiaGivan Date: Wed, 30 Oct 2024 10:16:11 +0100 Subject: [PATCH] NPL calculations corrections --- src/graphs/control-chart/ControlRenderer.js | 5 +++-- src/graphs/moving-range/MovingRangeGraph.js | 6 ++---- src/graphs/moving-range/MovingRangeRenderer.js | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/graphs/control-chart/ControlRenderer.js b/src/graphs/control-chart/ControlRenderer.js index 78ed6a3..30736fd 100644 --- a/src/graphs/control-chart/ControlRenderer.js +++ b/src/graphs/control-chart/ControlRenderer.js @@ -77,7 +77,8 @@ class ControlRenderer extends ScatterplotRenderer { } getAvgLeadTime() { - return Math.ceil(this.data.reduce((acc, curr) => acc + curr.leadTime, 0) / this.data.length); + const filteredData = this.data.filter((d) => d.deliveredDate >= this.baselineStartDate && d.deliveredDate <= this.baselineEndDate); + return Math.ceil(filteredData.reduce((acc, curr) => acc + curr.leadTime, 0) / filteredData.length); } generateLines(chartArea, data, x, y) { @@ -100,6 +101,7 @@ class ControlRenderer extends ScatterplotRenderer { } updateGraph(domain) { + this.computeGraphLimits(); this.updateChartArea(domain); if (this.connectDots) { const line = d3 @@ -108,7 +110,6 @@ class ControlRenderer extends ScatterplotRenderer { .y((d) => this.applyYScale(this.currentYScale, d.leadTime)); this.chartArea.selectAll('.dot-line').attr('d', line); } - this.computeGraphLimits(); this.drawGraphLimits(this.currentYScale); this.displayObservationMarkers(this.observations); } diff --git a/src/graphs/moving-range/MovingRangeGraph.js b/src/graphs/moving-range/MovingRangeGraph.js index fe20b0a..d6fae0c 100644 --- a/src/graphs/moving-range/MovingRangeGraph.js +++ b/src/graphs/moving-range/MovingRangeGraph.js @@ -26,10 +26,8 @@ class MovingRangeGraph { if (this.dataSet.length <= 0) { throw new Error('Data set is empty'); } - return Math.ceil( - this.dataSet.filter((d) => d.deliveredDate >= startDate && d.deliveredDate <= endDate).reduce((acc, curr) => acc + curr.leadTime, 0) / - this.dataSet.length - ); + const filteredData = this.dataSet.filter((d) => d.deliveredDate >= startDate && d.deliveredDate <= endDate); + return Math.ceil(filteredData.reduce((acc, curr) => acc + curr.leadTime, 0) / filteredData.length); } } diff --git a/src/graphs/moving-range/MovingRangeRenderer.js b/src/graphs/moving-range/MovingRangeRenderer.js index 096da66..7b733b8 100644 --- a/src/graphs/moving-range/MovingRangeRenderer.js +++ b/src/graphs/moving-range/MovingRangeRenderer.js @@ -88,13 +88,13 @@ class MovingRangeRenderer extends ScatterplotRenderer { } updateGraph(domain) { + this.computeGraphLimits(); this.updateChartArea(domain); const line = d3 .line() .x((d) => this.currentXScale(d.deliveredDate)) .y((d) => this.applyYScale(this.currentYScale, d.leadTime)); this.chartArea.selectAll('.dot-line').attr('d', line); - this.computeGraphLimits(); this.drawGraphLimits(this.currentYScale); } }