Skip to content

Commit

Permalink
NPL calculations corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaudiaGivan committed Oct 30, 2024
1 parent ba2544a commit f4e8499
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/graphs/control-chart/ControlRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -100,6 +101,7 @@ class ControlRenderer extends ScatterplotRenderer {
}

updateGraph(domain) {
this.computeGraphLimits();
this.updateChartArea(domain);
if (this.connectDots) {
const line = d3
Expand All @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions src/graphs/moving-range/MovingRangeGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/graphs/moving-range/MovingRangeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit f4e8499

Please sign in to comment.