Added the graph method.

This commit is contained in:
Ionică Bizău 2015-01-26 11:27:48 +02:00
parent 10d571fa63
commit dd5d500f0c

View file

@ -48,7 +48,7 @@ GitStats.record = function (data, callback) {
// Get stats // Get stats
GitStats.get(function (err, stats) { GitStats.get(function (err, stats) {
stats = 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]) , today = stats[day] = Object(stats[day])
, repo = today[data.url] = Object(today[data.url]) , repo = today[data.url] = Object(today[data.url])
; ;
@ -76,3 +76,32 @@ GitStats.get = function (data, callback) {
} }
FsExtra.readJSON(STORE_PATH, 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);
// ⬚ ▢ ▤ ▣ ⬛
});
};