Created
March 31, 2017 04:27
-
-
Save jerryzhang222/518c52a3cf84c384a813166b9cd4da98 to your computer and use it in GitHub Desktop.
sad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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