Simple analyzer and aggregator for a simple time log
Reads a text file containing one iso-8601 timestamp per line and normalizes them to quarter-hours. These quarter-hours are treated as "time spent", which gets aggregated into stats by day, week, month and weekday, and printed.
This is currently pretty much a one-off script with some added comments, but has already proved very useful in tracking time spent working, and there's potential for more.
- Have a cron job or something else write the current date into a file every quarter hour:
date --iso-8601=seconds >> log.txt
- Run the script in the log.txt directory to see the aggregate output:
$ ./timelog.py
Months
{'2016-02': 35.5}
Weeks
{'2016 W06': 0.5, '2016 W07': 35.0}
Days
{'2016-02-13 Sat': 0.5,
'2016-02-15 Mon': 6.0,
'2016-02-16 Tue': 8.25,
'2016-02-17 Wed': 10.5,
'2016-02-18 Thu': 10.25}
Days of Week
{'1 Mon': {'avg': 6.0, 'sum': 6.0},
'2 Tue': {'avg': 8.25, 'sum': 8.25},
'3 Wed': {'avg': 10.5, 'sum': 10.5},
'4 Thu': {'avg': 10.25, 'sum': 10.25},
'6 Sat': {'avg': 0.5, 'sum': 0.5}}
Longest session
2016-02-17 10:30:00+01:00 to 2016-02-17 20:45:00+01:00 (10:15:00)
Copyright 2017 Tilman Boerner
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.