support report html
* add a lin-chart mako * support more on result command * --html could report stdout instead pretty print Change-Id: I8819cc8ac375b9ae2ad4d3055704e617b82799f4
This commit is contained in:
parent
9bcd4a62df
commit
6a44daa26e
@ -5,3 +5,4 @@ sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
||||
psutil>=1.1.1,<2.0.0
|
||||
tooz>=1.19.0 # Apache-2.0
|
||||
PrettyTable>=0.7,<0.8
|
||||
Mako>=0.4.0
|
||||
|
@ -4,10 +4,15 @@
|
||||
|
||||
from scalpels.db import api as db_api
|
||||
from prettytable import PrettyTable
|
||||
from mako.template import Template
|
||||
from mako.lookup import TemplateLookup
|
||||
from scalpels import templates
|
||||
import os
|
||||
|
||||
|
||||
def pprint_result(result):
|
||||
t = PrettyTable(["timestamp", "%s(%s)" % (result.name, result.unit)])
|
||||
print "<task %s" % result.uuid
|
||||
t = PrettyTable(["timestamp", "%s (%s)" % (result.name, result.unit)])
|
||||
for data in result.data:
|
||||
t.add_row([data[0], data[1][:100]])
|
||||
print t
|
||||
@ -18,6 +23,15 @@ def get_last_task():
|
||||
last_task = db_api.task_get_last()
|
||||
return last_task
|
||||
|
||||
def generate_result_html(result):
|
||||
tmpl_dir = os.path.dirname(templates.__file__)
|
||||
lookup = TemplateLookup(directories=[tmpl_dir])
|
||||
t = lookup.get_template("line-chart.mako")
|
||||
print t.render(**result.__dict__)
|
||||
|
||||
def generate_multiple_result_html(result):
|
||||
raise NotImplementedError("%s is not impl" % "generate_multiple_result_html")
|
||||
|
||||
def run(config):
|
||||
uuid = config.get("uuid")
|
||||
last = config.get("last")
|
||||
|
@ -6,7 +6,21 @@ from scalpels.db import api as db_api
|
||||
from scalpels.cli.actions import report
|
||||
|
||||
def run(config):
|
||||
"""
|
||||
uuid: pprint it
|
||||
list: pprint all
|
||||
uuid and html: generate_result_html
|
||||
list and html: generate_multiple_result_html
|
||||
"""
|
||||
if config.get("list"):
|
||||
rets = db_api.get_all_results()
|
||||
for ret in rets:
|
||||
if config.get("html"):
|
||||
report.generate_multiple_result_html(rets)
|
||||
else:
|
||||
map(report.pprint_result, rets)
|
||||
elif config.get("uuid"):
|
||||
ret = db_api.result_get(config["uuid"])
|
||||
if config.get("html"):
|
||||
report.generate_result_html(ret)
|
||||
else:
|
||||
report.pprint_result(ret)
|
||||
|
@ -44,6 +44,8 @@ def main():
|
||||
# setup sca result --list
|
||||
result = subparsers.add_parser("result")
|
||||
result.add_argument("-l", "--list", action="store_true", dest="list", help="list all results from db")
|
||||
result.add_argument("uuid", type=str, default="", nargs="?", help="report the last task")
|
||||
result.add_argument("--html", action="store_true", dest="html", help="report html to stdout instead of pretty print")
|
||||
|
||||
parser = rootparser.parse_args()
|
||||
try:
|
||||
|
0
scalpels/templates/__init__.py
Normal file
0
scalpels/templates/__init__.py
Normal file
38
scalpels/templates/line-chart.mako
Normal file
38
scalpels/templates/line-chart.mako
Normal file
@ -0,0 +1,38 @@
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript"
|
||||
src="https://www.google.com/jsapi?autoload={
|
||||
'modules':[{
|
||||
'name':'visualization',
|
||||
'version':'1',
|
||||
'packages':['corechart']
|
||||
}]
|
||||
}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
google.setOnLoadCallback(drawChart);
|
||||
|
||||
function drawChart() {
|
||||
var data = google.visualization.arrayToDataTable([
|
||||
['Timestamp', '${unit}'],
|
||||
% for item in data:
|
||||
[${item[0]}, ${item[1]}],
|
||||
% endfor
|
||||
]);
|
||||
|
||||
var options = {
|
||||
title: '${name}',
|
||||
curveType: 'function',
|
||||
legend: { position: 'bottom' }
|
||||
};
|
||||
|
||||
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
|
||||
|
||||
chart.draw(data, options);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="curve_chart" style="width: 900px; height: 500px"></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user