mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 13:22:11 +01:00
Added the graph method.
This commit is contained in:
parent
10d571fa63
commit
dd5d500f0c
1 changed files with 30 additions and 1 deletions
31
lib/index.js
31
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);
|
||||
// ⬚ ▢ ▤ ▣ ⬛
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue