]> git.donarmstrong.com Git - neurodebian.git/blobdiff - tools/nd_apachelogs2subscriptionstats
Help stats script to deal with fresh ubuntu precise
[neurodebian.git] / tools / nd_apachelogs2subscriptionstats
index d16ab3713dffbbd4221e1cf6dae9cd72c4882216..0bae742a45c2db947134231ac57c28eac41c8e81 100755 (executable)
@@ -24,12 +24,12 @@ dt = [('ip', '|S16'),
       ('date', float)]
 
 
-def make_figure(data):
-    fig = pl.figure(figsize=(12,3))
+def make_figure(data, ymax):
+    fig = pl.figure(figsize=(14,3))
     ax = fig.add_subplot(121)
-    plot_datehist(ax, data, 10, [code for code in cfg.options('release codenames') if cfg.get('release codenames', code).count('Debian')], title="Debian", ymax=10)
+    plot_datehist(ax, data, 10, [code for code in cfg.options('release codenames') if cfg.get('release codenames', code).count('Debian')], title="Debian", ymax=ymax)
     ax = fig.add_subplot(122)
-    plot_datehist(ax, data, 10, [code for code in cfg.options('release codenames') if cfg.get('release codenames', code).count('Ubuntu')], title="Ubuntu", ymax=10)
+    plot_datehist(ax, data, 10, [code for code in cfg.options('release codenames') if cfg.get('release codenames', code).count('Ubuntu')], title="Ubuntu", ymax=ymax)
     fig.autofmt_xdate()
     return fig
 
@@ -47,6 +47,10 @@ def plot_datehist(ax, data, bins, suites, title=None, ymax=None):
         # make approx monthly bins, smaller bins yield spiky curves
         # needs new=True to work with oldish numpy
         (hist, bin_edges) = np.histogram(dates, np.ceil(history_length/30.), new=True)
+        if len(bin_edges) < 2:
+            # protect against single data point entries by ignoring them
+            # wouldn't be able to draw a line anyway ;-)
+            continue
         width = bin_edges[1] - bin_edges[0]
         # think lines
         ax.plot(bin_edges[:-1]+(width/2), hist / width,
@@ -104,4 +108,4 @@ if __name__ == '__main__':
         date = datetime.strptime(date, "%d %b %Y")
         data.append((ip.strip(), loc, suite, date2num(date)))
     data = np.array(data, dtype=dt)
-    make_figure(data).savefig(sys.argv[1], bbox_inches='tight', dpi=60)
+    make_figure(data, ymax=13).savefig(sys.argv[1], bbox_inches='tight', dpi=60)