-
|
I would like to see decimal hours-per-day totals. This would make it easier for me to transfer hours worked per day into my work time tracking system (Tempo). Something like this:
I'd like those intervals to be grouped/hidden. Basically the same thing with fewer columns, and only one row per day. This "one line per day" example illustrates what I'm thinking of (except I'd like decimal time totals), but that's a suggestion, yes? or has it been implemented? I've tried creating an extension, and it mostly works: (I'm discarding stderr to hide debugging output) The total time is correct, but I haven't figured out how to handle the case where an interval spans midnight, so the per-day breakdown is incorrect. Thanks to timewarrior I've got awesome tooling and raw data, I'm just looking for help on how to get it closer to what I need for Tempo. Here's my current mostly-working Details#!/usr/bin/env python3
# total hours per day in decimal format (for easy transfer to Tempo)
# compare / check against
# → timew week (chart w/daily totals)
# → timew summary :week (days w/intervals)
from datetime import datetime
import json
import sys
# No longer necessary since I switched from strptime() to fromisoformat(), but
# I'm keeping it around here in case I need to switch back (to avoid looking up
# format codes again).
#TIMEW_INTERNAL_DATE_FORMAT = "%Y%m%dT%H%M%SZ"
SIMPLE_OUTPUT_DATE_FORMAT = "%a %b %d"
header = 1
body = ""
for line in sys.stdin:
# skip & discard config
if header:
if line == "\n": header = 0
else:
body += line
print(body, file=sys.stderr)
data = json.loads(body)
totals = {}
for event in data:
print(f'🐛 ES: {event["start"]}', file=sys.stderr)
print(f'🐛 EE: {event["end"]}', file=sys.stderr)
start = datetime.fromisoformat(event['start'])
if 'end' in event:
end = datetime.fromisoformat(event['end'])
else:
end = datetime.utcnow()
duration = (end - start).total_seconds() / 3600 # Convert to hours
print(f'🐛 D: {duration}', file=sys.stderr)
# FIXME - handle timespan crossing midnight. Break single duration spanning
# midnight into list (duration per day). This is tricky!
startDate = start.astimezone().strftime(SIMPLE_OUTPUT_DATE_FORMAT)
endDate = end.astimezone().strftime(SIMPLE_OUTPUT_DATE_FORMAT)
print(f'🐛 S: {startDate}', file=sys.stderr)
print(f'🐛 E: {endDate}', file=sys.stderr)
if startDate in totals:
totals[startDate] += duration
else:
totals[startDate] = duration
total = 0
for day in totals:
total += totals[day]
print(f"{day} {totals[day]:5.2f}")
print(f'----------------')
# I think timewarrior adds an extra newline
print(f' Total: {total:5.2f}', end='')I'm using timewarrior 1.7.1 on Ubuntu 24.04 LTS 64-bit desktop. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The summary report is not intended to accommodate every possible use case (the file is more a brainstorming, not everything from there has/will be implemented). So a custom extension is the right way to go.
You could modify your
|
Beta Was this translation helpful? Give feedback.
The summary report is not intended to accommodate every possible use case (the file is more a brainstorming, not everything from there has/will be implemented). So a custom extension is the right way to go.
You could modify your
for event in data:loop by adding a second, internal, loop, which would cut each interval into daily chunks. Here's some pseudo code:startandendfrom the intervalstartDatefromstarts…