Telemetry: Don't use scientific notation for floats when printing results.
When parsing results for the dashboard we don't expect any letters (such as the 'e' in scientific notation) in the string of values. This CL makes sure we don't use scientific notation for printing floats. BUG=318093 Review URL: https://codereview.chromium.org/71543002 git-svn-id: http://src.chromium.org/svn/trunk/src/build@234829 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
4ec19bbee7
Коммит
1fdc0ea16e
|
@ -63,18 +63,26 @@ def GeomMeanAndStdDevFromHistogram(histogram_json):
|
|||
return geom_mean, math.sqrt(sum_of_squares / count)
|
||||
|
||||
|
||||
def _ValueToString(v):
|
||||
# Special case for floats so we don't print using scientific notation.
|
||||
if isinstance(v, float):
|
||||
return '%f' % v
|
||||
else:
|
||||
return str(v)
|
||||
|
||||
|
||||
def _MeanAndStdDevFromList(values):
|
||||
avg = None
|
||||
sd = None
|
||||
if len(values) > 1:
|
||||
try:
|
||||
value = '[%s]' % ','.join([str(v) for v in values])
|
||||
value = '[%s]' % ','.join([_ValueToString(v) for v in values])
|
||||
avg = sum([float(v) for v in values]) / len(values)
|
||||
sqdiffs = [(float(v) - avg) ** 2 for v in values]
|
||||
variance = sum(sqdiffs) / (len(values) - 1)
|
||||
sd = math.sqrt(variance)
|
||||
except ValueError:
|
||||
value = ", ".join(values)
|
||||
value = ', '.join(values)
|
||||
else:
|
||||
value = values[0]
|
||||
return value, avg, sd
|
||||
|
|
Загрузка…
Ссылка в новой задаче