Initial commit
This commit is contained in:
commit
e2ed91c217
67
csv_report.py
Executable file
67
csv_report.py
Executable file
@ -0,0 +1,67 @@
|
|||||||
|
#!/home/florent/.conda/envs/sixp/bin/python
|
||||||
|
#/usr/bin/env python
|
||||||
|
# file csv.py
|
||||||
|
# author Florent Guiotte <florent.guiotte@irisa.fr>
|
||||||
|
# version 0.0
|
||||||
|
# date 27 sept. 2022
|
||||||
|
"""Abstract
|
||||||
|
|
||||||
|
doc.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from timewreport.parser import TimeWarriorParser
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
|
def filter_tag(df, tag):
|
||||||
|
select = [tag in t for t in df.tags]
|
||||||
|
return df[select]
|
||||||
|
|
||||||
|
|
||||||
|
def get_tag_summary(df, tags):
|
||||||
|
summary_data = [(tag, filter_tag(df, tag).duration.sum()) for tag in tags]
|
||||||
|
summary = pd.DataFrame(summary_data, columns=['tag', 'time'])
|
||||||
|
duration_filter = [not not t for t in df.tags]
|
||||||
|
summary['ratio'] = summary.time / df[duration_filter].duration.sum()
|
||||||
|
|
||||||
|
return summary
|
||||||
|
|
||||||
|
|
||||||
|
def get_top_tag_summary(tag_summary):
|
||||||
|
tags_top = set([t.split()[0] for t in tag_summary.tag])
|
||||||
|
|
||||||
|
top_data = []
|
||||||
|
for tag in tags_top:
|
||||||
|
top_df = summary[[tag == t.split()[0] for t in summary.tag]].sum()
|
||||||
|
top_df.tag = tag
|
||||||
|
top_data += [top_df]
|
||||||
|
|
||||||
|
return pd.DataFrame(top_data)
|
||||||
|
|
||||||
|
|
||||||
|
def get_timew_df():
|
||||||
|
parser = TimeWarriorParser(sys.stdin)
|
||||||
|
|
||||||
|
data = [(i.get_start(), i.get_end(), i.get_duration(), i.get_tags()) for i in parser.get_intervals()]
|
||||||
|
cols = ('start', 'end', 'duration', 'tags')
|
||||||
|
df = pd.DataFrame(data, columns=cols)
|
||||||
|
|
||||||
|
df.start = pd.to_datetime(df.start)
|
||||||
|
df.end = pd.to_datetime(df.end)
|
||||||
|
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
df = get_timew_df()
|
||||||
|
|
||||||
|
tags = set([t for tl in df.tags for t in tl])
|
||||||
|
|
||||||
|
summary = get_tag_summary(df, tags)
|
||||||
|
top_summary = get_top_tag_summary(summary)
|
||||||
|
|
||||||
|
for k, s in (('Detailed summary', summary), ('Top level summary', top_summary)):
|
||||||
|
print()
|
||||||
|
print(f'--- {k} ---')
|
||||||
|
print(s.to_string(formatters={'ratio': '{:,.2%}'.format}))
|
Loading…
Reference in New Issue
Block a user