jkjk not final
This commit is contained in:
99
progress.py
Normal file
99
progress.py
Normal file
@@ -0,0 +1,99 @@
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from datetime import datetime, timedelta
|
||||
import math
|
||||
|
||||
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
|
||||
|
||||
today = datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)
|
||||
this_week = today - timedelta(days=7)
|
||||
|
||||
total_hours = 0.0
|
||||
day_hours = 0.0
|
||||
week_hours = 0.0
|
||||
|
||||
oldest_timestamp = datetime.now()
|
||||
|
||||
while i < len(lines):
|
||||
line = lines[i].strip()
|
||||
|
||||
if line.startswith('#'):
|
||||
current_chapter = line[line.find(' ')+1:]
|
||||
total_chapters += 1
|
||||
elif line.startswith('@start'):
|
||||
start = parse_timestamp(line.removeprefix('@start '))
|
||||
|
||||
if start < oldest_timestamp:
|
||||
oldest_timestamp = start
|
||||
|
||||
i += 1
|
||||
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)
|
||||
|
||||
num_days = (datetime.now() - oldest_timestamp).days or 1
|
||||
hours_per_day = total_hours / num_days
|
||||
|
||||
hours_per_chapter = total_hours / completed_chapters
|
||||
hours_to_completion = hours_per_chapter * (total_chapters - completed_chapters)
|
||||
days_to_completion = math.ceil(hours_to_completion / hours_per_day)
|
||||
|
||||
completion_date = datetime.now() + timedelta(days=days_to_completion)
|
||||
|
||||
completion_percentage = completed_chapters/total_chapters*100
|
||||
|
||||
print(f'Started on: {oldest_timestamp.strftime("%Y-%m-%d")}')
|
||||
print(f'Progress: [{completed_chapters}/{total_chapters}] ({round(completion_percentage, 2)}%)')
|
||||
print(f'Total: {round(total_hours, 2)}h')
|
||||
print(f'Week: {round(week_hours, 2)}h')
|
||||
print(f'Day: {round(day_hours, 2)}h')
|
||||
print(f'Hours per day: {round(hours_per_day, 2)}h')
|
||||
print(f'Hours to completion: {round(hours_to_completion, 2)}h')
|
||||
print(f'Completion date: {completion_date.strftime("%Y-%m-%d")}')
|
||||
|
||||
Reference in New Issue
Block a user