1
0
Fork 0
mirror of https://github.com/Luzifer/worktime.git synced 2024-10-18 08:04:22 +00:00
Personal working time tracker for employees
Find a file
Knut Ahlers 68b120c623
During track display tracked time
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-07-30 14:01:04 +02:00
cmd During track display tracked time 2019-07-30 14:01:04 +02:00
schema Allow time format without seconds 2017-08-07 13:37:22 +02:00
templates Initial version 2016-09-24 14:59:16 +02:00
vendor Switch to dep from Godeps, update dependencies 2017-09-22 13:18:15 +02:00
.gitignore Initial version 2016-09-24 14:59:16 +02:00
.repo-runner.yaml Migrate to recent version of publish script 2017-08-07 12:50:49 +02:00
Gopkg.lock Switch to dep from Godeps, update dependencies 2017-09-22 13:18:15 +02:00
Gopkg.toml Switch to dep from Godeps, update dependencies 2017-09-22 13:18:15 +02:00
History.md prepare release v0.3.0 2017-09-22 12:44:23 +02:00
LICENSE Initial version 2016-09-24 14:59:16 +02:00
main.go Initial version 2016-09-24 14:59:16 +02:00
Makefile Migrate to recent version of publish script 2017-08-07 12:50:49 +02:00
README.md Add README 2017-09-22 13:13:26 +02:00

Luzifer / worktime

Worktime is intended as a personal time tracker for cases where the employer trusts you to work the amount of hours set in your contract but you want to make sure you really did.

Usage

# worktime help
Manage worktimes in CouchDB

Usage:
  worktime [command]

Available Commands:
  overtime    Shows total overtime over all time
  show        Display a summary of the given / current day
  tag         Adds or removes a tag from the day or time entry inside the day
  time        manipulate times of a day

Flags:
      --config string    config file (default is $HOME/.worktime.yaml)
      --couchdb string   URL to access couchdb (http://user:pass@host:port/database)

Setup

You will need:

  • The worktime binary (see latest release)
  • A CouchDB instance already set up with a database
  • One design document (analysis) with (at least) one view (overtime) in it (see below for an example)

After you've set up all of this you will need to export the COUCHDB environment variable in the form https://user:pass@host/db when using the worktime commandline tool. (Alternatively you could pass the --couchdb commandline flag to worktime every time you call it)

Example of required view

This view (analysis/overtime) does the time calculation for you so you definitely need to adjust that one for your personal needs (weekly hours, tags, ...).

Map Function

function(day) {
  var hasTag = function(day, tag) { return day.tags && day.tags.indexOf(tag) > -1 }

  var worked_time = 0.0;
  var daily_hours = 8.0;

  for (var idx = 0; idx < day.times.length; idx++) {
    var time = day.times[idx];
    var s = new Date(day._id + 'T' + time.start);
    var e = new Date(day._id + 'T' + time.end);
    var diff = (e - s) / 1000.0 / 3600.0;
    
    if (hasTag(time, "break")) {
      worked_time = worked_time - diff;
    } else {
      worked_time = worked_time + diff;
    }
  }
  
  if (hasTag(day, "holiday") || hasTag(day, "vacation") || hasTag(day, "ill") || hasTag(day, "weekend")) {
    required_time = 0.0;
  } else {
    required_time = daily_hours;
  }
  
  var outcome = worked_time - required_time;
  
  emit(day._id, outcome);
}

Reduce Function

function(keys, values, rereduce) {
  var sum = 0.0;
  for(var idx = 0; idx < values.length; idx++) {
    sum = sum + values[idx];
  }
  
  return sum;
}

Of course this does not need to be the only view: You can for example add a view to count your days of vacation or even any other evaluation you can imagine. The tool just relies on analysis/overtime to be present.