mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2025-01-03 10:22:11 +01:00
Better algorithm to calculate the level
This commit is contained in:
parent
34d48dcb6a
commit
2c7516f3d4
1 changed files with 16 additions and 14 deletions
30
lib/index.js
30
lib/index.js
|
@ -2,28 +2,18 @@
|
||||||
var FsExtra = require("fs-extra")
|
var FsExtra = require("fs-extra")
|
||||||
, Ul = require("ul")
|
, Ul = require("ul")
|
||||||
, Moment = require("moment")
|
, Moment = require("moment")
|
||||||
, Couleurs = require("couleurs")()
|
|
||||||
, CliBox = require("cli-box")
|
, CliBox = require("cli-box")
|
||||||
;
|
;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const STORE_PATH = Ul.USER_DIR + "/.git-stats"
|
const STORE_PATH = Ul.USER_DIR + "/.git-stats"
|
||||||
, LEVELS = 5
|
, LEVELS = 5
|
||||||
, SQUARES = process.argv.indexOf("--no-ansi") !== -1 ? [
|
, SQUARES = [
|
||||||
"⬚"
|
"⬚"
|
||||||
, "▢"
|
, "▢"
|
||||||
, "▢"
|
|
||||||
, "▤"
|
, "▤"
|
||||||
, "▣"
|
, "▣"
|
||||||
, "⬛"
|
, "⬛"
|
||||||
] : [
|
|
||||||
Couleurs.fg("⬚", "#eee")
|
|
||||||
, Couleurs.fg("▢", "#eee")
|
|
||||||
, Couleurs.fg("▢", "#d6e685")
|
|
||||||
, Couleurs.fg("▤", "#8cc665")
|
|
||||||
, Couleurs.fg("▤", "#8cc665")
|
|
||||||
, Couleurs.fg("▣", "#44a340")
|
|
||||||
, Couleurs.fg("▣", "#1e6823")
|
|
||||||
]
|
]
|
||||||
, DAYS = [
|
, DAYS = [
|
||||||
"Sun"
|
"Sun"
|
||||||
|
@ -119,10 +109,12 @@ GitStats.iterateDays = function (data, callback) {
|
||||||
|
|
||||||
var start = data.start
|
var start = data.start
|
||||||
, end = data.end
|
, end = data.end
|
||||||
|
, tomrrow = Moment(end.format(DATE_FORMAT), DATE_FORMAT).add(1, "days")
|
||||||
|
, endStr = tomrrow.format(DATE_FORMAT)
|
||||||
, cDay = null
|
, cDay = null
|
||||||
;
|
;
|
||||||
|
|
||||||
while (start.format(DATE_FORMAT) !== end.format(DATE_FORMAT)) {
|
while (start.format(DATE_FORMAT) !== endStr) {
|
||||||
cDay = start.format(data.format);
|
cDay = start.format(data.format);
|
||||||
callback(cDay, start);
|
callback(cDay, start);
|
||||||
start.add(1, "days")
|
start.add(1, "days")
|
||||||
|
@ -163,10 +155,13 @@ GitStats.graph = function (data, callback) {
|
||||||
GitStats.calendar = function (data, callback) {
|
GitStats.calendar = function (data, callback) {
|
||||||
GitStats.graph(data, function (err, graph) {
|
GitStats.graph(data, function (err, graph) {
|
||||||
if (err) { return callback(err); }
|
if (err) { return callback(err); }
|
||||||
|
|
||||||
var cal = { total: 0, days: {}, cStreak: 0, lStreak: 0 }
|
var cal = { total: 0, days: {}, cStreak: 0, lStreak: 0 }
|
||||||
, cDay = null
|
, cDay = null
|
||||||
, days = Object.keys(graph)
|
, days = Object.keys(graph)
|
||||||
, max = 0
|
, max = 0
|
||||||
|
, levels = null
|
||||||
|
, cLevel = 0
|
||||||
;
|
;
|
||||||
|
|
||||||
days.forEach(function (c) {
|
days.forEach(function (c) {
|
||||||
|
@ -185,11 +180,15 @@ GitStats.calendar = function (data, callback) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
levels = max / LEVELS;
|
||||||
|
|
||||||
days.forEach(function (c) {
|
days.forEach(function (c) {
|
||||||
cDay = graph[c];
|
cDay = graph[c];
|
||||||
cal.days[c] = {
|
cal.days[c] = {
|
||||||
c: cDay.c
|
c: cDay.c
|
||||||
, level: cDay.c === 0 ? 0 : LEVELS - Math.floor(max / (cDay.c + 2))
|
, level: !levels
|
||||||
|
? 0 : (cLevel = Math.floor(cDay.c / levels)) >= 5
|
||||||
|
? 4 : !cLevel && cDay.c > 0 ? 1 : cLevel
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -218,13 +217,16 @@ GitStats.ansiCalendar = function (data, callback) {
|
||||||
GitStats.iterateDays(function (cDay, mDay) {
|
GitStats.iterateDays(function (cDay, mDay) {
|
||||||
sDay = mDay.format("ddd");
|
sDay = mDay.format("ddd");
|
||||||
cDayObj = cal.days[cDay];
|
cDayObj = cal.days[cDay];
|
||||||
|
if (!cDayObj) return;
|
||||||
|
|
||||||
if (sDay === "Sun" && Object.keys(cWeek).length) {
|
if (sDay === "Sun" && Object.keys(cWeek).length) {
|
||||||
year.push(cWeek);
|
year.push(cWeek);
|
||||||
cWeek = [" ", " ", " ", " ", " ", " ", " "];
|
cWeek = [" ", " ", " ", " ", " ", " ", " "];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cDayObj) return;
|
if (!SQUARES[cDayObj.level]) {
|
||||||
|
debugger
|
||||||
|
}
|
||||||
|
|
||||||
cWeek[DAYS.indexOf(sDay)] = SQUARES[cDayObj.level];
|
cWeek[DAYS.indexOf(sDay)] = SQUARES[cDayObj.level];
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue