Merge branch 'master-beta' into master-AIO
This commit is contained in:
@@ -1,15 +1,7 @@
|
||||
const durationToHumanReadable = require("./durationToHumanReadable");
|
||||
const moment = require("moment");
|
||||
const getLifecycleStatusColor = require("./getLifecycleStatusColor");
|
||||
const _ = require("lodash");
|
||||
const crypto = require('crypto');
|
||||
|
||||
const getColor = (key) => {
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(key);
|
||||
const hashedKey = hash.digest('hex');
|
||||
const num = parseInt(hashedKey, 16);
|
||||
return '#' + (num % 16777215).toString(16).padStart(6, '0');
|
||||
};
|
||||
|
||||
const calculateStatusDuration = (transitions, statuses) => {
|
||||
let statusDuration = {};
|
||||
@@ -33,26 +25,16 @@ const calculateStatusDuration = (transitions, statuses) => {
|
||||
if (!transition.prev_value) {
|
||||
statusDuration[transition.value] = {
|
||||
value: duration,
|
||||
humanReadable: transition.duration_readable
|
||||
humanReadable: durationToHumanReadable(moment.duration(duration))
|
||||
};
|
||||
} else if (!transition.next_value) {
|
||||
} else {
|
||||
if (statusDuration[transition.value]) {
|
||||
statusDuration[transition.value].value += duration;
|
||||
statusDuration[transition.value].humanReadable = transition.duration_readable;
|
||||
statusDuration[transition.value].humanReadable = durationToHumanReadable(moment.duration(statusDuration[transition.value].value));
|
||||
} else {
|
||||
statusDuration[transition.value] = {
|
||||
value: duration,
|
||||
humanReadable: transition.duration_readable
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (statusDuration[transition.value]) {
|
||||
statusDuration[transition.value].value += duration;
|
||||
statusDuration[transition.value].humanReadable = transition.duration_readable;
|
||||
} else {
|
||||
statusDuration[transition.value] = {
|
||||
value: duration,
|
||||
humanReadable: transition.duration_readable
|
||||
humanReadable: durationToHumanReadable(moment.duration(duration))
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -79,7 +61,7 @@ const calculateStatusDuration = (transitions, statuses) => {
|
||||
value,
|
||||
humanReadable,
|
||||
percentage: statusDuration[status].percentage,
|
||||
color: getColor(status),
|
||||
color: getLifecycleStatusColor(status),
|
||||
roundedPercentage: `${Math.round(statusDuration[status].percentage)}%`
|
||||
});
|
||||
}
|
||||
|
||||
11
server/utils/getLifecycleStatusColor.js
Normal file
11
server/utils/getLifecycleStatusColor.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const crypto = require('crypto');
|
||||
|
||||
const getLifecycleStatusColor = (key) => {
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(key);
|
||||
const hashedKey = hash.digest('hex');
|
||||
const num = parseInt(hashedKey, 16);
|
||||
return '#' + (num % 16777215).toString(16).padStart(6, '0');
|
||||
};
|
||||
|
||||
module.exports = getLifecycleStatusColor;
|
||||
Reference in New Issue
Block a user