-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot-uploads.py
79 lines (61 loc) · 1.51 KB
/
plot-uploads.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib
matplotlib.use("Agg")
import pylab
from datetime import date
from math import sqrt
from sys import stderr
from helpers import mediawiki
uploads = mediawiki.get_uploads()
pylab.figure(figsize=(20.0, 12.0))
uploads_per_month = {}
uploads_per_day = {}
for (timestamp, title) in uploads:
day = timestamp.date()
try:
uploads_per_day[day] += 1
except KeyError:
uploads_per_day[day] = 1
uploads_total = {}
totalcount = 0
days, daycount = zip(*sorted(uploads_per_day.items()))
uploads_total_per_day = {}
totalcount = 0
for day, count in zip(days, daycount):
totalcount += count
uploads_total_per_day[day] = totalcount
timestamps, totalcount = zip(*sorted(uploads_total_per_day.items()))
pylab.plot(
timestamps,
totalcount,
c='black',
linewidth=1,
zorder=-1
)
dayarea = [sqrt(d)*100 for d in daycount]
pylab.scatter(
x=days,
y=totalcount,
s=dayarea,
c=daycount,
cmap=pylab.cm.summer_r,
linewidths=1,
edgecolor='black'
)
pylab.suptitle(
'Timeline of Open Access Media Importer Contributions ' + \
'for %s between %s and %s' % (
mediawiki.get_wiki_name(),
min(days),
max(days)
)
)
pylab.xlabel("Time (UTC)")
pylab.ylabel("Pages")
pylab.colorbar()
pylab.grid(True)
filename = 'plot-uploads.png'
with open(filename, 'w') as f:
pylab.savefig(f, format='png', bb_inches='tight', pad_inches=0)
print('Wrote figure to “%s”.\n' % filename)