This commit is contained in:
olari
2021-05-31 12:47:57 +03:00
parent 3aef7c4133
commit a10d3e1326
3 changed files with 84 additions and 103 deletions

View File

@@ -7,27 +7,11 @@ from common import parse_timestamp
content = open(sys.argv[1]).read().strip()
"""
* Total hours
* Hours today
* Hours this week
* Percentage completed
* Pages completed
* Estimated hours to completion
* Estimated completion date
"""
lines = content.splitlines()
i = 0
current_chapter = ''
result = defaultdict(float)
total_chapters = 0
completed_chapters = 0
completed_chapters = set()
today = datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)
this_week = today - timedelta(days=7)
@@ -38,13 +22,17 @@ week_hours = 0.0
oldest_timestamp = datetime.now()
i = 0
while i < len(lines):
line = lines[i].strip()
if line.startswith('#'):
current_chapter = line[line.find(' ')+1:]
total_chapters += 1
elif line.startswith('@start'):
else:
completed_chapters.add(current_chapter)
if line.startswith('@start'):
start = parse_timestamp(line.removeprefix('@start '))
if start < oldest_timestamp:
@@ -54,28 +42,18 @@ while i < len(lines):
line = lines[i].strip()
end = parse_timestamp(line.removeprefix('@stop '))
delta = end - start
hours = delta.seconds / 60 / 60
result[current_chapter] += hours
total_hours += hours
if start > this_week:
week_hours += hours
if start > today:
day_hours += hours
elif line.startswith('@done'):
completed_chapters += 1
i += 1
#from pprint import pprint
#pprint(dict(result), sort_dicts=False)
completed_chapters = len(completed_chapters)
num_days = (datetime.now() - oldest_timestamp).days or 1
hours_per_day = total_hours / num_days