add times graph
This commit is contained in:
parent
cb337f44e6
commit
aa0fd92f1f
|
@ -0,0 +1,52 @@
|
|||
import datetime
|
||||
import matplotlib
|
||||
import matplotlib.dates
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils.dateparse import parse_date
|
||||
|
||||
from eodb.events.models import Commit
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--username', metavar='USERNAME')
|
||||
parser.add_argument('--datemin', metavar='DATEMIN')
|
||||
parser.add_argument('--datemax', metavar='DATEMAX')
|
||||
parser.add_argument('--committime', action='store_true',
|
||||
help='use commit datetime instead of author datetime')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
filters = {'author_email__endswith': '@entrouvert.com'}
|
||||
|
||||
title = 'Git activity'
|
||||
|
||||
if options.get('username'):
|
||||
filters['author_email__startswith'] = options['username'] + '@'
|
||||
title += ' for %s' % options['username']
|
||||
|
||||
datetime_var = 'author_datetime'
|
||||
if options.get('committime'):
|
||||
datetime_var = 'commit_datetime'
|
||||
if options.get('datemin'):
|
||||
filters[datetime_var + '__gte'] = parse_date(options['datemin'])
|
||||
title += ' from %s' % options['datemin']
|
||||
if options.get('datemax'):
|
||||
filters[datetime_var + '__lt'] = parse_date(options['datemax'])
|
||||
title += ' until %s' % options['datemax']
|
||||
|
||||
event_dates = []
|
||||
event_times = []
|
||||
for commit in Commit.objects.filter(**filters):
|
||||
graph_date = getattr(commit, datetime_var)
|
||||
event_dates.append(matplotlib.dates.date2num(graph_date.date()))
|
||||
event_times.append(graph_date.hour + graph_date.minute / 60. + graph_date.second / 3600)
|
||||
|
||||
plt.title(title)
|
||||
plt.scatter(event_dates, event_times, alpha=0.3)
|
||||
plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%m/%Y'))
|
||||
plt.gca().set_ylim([0, 24])
|
||||
plt.yticks(range(24))
|
||||
plt.show()
|
||||
|
Reference in New Issue