Relies on the git_time_extractor gem, which can be installed with gem install git git_time_extractor.
Example usage...
$ git-hours --after 06/20/2014
Lawrence Jones: 38.8hrs
| #!/usr/bin/env coffee | |
| _ = require 'underscore' | |
| spawn = (require 'child_process').spawn | |
| options = | |
| after: null | |
| before: null | |
| Array::cons = -> | |
| @[..-2].reduce ((a,c,i) => a.push [c,@[i+1]]; a), [] | |
| for pair in process.argv[2..].cons() | |
| [opt, val] = pair | |
| if (key = opt.match(/^--(\w+)$/)?[1])? and options.hasOwnProperty key | |
| options[key] = new Date val | |
| isBetween = (after, before, date) -> | |
| try date = new Date(date) | |
| catch err then return false | |
| !((after? and date < after) or | |
| (before? and date > before)) | |
| csv = '' | |
| git_time = spawn 'git_time_extractor' | |
| git_time.stdout.encoding = 'utf8' | |
| git_time.stdout.on 'data', (data) -> | |
| csv += data | |
| git_time.on 'exit', (err) -> | |
| process.exit err if err != 0 | |
| print_times process_csv csv | |
| process_csv = (csv) -> | |
| [headers, rows...] = (csv.split '\n').map (line) -> line.split ',' | |
| workers = new Object | |
| sum = rows | |
| .map (tokens) -> _.object headers, tokens | |
| .filter (record) -> | |
| isBetween(options.after, options.before, record.Date) && | |
| record.Minutes? && | |
| (record.Minutes = parseInt(record.Minutes, 10)) | |
| .map (c) -> | |
| if c.Person? | |
| workers[c.Person] = (workers[c.Person] ? 0) + c.Minutes | |
| return workers | |
| print_times = (workers) -> | |
| for own person,mins of workers | |
| console.log """ | |
| #{person}:\t#{Math.floor(mins/6)/10}hrs""" |