Skip to content

Commit 805eec6

Browse files
authored
Merge pull request #43 from pfizer-opensource/npl-fixes
Corrections for natural process limits calculations
2 parents ba2544a + f4e8499 commit 805eec6

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/graphs/control-chart/ControlRenderer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class ControlRenderer extends ScatterplotRenderer {
7777
}
7878

7979
getAvgLeadTime() {
80-
return Math.ceil(this.data.reduce((acc, curr) => acc + curr.leadTime, 0) / this.data.length);
80+
const filteredData = this.data.filter((d) => d.deliveredDate >= this.baselineStartDate && d.deliveredDate <= this.baselineEndDate);
81+
return Math.ceil(filteredData.reduce((acc, curr) => acc + curr.leadTime, 0) / filteredData.length);
8182
}
8283

8384
generateLines(chartArea, data, x, y) {
@@ -100,6 +101,7 @@ class ControlRenderer extends ScatterplotRenderer {
100101
}
101102

102103
updateGraph(domain) {
104+
this.computeGraphLimits();
103105
this.updateChartArea(domain);
104106
if (this.connectDots) {
105107
const line = d3
@@ -108,7 +110,6 @@ class ControlRenderer extends ScatterplotRenderer {
108110
.y((d) => this.applyYScale(this.currentYScale, d.leadTime));
109111
this.chartArea.selectAll('.dot-line').attr('d', line);
110112
}
111-
this.computeGraphLimits();
112113
this.drawGraphLimits(this.currentYScale);
113114
this.displayObservationMarkers(this.observations);
114115
}

src/graphs/moving-range/MovingRangeGraph.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ class MovingRangeGraph {
2626
if (this.dataSet.length <= 0) {
2727
throw new Error('Data set is empty');
2828
}
29-
return Math.ceil(
30-
this.dataSet.filter((d) => d.deliveredDate >= startDate && d.deliveredDate <= endDate).reduce((acc, curr) => acc + curr.leadTime, 0) /
31-
this.dataSet.length
32-
);
29+
const filteredData = this.dataSet.filter((d) => d.deliveredDate >= startDate && d.deliveredDate <= endDate);
30+
return Math.ceil(filteredData.reduce((acc, curr) => acc + curr.leadTime, 0) / filteredData.length);
3331
}
3432
}
3533

src/graphs/moving-range/MovingRangeRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ class MovingRangeRenderer extends ScatterplotRenderer {
8888
}
8989

9090
updateGraph(domain) {
91+
this.computeGraphLimits();
9192
this.updateChartArea(domain);
9293
const line = d3
9394
.line()
9495
.x((d) => this.currentXScale(d.deliveredDate))
9596
.y((d) => this.applyYScale(this.currentYScale, d.leadTime));
9697
this.chartArea.selectAll('.dot-line').attr('d', line);
97-
this.computeGraphLimits();
9898
this.drawGraphLimits(this.currentYScale);
9999
}
100100
}

0 commit comments

Comments
 (0)