diff --git a/lib/index.js b/lib/index.js index d81dc39..512afea 100644 --- a/lib/index.js +++ b/lib/index.js @@ -48,7 +48,7 @@ GitStats.record = function (data, callback) { // Get stats GitStats.get(function (err, stats) { stats = stats || {}; - var day = data.date.format("MMM DDD, YYYY") + var day = data.date.format("MMM D, YYYY") , today = stats[day] = Object(stats[day]) , repo = today[data.url] = Object(today[data.url]) ; @@ -76,3 +76,32 @@ GitStats.get = function (data, callback) { } FsExtra.readJSON(STORE_PATH, callback); }; + +GitStats.graph = function (data, callback) { + GitStats.get(data, function (err, stats) { + if (err) { return callback(err); } + var year = {} + , end = Moment() + , start = Moment().subtract({ years: 1 }) + , cDay = null + , cDayObj = null + ; + + while (!(start > end)) { + cDay = start.format("MMM D, YYYY"); + cDayObj = year[cDay] = { + _: stats[cDay] || {} + , c: 0 + }; + + Object.keys(cDayObj._).forEach(function (c) { + cDayObj.c += Object.keys(cDayObj._[c]).length; + }); + + start.add(1, "days") + } + + callback(null, year); + // ⬚ ▢ ▤ ▣ ⬛ + }); +};