Compute squares.

This commit is contained in:
Ionică Bizău 2015-01-27 13:07:15 +02:00
parent 9d829d3068
commit 78082da8c8

View file

@ -7,6 +7,16 @@ var FsExtra = require("fs-extra")
// Constants
const STORE_PATH = Ul.USER_DIR + "/.git-stats"
, LEVELS = 5
, SQUARES = ["⬚", "O", "▢", "▤", "▣", "⬛"]
, DAYS = {
Sun: 0
, Mon: 1
, Tue: 2
, Wed: 3
, Thu: 4
, Fri: 5
, Sat: 6
}
;
// Constructor
@ -96,7 +106,7 @@ GitStats.iterateDays = function (data, callback) {
while (!start.isAfter(end)) {
cDay = start.format(data.format);
callback(cDay);
callback(cDay, start);
start.add(1, "days")
}
};
@ -167,10 +177,34 @@ GitStats.ansiCalendar = function (data, callback) {
callback = data;
data = undefined;
}
// ⬚ ▢ ▤ ▣ ⬛
var year = []
, cWeek = []
, sDay = ""
, cDayObj = null
;
GitStats.calendar(data, function (err, cal) {
if (err) { return callback(err); }
GitStats.iterateDays(function (cDay, mDay) {
sDay = mDay.format("ddd");
cDayObj = cal.days[cDay];
if (sDay === "Sun" && Object.keys(cWeek).length) {
year.push(cWeek);
cWeek = []
}
if (!cDayObj) return;
cWeek[DAYS[sDay]] = SQUARES[cDayObj.level];
});
if (cWeek.length) {
year.push(cWeek);
}
debugger
});
};