Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show daily, weekly and monthly pomodoro history 🍅 #118

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.DS_Store
node_modules
storage
23 changes: 21 additions & 2 deletions care.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions pomodoro.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
},
Expand All @@ -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`,
};
}
}