Skip to content

Instantly share code, notes, and snippets.

@jerryzhang222
Created March 31, 2017 04:27
Show Gist options
  • Save jerryzhang222/518c52a3cf84c384a813166b9cd4da98 to your computer and use it in GitHub Desktop.
Save jerryzhang222/518c52a3cf84c384a813166b9cd4da98 to your computer and use it in GitHub Desktop.
sad
get() {
const stepName = this.get('stepName');
console.log(this.get('estimateTime'));
const estimateTime = new Promise((resolve, reject) => {
this.get('estimateTime').then((builds) => {
let durations = [];
builds.forEach((build) => {
const steps = build.get('steps');
durations.push(steps.map((step) => {
if (step.name === stepName) {
const start = step.startTime;
const end = step.endTime;
if (end && start) {
return Date.parse(end) - Date.parse(start);
}
}
return null;
}));
});
const flattenedDurations = [].concat.apply([], durations);
const filteredDurations = flattenedDurations.filter(val => val !== null);
const sum = filteredDurations.reduce((a, b) => a + b);
return sum / filteredDurations.length;
}).then((averageTime) => {
if (averageTime) {
console.log(humanizeDuration(averageTime, { round: true, largest: 2 }));
resolve(humanizeDuration(averageTime, { round: true, largest: 2 }));
}
return reject();
});
});
return estimateTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment