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.
16 from datetime
import datetime
17 from matplotlib
.dates
import date2num
20 from matplotlib
.pylab
import *
23 OUTPUT_FILE
= '../../www/images/svn-dav-securityspace-survey.png'
24 OUTPUT_IMAGE_WIDTH
= 800
26 STATS
= """1/1/2003 70
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])
95 def get_ordinal_date(date
):
96 # This is the only way I can get matplotlib to do the dates right.
100 def parse_stats(str):
104 lines
= str.split('\n')
106 key
, val
= line
.split(' ', 1)
108 dates
.append(int(get_ordinal_date(get_date(key
))))
109 counts
.append(int(val
.lstrip()))
113 def draw_graph(dates
, counts
):
114 ###########################################################
115 # Drawing takes place here.
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')
134 ###########################################################
135 png
= open(OUTPUT_FILE
, 'w')
138 os
.rename(OUTPUT_FILE
, OUTPUT_FILE
+ ".tmp.png")
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")
151 sys
.stderr
.write("Error attempting to resize the graphic: %s\n" % (str(e
)))
152 os
.rename(OUTPUT_FILE
+ ".tmp.png", OUTPUT_FILE
)
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!"