Multiple lines in charts

This commit is contained in:
Ilya Shakhat 2016-02-19 18:18:37 +03:00
parent d62c59df34
commit 29660a67ac
2 changed files with 27 additions and 11 deletions

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import collections
import errno import errno
import functools import functools
import os import os
@ -36,6 +37,7 @@ def generate_chart(chart_str, records_collection, doc_folder, tag):
chart = yaml.safe_load(chart_str) chart = yaml.safe_load(chart_str)
pipeline = chart.get('pipeline') pipeline = chart.get('pipeline')
title = chart.get('title') title = chart.get('title')
fill = chart.get('fill') or False
axes = chart.get('axes') or dict(x='x', y='y') axes = chart.get('axes') or dict(x='x', y='y')
if tag: if tag:
@ -43,28 +45,35 @@ def generate_chart(chart_str, records_collection, doc_folder, tag):
chart_data = records_collection.aggregate(pipeline) chart_data = records_collection.aggregate(pipeline)
line = [] lines = collections.defaultdict(list)
table = ''' table = '''
.. list-table:: %(title)s .. list-table:: %(title)s
:header-rows: 1 :header-rows: 1
* - %(x)s *
- %(y)s ''' % dict(title=title)
''' % dict(title=title, x=axes['x'], y=axes['y'])
table += ''.join((' - %s\n' % axes[k]) for k in sorted(axes.keys()))
y_keys = set(axes.keys()) ^ set('x')
for chart_rec in chart_data: for chart_rec in chart_data:
line.append((chart_rec['x'], chart_rec['y'])) for k in y_keys:
lines[k].append((chart_rec['x'], chart_rec[k]))
table += (' *\n' + table += (' *\n' +
'\n'.join(' - %d' % chart_rec[v] for v in ('x', 'y')) + '\n'.join(' - %d' % chart_rec[v]
for v in sorted(axes.keys())) +
'\n') '\n')
xy_chart = pygal.XY(style=style.RedBlueStyle, xy_chart = pygal.XY(style=style.RedBlueStyle,
fill=True, fill=fill,
legend_at_bottom=True, legend_at_bottom=True,
include_x_axis=True, include_x_axis=True,
x_title=axes['x']) x_title=axes['x'])
xy_chart.add(axes['y'], line)
for k in y_keys:
xy_chart.add(axes[k], lines[k])
chart_filename = utils.strict(title) chart_filename = utils.strict(title)
abs_chart_filename = '%s.svg' % os.path.join(doc_folder, chart_filename) abs_chart_filename = '%s.svg' % os.path.join(doc_folder, chart_filename)
@ -130,7 +139,7 @@ def main():
base_dir = os.path.dirname(scenario_file_path) base_dir = os.path.dirname(scenario_file_path)
generate_report(scenario, base_dir, cfg.CONF.mongo_url, cfg.CONF.mongo_db, generate_report(scenario, base_dir, cfg.CONF.mongo_url, cfg.CONF.mongo_db,
cfg.CONF.book) cfg.CONF.book, cfg.CONF.tag)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -14,11 +14,18 @@ Chart and table:
axes: axes:
x: threads x: threads
y: queries per sec y: queries per sec
y2: read queries per sec
chart: line chart: line
pipeline: pipeline:
- { $match: { class: sysbench-oltp, status: OK }} - { $match: { class: sysbench-oltp, status: OK }}
- { $group: { _id: { threads: "$threads" }, queries_total_per_sec: { $avg: { $divide: ["$queries_total", "$duration"] }}}} - { $group: { _id: { threads: "$threads" },
- { $project: { x: "$_id.threads", y: "$queries_total_per_sec" }} queries_total_per_sec: { $avg: { $divide: ["$queries_total", "$duration"] }},
queries_read_per_sec: { $avg: { $divide: ["$queries_read", "$duration"] }}
}}
- { $project: { x: "$_id.threads",
y: "$queries_total_per_sec",
y2: "$queries_read_per_sec"
}}
- { $sort: { x: 1 }} - { $sort: { x: 1 }}
''' | chart ''' | chart
}} }}