diff --git a/.gitignore b/.gitignore index 5c2b9e2..0a9aadd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env .DS_Store node_modules +storage diff --git a/care.js b/care.js index d01afcb..f316c8e 100755 --- a/care.js +++ b/care.js @@ -341,8 +341,27 @@ var pomodoroHandlers = { } var content = `In Pomodoro Mode: ${remainingTime} ${statusText}`; - var metaData = `Duration: ${pomodoroObject.getRunningDuration()} Minutes, Break Time: ${pomodoroObject.getBreakDuration()} Minutes\n`; - metaData += 'commands: \n s - start/pause/resume \n e - stop \n u - update duration \n b - update break time'; + var pomodoroHistory = { + today: pomodoroObject.getHistory('day'), + week: pomodoroObject.getHistory('week'), + month: pomodoroObject.getHistory('month'), + } + + var metaData = ` + Duration: ${pomodoroObject.getRunningDuration()}m, Break Time: ${pomodoroObject.getBreakDuration()}m, + + Total Pomodoros Run: + Today : ${pomodoroHistory.today.count} [${pomodoroHistory.today.duration}] + This Week : ${pomodoroHistory.week.count} [${pomodoroHistory.week.duration}] + This Month : ${pomodoroHistory.month.count} [${pomodoroHistory.month.duration}] + + commands: + s - start/pause/resume + e - stop + u - update duration + b - update break time + `; + metaData.replace(/(\r?\n|\r)\s+/gm, '\n'); parrotBox.content = getAnsiArt(content) + metaData; screen.render(); }, diff --git a/package.json b/package.json index 5fe5f48..0c643b2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,9 @@ "git-user-name": "^1.2.0", "gitlog": "^2.4.0", "is-git": "0.0.1", + "moment": "^2.18.1", "node-notifier": "^5.1.2", + "node-storage": "0.0.7", "resolve-dir": "^1.0.0", "scraperjs": "^1.2.0", "sign-bunny": "^1.0.0", diff --git a/pomodoro.js b/pomodoro.js index fe5b94a..63a984e 100644 --- a/pomodoro.js +++ b/pomodoro.js @@ -1,3 +1,6 @@ +var Storage = require('node-storage'); +var moment = require('moment'); +var store = new Storage(__dirname + '/storage/pomodoro.json'); var States = { RUNNING: 'running', @@ -34,6 +37,8 @@ var pomodoro = function(options) { _breakDurationRemaining = _breakDuration * 60; _currentState = States.IN_BREAK options.onBreakStarts && options.onBreakStarts(); + pomodoroStorage.addNewPomodoro(moment().subtract(_runningDuration, 'minutes').toDate(), moment().toDate()) + } else { _runningDurationRemaining -= 1; if (options.onTick) options.onTick() @@ -108,6 +113,10 @@ var pomodoro = function(options) { return ('0' + Math.floor(remainingTime/60)).slice(-2) + ':' + ('0' + remainingTime % 60).slice(-2); }, + getHistory(type) { + return pomodoroStorage.getHistory(type); + }, + isRunning() { return _currentState === States.RUNNING; }, @@ -130,3 +139,26 @@ var pomodoro = function(options) { module.exports = pomodoro; + + +var pomodoroStorage = { + addNewPomodoro: function(startDate, endDate) { + var pomodoros = store.get('pomodoros') || []; + pomodoros.push({ startDate, endDate }) + store.put('pomodoros', pomodoros); + }, + + // type = day/week/month/year + getHistory(type) { + var pomodoros = store.get('pomodoros') || []; + if (type) { + pomodoros = pomodoros.filter(item => moment().isSame(item.endDate, type)); + } + var duration = pomodoros.reduce((total, p) => total + moment(p.endDate).diff(p.startDate), 0); + duration = moment.duration(duration); + return { + count: pomodoros.length, + duration: `${Math.floor(duration.asHours())}h:${duration.minutes()}m`, + }; + } +}