aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark
diff options
context:
space:
mode:
authorEmma Foley <emma.l.foley@intel.com>2019-01-24 15:19:44 +0000
committerEmma Foley <emma.l.foley@intel.com>2019-02-11 11:53:20 +0000
commit0738c2544e3220a3e0fd80a77ab1f2800f90533e (patch)
tree5a059cd563d32f2cb2c65a48781376b1819988a3 /yardstick/benchmark
parente815d4190f8cedfd6884959842b7da9452f0ba50 (diff)
Refactor: add _format_datasets
JIRA: YARDSTICK-1593 Change-Id: I8d2c8665d767c92da20db8f97690f20da4a68908 Signed-off-by: Emma Foley <emma.l.foley@intel.com>
Diffstat (limited to 'yardstick/benchmark')
-rw-r--r--yardstick/benchmark/core/report.py72
1 files changed, 41 insertions, 31 deletions
diff --git a/yardstick/benchmark/core/report.py b/yardstick/benchmark/core/report.py
index b7d2fd02b..30ba243c3 100644
--- a/yardstick/benchmark/core/report.py
+++ b/yardstick/benchmark/core/report.py
@@ -138,6 +138,46 @@ class Report(object):
timestamps.append(metric_time) # HH:MM:SS.micros
return timestamps
+ def _format_datasets(self, metric_name, metrics):
+ values = []
+ for metric in metrics:
+ val = metric.get(metric_name, None)
+ if val is None:
+ # keep explicit None or missing entry as is
+ pass
+ elif isinstance(val, (int, float)):
+ # keep plain int or float as is
+ pass
+ elif six.PY2 and isinstance(val,
+ long): # pylint: disable=undefined-variable
+ # PY2: long value would be rendered with trailing L,
+ # which JS does not support, so convert it to float
+ val = float(val)
+ elif isinstance(val, six.string_types):
+ s = val
+ if not isinstance(s, str):
+ s = s.encode('utf8') # PY2: unicode to str
+ try:
+ # convert until failure
+ val = s
+ val = float(s)
+ val = int(s)
+ if six.PY2 and isinstance(val,
+ long): # pylint: disable=undefined-variable
+ val = float(val) # PY2: long to float
+ except ValueError:
+ # value may have been converted to a number
+ pass
+ finally:
+ # if val was not converted into a num, then it must be
+ # text, which shouldn't end up in the report
+ if isinstance(val, six.string_types):
+ val = None
+ else:
+ raise ValueError("Cannot convert %r" % val)
+ values.append(val)
+ return values
+
@cliargs("task_id", type=str, help=" task id", nargs=1)
@cliargs("yaml_name", type=str, help=" Yaml file Name", nargs=1)
def _generate_common(self, args):
@@ -174,37 +214,7 @@ class Report(object):
# extract and convert field values
for key in field_keys:
- values = []
- for metric in db_metrics:
- val = metric.get(key, None)
- if val is None:
- # keep explicit None or missing entry as is
- pass
- elif isinstance(val, (int, float)):
- # keep plain int or float as is
- pass
- elif six.PY2 and isinstance(val,
- long): # pylint: disable=undefined-variable
- # PY2: long value would be rendered with trailing L,
- # which JS does not support, so convert it to float
- val = float(val)
- elif isinstance(val, six.string_types):
- s = val
- if not isinstance(s, str):
- s = s.encode('utf8') # PY2: unicode to str
- try:
- # convert until failure
- val = s
- val = float(s)
- val = int(s)
- if six.PY2 and isinstance(val,
- long): # pylint: disable=undefined-variable
- val = float(val) # PY2: long to float
- except ValueError:
- pass
- else:
- raise ValueError("Cannot convert %r" % val)
- values.append(val)
+ values = self._format_datasets(key, db_metrics)
datasets.append({'label': key, 'data': values})
table_vals[key] = values