From: "Vikraman Choudhury" <vikraman.choudhury@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
Date: Thu, 11 Aug 2011 20:41:07 +0000 (UTC) [thread overview]
Message-ID: <c6a27937f63a7629aeb235fb5ef8bef5c66aee78.vikraman@gentoo> (raw)
commit: c6a27937f63a7629aeb235fb5ef8bef5c66aee78
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Thu Aug 11 20:40:36 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Thu Aug 11 20:40:36 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=c6a27937
add barcharts for /arch and /keyword
---
server/arch.py | 7 ++++++-
server/helpers.py | 25 +++++++++++++++++++++++++
server/kwd.py | 7 ++++++-
server/templates/arch.html | 4 +++-
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" />
next reply other threads:[~2011-08-11 20:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-11 20:41 Vikraman Choudhury [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-08-03 23:45 [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/ Vikraman Choudhury
2011-08-03 21:52 Vikraman Choudhury
2011-07-17 21:51 Vikraman Choudhury
2011-07-09 17:09 Vikraman Choudhury
2011-07-07 19:40 Vikraman Choudhury
2011-07-07 16:02 Vikraman Choudhury
2011-07-03 18:04 Vikraman Choudhury
2011-06-14 17:43 Vikraman Choudhury
2011-05-06 14:42 Vikraman Choudhury
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c6a27937f63a7629aeb235fb5ef8bef5c66aee78.vikraman@gentoo \
--to=vikraman.choudhury@gmail.com \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox