43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
import datetime
|
|
import matplotlib
|
|
import matplotlib.dates
|
|
import matplotlib.pyplot as plt
|
|
|
|
from .common import GraphCommand
|
|
|
|
|
|
class Command(GraphCommand):
|
|
def add_arguments(self, parser):
|
|
super(Command, self).add_arguments(parser)
|
|
parser.add_argument('--groupby', metavar='TIME UNIT', default='weeks',
|
|
help='aggregate over weeks (default) / months / years')
|
|
|
|
def handle(self, *args, **options):
|
|
title = 'Git activity'
|
|
|
|
datetime_var = 'author_datetime'
|
|
if options.get('committime'):
|
|
datetime_var = 'commit_datetime'
|
|
|
|
events = {}
|
|
for commit in self.get_commits(options):
|
|
commit_date = getattr(commit, datetime_var).date()
|
|
if options.get('groupby') == 'weeks':
|
|
graph_date = commit_date - datetime.timedelta(days=commit_date.weekday())
|
|
elif options.get('groupby') == 'months':
|
|
graph_date = commit_date.replace(day=1)
|
|
elif options.get('groupby') == 'years':
|
|
graph_date = commit_date.replace(month=1, day=1)
|
|
|
|
date = matplotlib.dates.date2num(graph_date)
|
|
if not date in events:
|
|
events[date] = 0
|
|
events[date] = events[date] + 1
|
|
|
|
dates = sorted(events.keys())
|
|
values = [events[x] for x in dates]
|
|
|
|
plt.plot(dates, values)
|
|
plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%m/%Y'))
|
|
self.plot(options)
|