aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/core/report.py
diff options
context:
space:
mode:
authorPatrice Buriez <patrice.buriez@intel.com>2018-11-09 10:45:31 +0100
committerPatrice Buriez <patrice.buriez@intel.com>2018-11-22 20:18:12 +0100
commit835411e9d454b9672081cb1ff3241c036f204b95 (patch)
tree196ff18ff2df48f2f679f7e9ff5bc6b01f2f45b4 /yardstick/benchmark/core/report.py
parentf4f0862633bfda306d86835325e6572362d7cfdd (diff)
Add parser to support jsTree in report
Allow the user to select what data to show in the report using jsTree to navigate a hierarchical metrics list. JIRA: YARDSTICK-1367 Topic: report/html_table (4 of 11) Change-Id: I86d782a0a70b80a1cdfaab2f41afb7668066cbf7 Signed-off-by: Emma Foley <emma.l.foley@intel.com> Signed-off-by: Patrice Buriez <patrice.buriez@intel.com>
Diffstat (limited to 'yardstick/benchmark/core/report.py')
-rw-r--r--yardstick/benchmark/core/report.py66
1 files changed, 63 insertions, 3 deletions
diff --git a/yardstick/benchmark/core/report.py b/yardstick/benchmark/core/report.py
index a43efecb7..a484a49f3 100644
--- a/yardstick/benchmark/core/report.py
+++ b/yardstick/benchmark/core/report.py
@@ -1,7 +1,7 @@
-#############################################################################
-# Copyright (c) 2017 Rajesh Kudaka
+##############################################################################
+# Copyright (c) 2017 Rajesh Kudaka <4k.rajesh@gmail.com>
+# Copyright (c) 2018 Intel Corporation.
#
-# Author: Rajesh Kudaka 4k.rajesh@gmail.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
@@ -22,6 +22,66 @@ from yardstick.common import constants as consts
from yardstick.common.utils import cliargs
+class JSTree(object):
+ """Data structure to parse data for use with the JS library jsTree"""
+ def __init__(self):
+ self._created_nodes = ['#']
+ self.jstree_data = []
+
+ def _create_node(self, _id):
+ """Helper method for format_for_jstree to create each node.
+
+ Creates the node (and any required parents) and keeps track
+ of the created nodes.
+
+ :param _id: (string) id of the node to be created
+ :return: None
+ """
+ components = _id.split(".")
+
+ if len(components) == 1:
+ text = components[0]
+ parent_id = "#"
+ else:
+ text = components[-1]
+ parent_id = ".".join(components[:-1])
+ # make sure the parent has been created
+ if not parent_id in self._created_nodes:
+ self._create_node(parent_id)
+
+ self.jstree_data.append({"id": _id, "text": text, "parent": parent_id})
+ self._created_nodes.append(_id)
+
+ def format_for_jstree(self, data):
+ """Format the data into the required format for jsTree.
+
+ The data format expected is a list of key-value pairs which represent
+ the data and name for each metric e.g.:
+
+ [{'data': [0, ], 'name': 'tg__0.DropPackets'},
+ {'data': [548, ], 'name': 'tg__0.LatencyAvg.5'},]
+
+ This data is converted into the format required for jsTree to group and
+ display the metrics in a hierarchial fashion, including creating a
+ number of parent nodes e.g.::
+
+ [{"id": "tg__0", "text": "tg__0", "parent": "#"},
+ {"id": "tg__0.DropPackets", "text": "DropPackets", "parent": "tg__0"},
+ {"id": "tg__0.LatencyAvg", "text": "LatencyAvg", "parent": "tg__0"},
+ {"id": "tg__0.LatencyAvg.5", "text": "5", "parent": "tg__0.LatencyAvg"},]
+
+ :param data: (list) data to be converted
+ :return: list
+ """
+ self._created_nodes = ['#']
+ self.jstree_data = []
+
+ for item in data:
+ self._create_node(item["name"])
+
+ return self.jstree_data
+
+
class Report(object):
"""Report commands.