FIX: ensures average is applied on last incomplete segment (#13472)
This commit is contained in:
parent
fa470cf6fe
commit
1a6759a5d9
|
@ -506,6 +506,11 @@ const Report = EmberObject.extend({
|
||||||
export const WEEKLY_LIMIT_DAYS = 365;
|
export const WEEKLY_LIMIT_DAYS = 365;
|
||||||
export const DAILY_LIMIT_DAYS = 34;
|
export const DAILY_LIMIT_DAYS = 34;
|
||||||
|
|
||||||
|
function applyAverage(value, start, end) {
|
||||||
|
const count = end.diff(start, "day") + 1; // 1 to include start
|
||||||
|
return parseFloat((value / count).toFixed(2));
|
||||||
|
}
|
||||||
|
|
||||||
Report.reopenClass({
|
Report.reopenClass({
|
||||||
groupingForDatapoints(count) {
|
groupingForDatapoints(count) {
|
||||||
if (count < DAILY_LIMIT_DAYS) {
|
if (count < DAILY_LIMIT_DAYS) {
|
||||||
|
@ -562,6 +567,7 @@ Report.reopenClass({
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let appliedAverage = false;
|
||||||
data.forEach((d) => {
|
data.forEach((d) => {
|
||||||
const date = moment(d.x, "YYYY-MM-DD");
|
const date = moment(d.x, "YYYY-MM-DD");
|
||||||
|
|
||||||
|
@ -570,15 +576,20 @@ Report.reopenClass({
|
||||||
!date.isBetween(currentStart, currentEnd)
|
!date.isBetween(currentStart, currentEnd)
|
||||||
) {
|
) {
|
||||||
if (model.average) {
|
if (model.average) {
|
||||||
const days = currentEnd.diff(currentStart, "day") + 1; // 1 to include start
|
transformedData[currentIndex].y = applyAverage(
|
||||||
transformedData[currentIndex].y = parseFloat(
|
transformedData[currentIndex].y,
|
||||||
(transformedData[currentIndex].y / days).toFixed(2)
|
currentStart,
|
||||||
|
currentEnd
|
||||||
);
|
);
|
||||||
|
|
||||||
|
appliedAverage = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentIndex += 1;
|
currentIndex += 1;
|
||||||
currentStart = currentStart.add(1, kind).startOf(isoKind);
|
currentStart = currentStart.add(1, kind).startOf(isoKind);
|
||||||
currentEnd = currentEnd.add(1, kind).endOf(isoKind);
|
currentEnd = currentEnd.add(1, kind).endOf(isoKind);
|
||||||
|
} else {
|
||||||
|
appliedAverage = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transformedData[currentIndex]) {
|
if (transformedData[currentIndex]) {
|
||||||
|
@ -591,6 +602,14 @@ Report.reopenClass({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (model.average && !appliedAverage) {
|
||||||
|
transformedData[currentIndex].y = applyAverage(
|
||||||
|
transformedData[currentIndex].y,
|
||||||
|
currentStart,
|
||||||
|
moment(model.end_date).subtract(1, "day") // remove 1 day as model end date is at 00:00 of next day
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return transformedData;
|
return transformedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue