diff options
author | Vikraman Choudhury <vikraman.choudhury@gmail.com> | 2011-08-12 02:10:36 +0530 |
---|---|---|
committer | Vikraman Choudhury <vikraman.choudhury@gmail.com> | 2011-08-12 02:10:36 +0530 |
commit | c6a27937f63a7629aeb235fb5ef8bef5c66aee78 (patch) | |
tree | 9fea7200f38eb1f26b2a9b00c7a2d4c633196f0b /server | |
parent | mv profile.py to profiles.py due to name conflicts (diff) | |
download | gentoostats-c6a27937f63a7629aeb235fb5ef8bef5c66aee78.tar.gz gentoostats-c6a27937f63a7629aeb235fb5ef8bef5c66aee78.tar.bz2 gentoostats-c6a27937f63a7629aeb235fb5ef8bef5c66aee78.zip |
add barcharts for /arch and /keyword
Diffstat (limited to 'server')
-rw-r--r-- | server/arch.py | 7 | ||||
-rw-r--r-- | server/helpers.py | 25 | ||||
-rw-r--r-- | server/kwd.py | 7 | ||||
-rw-r--r-- | server/templates/arch.html | 4 | ||||
-rw-r--r-- | server/templates/keyword.html | 4 |
5 files changed, 43 insertions, 4 deletions
diff --git a/server/arch.py b/server/arch.py index 20dde69..814c7c4 100644 --- a/server/arch.py +++ b/server/arch.py @@ -11,4 +11,9 @@ class Arch(object): if helpers.is_json_request(): return helpers.serialize(arch_data) else: - return render.arch(arch_data) + x_ticklabels = arch_data.keys() + y_values = [ arch_data[a]['HOSTS'] for a in x_ticklabels ] + arch_plot = helpers.barchart(title = 'Hosts per arch', x_label = 'Arch', + y_label = 'Number of Hosts', x_ticklabels = x_ticklabels, + y_values = y_values) + return render.arch(arch_data, arch_plot) diff --git a/server/helpers.py b/server/helpers.py index a5977be..5b81cb3 100644 --- a/server/helpers.py +++ b/server/helpers.py @@ -3,8 +3,16 @@ import web import json import uuid import re +import StringIO +import base64 from portage.versions import catpkgsplit +# matplotlib requires a writable home directory +import os +os.environ['HOME'] = '/tmp' +from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas +from matplotlib.figure import Figure + # check valid uuid def is_uuid(uuid): @@ -118,3 +126,20 @@ def serialize(object, human=True): else: indent = None return json.JSONEncoder(indent=indent).encode(object) + +def barchart(title, x_label, x_ticklabels, y_label, y_values): + fig = Figure() + canvas = FigureCanvas(fig) + ind = range(len(y_values)) + + ax = fig.add_subplot(1, 1, 1) + ax.set_title(title) + ax.set_xlabel(x_label) + ax.set_ylabel(y_label) + ax.set_xticks(ind) + ax.set_xticklabels(x_ticklabels) + ax.bar(ind, y_values, align='center') + + ret = StringIO.StringIO() + canvas.print_figure(ret) + return base64.b64encode(ret.getvalue()) diff --git a/server/kwd.py b/server/kwd.py index b8c50cd..779ac61 100644 --- a/server/kwd.py +++ b/server/kwd.py @@ -11,4 +11,9 @@ class Keyword(object): if helpers.is_json_request(): return helpers.serialize(keyword_data) else: - return render.keyword(keyword_data) + x_ticklabels = keyword_data.keys() + y_values = [ keyword_data[k]['PACKAGES'] for k in x_ticklabels ] + keyword_plot = helpers.barchart(title = 'Installed packages per keyword', + x_label = 'Keyword', y_label = 'Number of Packages', + x_ticklabels = x_ticklabels, y_values = y_values) + return render.keyword(keyword_data, keyword_plot) diff --git a/server/templates/arch.html b/server/templates/arch.html index 04ddcf6..8decac5 100644 --- a/server/templates/arch.html +++ b/server/templates/arch.html @@ -1,4 +1,4 @@ -$def with (arch_data) +$def with (arch_data, arch_plot) $var title: Arch <table border="1"> @@ -9,3 +9,5 @@ $var title: Arch $for arch in arch_data.keys(): <tr><td>$arch</td><td>$arch_data[arch]['HOSTS']</td></tr> </table> + +<img src="data:image/png;base64,$arch_plot"/> diff --git a/server/templates/keyword.html b/server/templates/keyword.html index 2dee5ea..608693f 100644 --- a/server/templates/keyword.html +++ b/server/templates/keyword.html @@ -1,4 +1,4 @@ -$def with (keyword_data) +$def with (keyword_data, keyword_plot) $var title: Keyword <table border="1"> @@ -10,3 +10,5 @@ $var title: Keyword $for keyword in keyword_data.keys(): <tr><td>$keyword</td><td>$keyword_data[keyword]['HOSTS']</td><td>$keyword_data[keyword]['PACKAGES']</td></tr> </table> + +<img src="data:image/png;base64,$keyword_plot" /> |