Setup


In [ ]:
%pylab inline

In [ ]:
!pip3 install brewer2mpl

In [ ]:
import pandas

In [ ]:
import brewer2mpl
brewer_colors = brewer2mpl.get_map('Pastel1', 'Qualitative', 7).mpl_colors

Input


In [ ]:
log = pandas.read_csv('.tasks-log.csv', sep=';', parse_dates=[4], index_col='start')

All time totals


In [ ]:
grp = log.groupby('project').sum().duration

In [ ]:
pie(grp, labels=grp.index, autopct='%1.1f%%', colors=brewer_colors, )
plt.axis('equal')

In [ ]:
grouper = pandas.TimeGrouper('1D')

Per-day plot


In [ ]:
grp = log.groupby([lambda x: x.date, 'project']).sum()

In [ ]:
projects = log.project.unique()
def make_index(days = 7):
    global dates
    dates = [datetime.date.today()-
            datetime.timedelta(days=x)
            for x in range(days)
            ]
    return[[date, project]
           for project in projects
           for date in dates
           ]
index_frame = pandas.DataFrame(make_index())
index_frame.columns = ['start', 'project']
index_frame.set_index(['start', 'project'], inplace=True)

In [ ]:
grp = grp.reindex_axis(index_frame.index, copy=False)
grp.fillna(0, inplace=True)

In [ ]:
xax = plt.axes().xaxis
offset = zeros_like(dates)
for index, project in enumerate(projects):
    single = grp.xs(project, level='project').duration
    single /= 60
    bar(single.index, single, 
        color=[brewer_colors[index]],
        label=project,
        bottom=offset,
        align='center')
    offset += single
legend(loc='best')
ylabel('minutes')
xlabel('date')
xax.set_ticks(dates)
xax.set_ticklabels([date.strftime("%m-%d") 
                    for date in dates])
for tl in xax.get_ticklabels():
      tl.set_fontsize(10)
      tl.set_rotation(30)
show()

In [ ]: