#!/usr/bin/env python3 from datetime import datetime from phabricator import Phabricator import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm import matplotlib.dates as mdates import matplotlib.ticker as tick from scipy.ndimage.filters import gaussian_filter import pandas as pd start = datetime(year=2020, month=7, day=1) width = 6 xoff = 2 yoff = 2 def format_stamp(stamp): dt = datetime.utcfromtimestamp(stamp) date = dt time = (dt.hour + 24 - yoff) % 24 + dt.minute / 60.0 return [date, time] phab = Phabricator() # This will use your ~/.arcrc file diff = phab.differential.query() dates = [] for d in diff: created = format_stamp(int(d["dateCreated"])) modified = format_stamp(int(d["dateModified"])) dates += [created, modified] def y_fmt(x, y): return f"{(int(x//1 + yoff))%24}:{int(x%1 * 60)}0" weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday") def x_fmt(x, y): return weekDays[int((x/width + xoff) % 7)] def myplot(x, y, s, bins=1000): heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins) heatmap = gaussian_filter(heatmap, sigma=s) extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]] return heatmap.T, extent fig, axs = plt.subplots(2, 2) sigmas = [0, 0, 32, 32] x = [mdates.date2num(i) for i, j in dates] x2 = [(dt.weekday() + 7 - xoff) % 7 * width for dt, j in dates] y = [j for i, j in dates] daymonthFmt = mdates.DateFormatter('%d %B') for i, ax, s in zip(range(len(x)), axs.flatten(), sigmas): px = x if i % 2 == 0: ax.xaxis.set_major_formatter(tick.FuncFormatter(x_fmt)) ax.xaxis.set_ticks(np.arange(0, 7 * width, width)) px = x2 ax.set_title( "Commits per weekday") else: ax.xaxis.set_major_formatter(daymonthFmt) ax.set_title( "Commits per day") #ax.xaxis.set_ticks(pd.date_range(start="2020-07", end="2020-09", freq="D")) #ax.tick_params(labelrotation=90) ax.yaxis.set_major_formatter(tick.FuncFormatter(y_fmt)) ax.yaxis.set_ticks(np.arange(0, 25, 1.0)) ax.ylabel = "Time" if s == 0: ax.plot(px, y, 'k.', markersize=5) ax.set_title( ax.get_title() + " Scatter plot") else: img, extent = myplot(px, y, s) ax.imshow(img, extent=extent, origin='lower', cmap=cm.magma) ax.set_title( ax.get_title() + " Smoothing with $\sigma$ = %d" % s) plt.show()