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

28 lines
No EOL
1,000 B
Python

#!/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'])
df['duration_dec'] = df['Duration'].dt.total_seconds() / 3600
df.rename(columns={
'Project': 'project',
'Description': 'description',
'Start date': 'day',
'Duration': 'duration'
}, inplace=True)
dfg = df.groupby(['project','description','day'], as_index=False).agg({'duration': 'sum'})
dfg['duration'] = round(dfg['duration'].dt.total_seconds() / 60 / 60, 2)
print("Total hours are: ", round(dfg['duration'].sum(), 2))
dfg.to_csv(Path(sys.argv[1]).stem + '-grouped.csv', index=False)
dfc = dfg.groupby(['project'] , as_index=False).agg({'duration': 'sum'})
for index, row in dfc.iterrows():
print(row['project'], str(row['duration']).replace(".",","))