Merge "support generate multi results in one html"

This commit is contained in:
Jenkins 2015-10-30 10:04:53 +00:00 committed by Gerrit Code Review
commit 835eadd205
4 changed files with 58 additions and 4 deletions

View File

@ -30,8 +30,12 @@ def generate_result_html(result):
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 generate_multiple_result_html(results):
tmpl_dir = os.path.dirname(templates.__file__)
lookup = TemplateLookup(directories=[tmpl_dir])
t = lookup.get_template("multi-line-chart.mako")
d = {"results": results}
print t.render(**d)
def run(config):
uuid = config.get("uuid")
@ -52,6 +56,11 @@ def run(config):
print "command report: %s" % config
print "task: <%s>" % task.uuid
rets = []
for ret_uuid in task.results:
ret = db_api.result_get(ret_uuid)
pprint_result(ret)
rets.append(ret)
if config.get("html"):
generate_multiple_result_html(rets)
else:
map(pprint_result, rets)

View File

@ -34,6 +34,7 @@ def main():
# setup report actions
report = subparsers.add_parser("report")
report.add_argument("--last", action="store_true", dest="last", help="report the last task")
report.add_argument("--html", action="store_true", dest="html", help="report html to stdout instead of pretty print")
report.add_argument("uuid", type=str, default="", nargs="?", help="report the last task")
# setup re-setup actions

View File

@ -0,0 +1,43 @@
<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() {
% for ret in results:
var data_${ret.id} = google.visualization.arrayToDataTable([
['Timestamp', '${ret.unit}'],
% for item in ret.data:
[${item[0]}, ${item[1]}],
% endfor
]);
var options_${ret.id} = {
title: '${ret.name}',
curveType: 'function',
legend: { position: 'bottom' }
};
var chart_${ret.id} = new google.visualization.LineChart(document.getElementById('chart_${ret.id}'));
chart_${ret.id}.draw(data_${ret.id}, options_${ret.id});
% endfor
}
</script>
</head>
<body>
% for ret in results:
<div id="chart_${ret.id}" style="width: 1600px; height: 200px"></div>
% endfor
</body>
</html>

View File

@ -32,5 +32,6 @@ sleep 120
sca stop
for i in `sca result --list --short | tail -n2`; do
sca result $i --html > $BASE/logs/scalpels-test-$i.html
sca result $i --html > $BASE/logs/scalpels-result-$i.html
done
sca report --html > $BASE/logs/scalpels-report.html