1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#!/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
start = datetime(year=2020, month=7, day=1)
width = 6
def format_stamp(stamp):
dt = datetime.utcfromtimestamp(stamp)
date = (dt.weekday() + 5) % 7 * width
time = dt.hour + 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)}:{int(x%1 * 60)}"
weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
def x_fmt(x, y):
return weekDays[int((x/width + 2) % 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, 16, 32, 48]
x = [i for i, j in dates]
y = [j for i, j in dates]
daymonthFmt = mdates.DateFormatter('%d %B')
for ax, s in zip(axs.flatten(), sigmas):
#ax.xaxis.set_major_formatter(daymonthFmt)
#_ = plt.xticks(rotation=90)
ax.yaxis.set_major_formatter(tick.FuncFormatter(y_fmt))
ax.xaxis.set_major_formatter(tick.FuncFormatter(x_fmt))
ax.xaxis.set_ticks(np.arange(0, 7 * width, width))
if s == 0:
ax.plot(x, y, 'k.', markersize=5)
ax.set_title("Scatter plot")
else:
img, extent = myplot(x, y, s)
ax.imshow(img, extent=extent, origin='lower', cmap=cm.jet)
ax.set_title("Smoothing with $\sigma$ = %d" % s)
plt.show()
|