diff options
author | Kimmo Brunfeldt <kimmobrunfeldt@gmail.com> | 2015-07-24 12:38:41 +0300 |
---|---|---|
committer | Kimmo Brunfeldt <kimmobrunfeldt@gmail.com> | 2015-07-24 12:38:41 +0300 |
commit | 8aaeee237cb9d9028e7a2592a25ad8468b1f45e4 (patch) | |
tree | 70f14f0b28814d2f5931754ba8451e293777cbee | |
parent | d4a95d8430b9da20b900162d657775855b24fec0 (diff) | |
download | git-hours-8aaeee237cb9d9028e7a2592a25ad8468b1f45e4.zip git-hours-8aaeee237cb9d9028e7a2592a25ad8468b1f45e4.tar.gz git-hours-8aaeee237cb9d9028e7a2592a25ad8468b1f45e4.tar.bz2 |
Sort output based on working hours
-rwxr-xr-x | index.js | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -23,28 +23,36 @@ function main() { config = mergeDefaultsWithArgs(config); commits('.').then(function(commits) { - var work = {}; - var commitsByEmail = _.groupBy(commits, function(commit) { return commit.author.email || 'unknown'; }); - _.each(commitsByEmail, function(authorCommits, authorEmail) { - work[authorEmail] = { + var authorWorks = _.map(commitsByEmail, function(authorCommits, authorEmail) { + return { + email: authorEmail, name: authorCommits[0].author.name, hours: estimateHours(_.pluck(authorCommits, 'date')), commits: authorCommits.length }; }); - var totalHours = _.reduce(work, function(sum, authorWork) { + // XXX: This relies on the implementation detail that json is printed + // in the same order as the keys were added. This is anyway just for + // making the output easier to read, so it doesn't matter if it + // isn't sorted in some cases. + var sortedWork = {}; + _.each(_.sortBy(authorWorks, 'hours'), function(authorWork) { + sortedWork[authorWork.email] = _.omit(authorWork, 'email'); + }); + + var totalHours = _.reduce(sortedWork, function(sum, authorWork) { return sum + authorWork.hours; }, 0); - work.total = { + sortedWork.total = { hours: totalHours, commits: commits.length }; - console.log(JSON.stringify(work, undefined, 2)); + console.log(JSON.stringify(sortedWork, undefined, 2)); }).catch(function(e) { console.error(e.stack); }); |