summaryrefslogtreecommitdiff
path: root/diffs.py
blob: c9e78301f8470dd54bccb0bbee3fc7039d078659 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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()