[shell-perf-web] Add a basic report view
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shell-perf-web] Add a basic report view
- Date: Wed, 26 May 2010 14:35:31 +0000 (UTC)
commit 69428d6207b6142d36f91001a3d9eacc6066b7c3
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Sat May 22 23:20:32 2010 -0400
Add a basic report view
Add a page that shows a table with the different runs of the
report; link to that from the column headers of the system view.
shell/perf/report_table.py | 47 ++++++++++++++++++++++++++++++++++++++
shell/perf/views.py | 44 +++++++++++++++++++++++++++++++++-
shell/urls.py | 4 +++
static/shell-perf.css | 4 +++
templates/pages/report_view.html | 26 +++++++++++++++++++++
5 files changed, 123 insertions(+), 2 deletions(-)
---
diff --git a/shell/perf/report_table.py b/shell/perf/report_table.py
index 6e7ed52..a55ca90 100644
--- a/shell/perf/report_table.py
+++ b/shell/perf/report_table.py
@@ -48,3 +48,50 @@ class ReportTable:
def rows(self):
self.__get_data()
return self.__rows
+
+# This provides an identical interface to ReportTable, but instead
+# of comparing reports, it compares runs in one report
+class RunTable:
+ def __init__(self, report_json):
+ self.json = report_json
+ self.reports = []
+ self.__col_headers = None
+ self.__rows = None
+
+ def __get_data(self):
+ if self.__rows != None:
+ return
+
+ self.__col_headers = []
+ self.__rows = []
+
+ metrics = self.json['metrics']
+ metric_names = sorted(metrics.keys())
+
+ if len(metric_names) == 0:
+ return
+
+ first_metric = metrics[metric_names[0]]
+ self.__col_headers = []
+ for i in xrange(0, len(first_metric['values'])):
+ self.__col_headers.append({ 'name': "Run %d" % (i + 1),
+ 'link': None })
+
+ for name in metric_names:
+ metric = metrics[name]
+ # For ReportTable, row.metric is a Metric object, here it's just a dictionary
+ # that looks much the same to to the template
+ self.__rows.append({ 'metric': { 'name': name,
+ 'description': metric['description'],
+ 'units': metric['units'] },
+ 'values': metric['values'] })
+
+ @property
+ def col_headers(self):
+ self.__get_data()
+ return self.__col_headers
+
+ @property
+ def rows(self):
+ self.__get_data()
+ return self.__rows
diff --git a/shell/perf/views.py b/shell/perf/views.py
index dc56b5f..481c1ea 100644
--- a/shell/perf/views.py
+++ b/shell/perf/views.py
@@ -15,7 +15,7 @@ from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbid
from django.views.decorators.http import require_POST
from models import Metric, System, SystemEdit, Report
-from report_table import ReportTable
+from report_table import ReportTable, RunTable
from system_form import SystemForm, NameField
import signed_request
import util
@@ -212,6 +212,45 @@ def _do_edit(system, form):
return edit
+def report_json(request, system_name, report_id):
+ try:
+ report = Report.objects.get(id=report_id)
+ except Report.DoesNotExist:
+ raise Http404
+
+ if system_name != report.system.name:
+ raise Http404
+
+ response = HttpResponse(mimetype="application/json")
+
+ gunzip = GzipFile(report.upload.path, "r")
+ reportContents = gunzip.read()
+
+ return HttpResponse(reportContents, mimetype="application/json")
+
+def report_view(request, system_name, report_id):
+ try:
+ report = Report.objects.get(id=report_id)
+ except Report.DoesNotExist:
+ raise Http404
+
+ if system_name != report.system.name:
+ raise Http404
+
+ gunzip = GzipFile(report.upload.path, "r")
+ report_contents = gunzip.read()
+ report_json = json.loads(report_contents)
+
+ run_table = RunTable(report_json)
+
+ return render_to_response('pages/report_view.html',
+ { 'page': 'report_view',
+ 'page_title': report.system.name,
+ 'settings': settings,
+ 'report': report,
+ 'report_json': report_json,
+ 'report_table': run_table})
+
def system_edit(request, system_name):
try:
system = System.objects.get(name=system_name)
@@ -381,7 +420,8 @@ def system_view(request, system_name):
report_table = ReportTable()
for report in reports:
report_table.add_report(report,
- report.date.strftime("%y-%m-%d"))
+ report.date.strftime("%y-%m-%d"),
+ "report/%s/%d" % (system.name, report.id))
return render_to_response('pages/system_view.html',
{ 'page': 'system_view',
diff --git a/shell/urls.py b/shell/urls.py
index a6c75bf..0e34ccf 100644
--- a/shell/urls.py
+++ b/shell/urls.py
@@ -8,6 +8,10 @@ urlpatterns = patterns('',
(r'^confirm_edit$', 'shell.perf.views.confirm_edit'),
(r'^home$', 'shell.perf.views.home'),
(r'^register$', 'shell.perf.views.register'),
+ # The system name is included in the report URls only to make the
+ # the URLs more self-documenting
+ (r'^report/(?P<system_name>[^/]+)/(?P<report_id>\d+)/json$', 'shell.perf.views.report_json'),
+ (r'^report/(?P<system_name>[^/]+)/(?P<report_id>\d+)$', 'shell.perf.views.report_view'),
(r'^system/(?P<system_name>[^/]+)/admin$', 'shell.perf.views.system_admin'),
(r'^system/(?P<system_name>[^/]+)/edit$', 'shell.perf.views.system_edit'),
(r'^system/(?P<system_name>[^/]+)/mail_key$', 'shell.perf.views.system_mail_key'),
diff --git a/static/shell-perf.css b/static/shell-perf.css
index ed48d4e..fdb9568 100644
--- a/static/shell-perf.css
+++ b/static/shell-perf.css
@@ -132,6 +132,10 @@ a:hover {
margin-bottom: 1em;
}
+.report-info {
+ margin-bottom: 1em;
+}
+
#formGroup {
border: 1px solid #888888;
background: white;
diff --git a/templates/pages/report_view.html b/templates/pages/report_view.html
new file mode 100644
index 0000000..94372af
--- /dev/null
+++ b/templates/pages/report_view.html
@@ -0,0 +1,26 @@
+{% extends "base.html" %}
+
+{% block main %}
+
+<table class="report-info">
+ <tr>
+ <td>System:</td>
+ <td><a href="system/{{ report.system.name }}">{{ report.system.name }}</a></td>
+ </tr>
+ <tr>
+ <td>Date:</td>
+ <td>{{ report.date|date:"Y-m-d H:i" }}</td>
+ </tr>
+ <tr>
+ <td>Revision:</td>
+ <td>{{ report_json.revision|slice:":10" }}</td>
+ </tr>
+ <tr>
+ <td>Monitor layout:</td>
+ <td>{{ report_json.monitors|join:" " }}</td>
+ </tr>
+</table>
+
+{% include "include/report_table.html" %}
+
+{% endblock %}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]