Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / tools / dev / graph-dav-servers.py
blobe2bf0df9c4f4d73bdaae70abb91f390987765437
1 #!/usr/bin/env python
3 # graph-svn-dav.py by Brian W. Fitzpatrick <fitz@red-bean.com>
5 # This was originally a quick hack to make a pretty picture of svn DAV servers.
7 # I've dropped it in Subversion's repository at the request of Karl Fogel.
9 # Be warned this this script has many dependencies that don't ship with Python.
11 import sys
12 import os
13 import fileinput
14 import datetime
15 import time
16 from datetime import datetime
17 from matplotlib.dates import date2num
18 import matplotlib
19 matplotlib.use('Agg')
20 from matplotlib.pylab import *
21 import Image
23 OUTPUT_FILE = '../../www/images/svn-dav-securityspace-survey.png'
24 OUTPUT_IMAGE_WIDTH = 800
26 STATS = """1/1/2003 70
27 2/1/2003 158
28 3/1/2003 222
29 4/1/2003 250
30 5/1/2003 308
31 6/1/2003 369
32 7/1/2003 448
33 8/1/2003 522
34 9/1/2003 665
35 10/1/2003 782
36 11/1/2003 969
37 12/1/2003 1009
38 1/1/2004 1162
39 2/1/2004 1307
40 3/1/2004 1424
41 4/1/2004 1792
42 5/1/2004 2113
43 6/1/2004 2502
44 7/1/2004 2941
45 8/1/2004 3863
46 9/1/2004 4174
47 10/1/2004 4187
48 11/1/2004 4783
49 12/1/2004 4995
50 1/1/2005 5565
51 2/1/2005 6505
52 3/1/2005 7897
53 4/1/2005 8751
54 5/1/2005 9793
55 6/1/2005 11534
56 7/1/2005 12808
57 8/1/2005 13545
58 9/1/2005 15233
59 10/1/2005 17588
60 11/1/2005 18893
61 12/1/2005 20278
62 1/1/2006 21084
63 2/1/2006 23861
64 3/1/2006 26540
65 4/1/2006 29396
66 5/1/2006 33001
67 6/1/2006 35082
68 7/1/2006 38939
69 8/1/2006 40672
70 9/1/2006 46525
71 10/1/2006 54247
72 11/1/2006 63145
73 12/1/2006 68988
74 1/1/2007 77027
75 2/1/2007 84813
76 3/1/2007 95679
77 4/1/2007 103852
78 5/1/2007 117267
79 6/1/2007 133665
80 7/1/2007 137575
81 8/1/2007 155426
82 9/1/2007 159055
83 10/1/2007 169939
84 11/1/2007 180831
85 12/1/2007 187093
86 1/1/2008 199432"""
89 def get_date(raw_date):
90 date = time.strptime(raw_date, "%m/%d/%Y")
91 date = datetime(date[0], date[1], date[2], date[3])
92 return date
95 def get_ordinal_date(date):
96 # This is the only way I can get matplotlib to do the dates right.
97 return date2num(date)
100 def parse_stats(str):
101 dates = []
102 counts = []
104 lines = str.split('\n')
105 for line in lines:
106 key, val = line.split(' ', 1)
108 dates.append(int(get_ordinal_date(get_date(key))))
109 counts.append(int(val.lstrip()))
110 return dates, counts
113 def draw_graph(dates, counts):
114 ###########################################################
115 # Drawing takes place here.
116 figure(1)
118 ax = subplot(111)
119 plot_date(dates, counts, color='r', linestyle='-', marker='o', markersize=3)
121 ax.xaxis.set_major_formatter( DateFormatter('%Y') )
122 ax.xaxis.set_major_locator( YearLocator() )
123 ax.xaxis.set_minor_locator( MonthLocator() )
124 ax.set_xlim( (dates[0] - 92, dates[len(dates) - 1] + 92) )
126 ax.yaxis.set_major_formatter( FormatStrFormatter('%d') )
128 ylabel('Total # of Public DAV Servers')
130 lastdate = datetime.fromordinal(dates[len(dates) - 1]).strftime("%B %Y")
131 xlabel("Data as of " + lastdate)
132 title('Security Space Survey of\nPublic Subversion DAV Servers')
133 # End drawing
134 ###########################################################
135 png = open(OUTPUT_FILE, 'w')
136 savefig(png)
137 png.close()
138 os.rename(OUTPUT_FILE, OUTPUT_FILE + ".tmp.png")
139 try:
140 im = Image.open(OUTPUT_FILE + ".tmp.png", 'r')
141 (width, height) = im.size
142 print "Original size: %d x %d pixels" % (width, height)
143 scale = float(OUTPUT_IMAGE_WIDTH) / float(width)
144 width = OUTPUT_IMAGE_WIDTH
145 height = int(float(height) * scale)
146 print "Final size: %d x %d pixels" % (width, height)
147 im = im.resize((width, height), Image.ANTIALIAS)
148 im.save(OUTPUT_FILE, im.format)
149 os.unlink(OUTPUT_FILE + ".tmp.png")
150 except Exception, e:
151 sys.stderr.write("Error attempting to resize the graphic: %s\n" % (str(e)))
152 os.rename(OUTPUT_FILE + ".tmp.png", OUTPUT_FILE)
153 raise
154 close()
157 if __name__ == '__main__':
158 dates, counts = parse_stats(STATS);
159 draw_graph(dates, counts)
160 print "Don't forget to update ../../www/svn-dav-securityspace-survey.html!"