IO-3017 Lifecycle NaN prevention
Signed-off-by: Allan Carr <allan.carr@thinkimex.com>
This commit is contained in:
@@ -78,10 +78,10 @@ const jobLifecycle = async (req, res) => {
|
|||||||
Object.keys(flatGroupedAllDurations).forEach((status) => {
|
Object.keys(flatGroupedAllDurations).forEach((status) => {
|
||||||
const value = flatGroupedAllDurations[status].reduce((acc, curr) => acc + curr.value, 0);
|
const value = flatGroupedAllDurations[status].reduce((acc, curr) => acc + curr.value, 0);
|
||||||
const humanReadable = durationToHumanReadable(moment.duration(value));
|
const humanReadable = durationToHumanReadable(moment.duration(value));
|
||||||
const percentage = (value / finalTotal) * 100;
|
const percentage = finalTotal > 0 ? (value / finalTotal) * 100 : 0;
|
||||||
const color = getLifecycleStatusColor(status);
|
const color = getLifecycleStatusColor(status);
|
||||||
const roundedPercentage = `${Math.round(percentage)}%`;
|
const roundedPercentage = `${Math.round(percentage)}%`;
|
||||||
const averageValue = value / jobIDs.length;
|
const averageValue = _size(jobIDs) > 0 ? value / jobIDs.length : 0;
|
||||||
const averageHumanReadable = durationToHumanReadable(moment.duration(averageValue));
|
const averageHumanReadable = durationToHumanReadable(moment.duration(averageValue));
|
||||||
finalSummations.push({
|
finalSummations.push({
|
||||||
status,
|
status,
|
||||||
@@ -105,8 +105,11 @@ const jobLifecycle = async (req, res) => {
|
|||||||
total: finalTotal,
|
total: finalTotal,
|
||||||
statusCounts: finalStatusCounts,
|
statusCounts: finalStatusCounts,
|
||||||
humanReadable: durationToHumanReadable(moment.duration(finalTotal)),
|
humanReadable: durationToHumanReadable(moment.duration(finalTotal)),
|
||||||
averageValue: finalTotal / jobIDs.length,
|
averageValue: _size(jobIDs) > 0 ? finalTotal / jobIDs.length : 0,
|
||||||
averageHumanReadable: durationToHumanReadable(moment.duration(finalTotal / jobIDs.length))
|
averageHumanReadable:
|
||||||
|
_size(jobIDs) > 0
|
||||||
|
? durationToHumanReadable(moment.duration(finalTotal / jobIDs.length))
|
||||||
|
: durationToHumanReadable(moment.duration(0))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user