dotfiles/home-manager/pkgs/toggl-time-grouper/toggl-time-grouper

24 lines
820 B
Text
Raw Normal View History

2023-10-04 01:59:47 +02:00
#!/usr/bin/env python3
import pandas as pd
import sys
from pathlib import Path
df = pd.read_csv(sys.argv[1])
df = df.drop(columns=['User', 'Email', 'Billable', 'Tags', 'Amount ()', 'Start time', 'End date', 'End time'])
df['Duration'] = pd.to_timedelta(df['Duration'])
df['Start date'] = pd.to_datetime(df['Start date'])
2023-11-03 22:26:59 +01:00
df['duration_dec'] = df['Duration'].dt.total_seconds() / 3600
df.rename(columns={
'Project': 'project',
'Description': 'description',
'Start date': 'day',
'Duration': 'duration'
}, inplace=True)
2023-10-04 01:59:47 +02:00
2023-11-03 22:26:59 +01:00
df = df.groupby(['project','description','day'], as_index=False).agg({'duration': 'sum'})
df['duration'] = round(df['duration'].dt.total_seconds() / 60 / 60, 2)
print("Total hours are: ", round(df['duration'].sum(), 2))
2023-10-04 01:59:47 +02:00
2023-11-03 22:26:59 +01:00
df.to_csv(Path(sys.argv[1]).stem + '-grouped.csv', index=False)