1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
15 class AvgStdevMetadata(object):
16 """Class for metadata specifying the average and standard deviation."""
18 def __init__(self, size=0, avg=0.0, stdev=0.0):
19 """Construct the metadata by setting the values needed.
21 The values are sanitized, so faulty callers to not cause math errors.
23 :param size: Number of values participating in this group.
24 :param avg: Population average of the participating sample values.
25 :param stdev: Population standard deviation of the sample values.
30 self.size = size if size >= 0 else 0
31 self.avg = avg if size >= 1 else 0.0
32 self.stdev = stdev if size >= 2 else 0.0
35 """Return string with human readable description of the group.
37 :returns: Readable description.
40 return "size={size} avg={avg} stdev={stdev}".format(
41 size=self.size, avg=self.avg, stdev=self.stdev)
44 """Return string executable as Python constructor call.
46 :returns: Executable constructor call.
49 return "AvgStdevMetadata(size={size},avg={avg},stdev={stdev})".format(
50 size=self.size, avg=self.avg, stdev=self.stdev)