Time is tracked by logging the active, focused window of the user every second. The consolidate script is mean to be run on a 5 minute interval on the seconds, and consolidates the raw time log.
You then upload your consolidated time log to https://timetrack.slgotting.com, and you can inspect your time usage with a graphical UI
Right now this script is only usable on Linux. Tested working on Ubuntu 18. It should work on any linux distro if the following commands are available:
- xdotool
- wmctrl
- xprintidle
I may add support for Windows in the future but I wanted to get it out as it is right now.
sudo apt install xdotool wmctrl xprintidle
pip install timetrack-slg
sudo -E env "PATH=$PATH" install-timetrack-slg -u username
sudo access is necessary because we're installing a new systemd service The -E env sets your superuser's PATH variable to your current PATH variable, so root has access to the necessary python packages
This is the hard way, make sure to look over any commands and see that they contain proper variable values
Make sure to change username to your username | |
---|---|
Also your python file install might be at a location other than /home/username/.local/bin/timetrack-slg . To find location, run whereis timetrack-slg . Update ExecStart as necessary |
|
ℹ️ | The -s switch is set to .9766 because this is the interval I found gives me close to or exactly 1 run per second. See "Calculate your sleep time" for information on how to calculate what value you should use. |
ℹ️ | Get your DISPLAY variable with env | grep DISPLAY |
ℹ️ | Output file -o /home/username/timetrack-slg/time-log.json must be a json file |
ℹ️ | Run timetrack-slg -h to see all options |
In your terminal, run:
echo '[Unit]
Description=Time tracker
After=multi-user.target
[Service]
User=username
Type=simple
Restart=always
Environment="DISPLAY=:0"
ExecStart=/home/username/.local/bin/timetrack-slg \
--output_filepath /home/username/timetrack-slg/time-log.json \
--sleep_time 0.9766 \
--time_til_idle 30 \
--config_filepath /home/username/.config/slg/time-log.yml
[Install]
WantedBy=multi-user.target' | sudo tee /etc/systemd/system/timetrack-slg.service >/dev/null
Restart systemctl daemon:
sudo systemctl daemon-reload
Then tell systemd to start this up at boot with:
sudo systemctl enable timetrack-slg.service
And start er up with:
sudo systemctl start timetrack-slg.service
Add this line to your crontab (changing username and paths where necessary):
*/5 * * * * /home/username/.local/bin/timetrack-consolidate-slg --input_filepath /home/username/timetrack-slg/time-log.json --config_filepath /home/username/.config/slg/time-log.yml --run_interval 5
This line consolidates the time-log.json file every 5 minutes so that our timelog filesize doesnt grow too big.
If you've done everything correctly, you should have a time-log-consolidated.json generated in the input_filepath location (if at least 5 minutes have passed).
- Make sure timetrack-consolidate-slg is running in crontab every 5 minutes.
- Run the script without any -s flag set for a while. 10 minutes to be safe. Shouldn't need to do this more than once so find something else to do while waiting.
- Inspect your consolidate file and add up the times of a 5 minute block. The value should be relatively close to 300 (~ 290 - 299). Mine was 293
- Divide number by 300. So in my case I had 293 so ( 293 / 300 ) is .9766, hence the value you see above.
Note: Since we will simply overwrite any times that already exist, we can use a number lower than this and run the script more frequently (0.96 or even lower) to guarantee we have 300 data points every 5 minutes.