39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
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('--opacity', type=float, default=0.3)
|
|
|
|
def handle(self, *args, **options):
|
|
datetime_var = 'author_datetime'
|
|
if options.get('committime'):
|
|
datetime_var = 'commit_datetime'
|
|
|
|
event_dates = []
|
|
event_times = []
|
|
plots = []
|
|
for i, (legend, serie) in enumerate(self.get_series(options)):
|
|
for commit in serie:
|
|
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)
|
|
plot = plt.scatter(event_dates, event_times, alpha=options.get('opacity'))
|
|
plots.append((legend, plot))
|
|
|
|
if i > 1:
|
|
plt.legend([plot[0] for legend, plot in plots],
|
|
[legend for legend, plot in plots])
|
|
|
|
plt.gca().xaxis.set_major_locator(matplotlib.dates.YearLocator())
|
|
plt.gca().xaxis.set_minor_locator(matplotlib.dates.MonthLocator())
|
|
plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%m/%Y'))
|
|
plt.gca().set_ylim([0, 24])
|
|
plt.yticks(range(24))
|
|
self.plot(options)
|