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.
14 """Module for holding AvgStdevMetadata class."""
16 from AbstractGroupMetadata import AbstractGroupMetadata
19 class AvgStdevMetadata(AbstractGroupMetadata):
20 """Class for metadata specifying the average and standard deviation."""
22 def __init__(self, size=0, avg=0.0, stdev=0.0):
23 """Construct the metadata by setting the values needed.
25 The values are sanitized, so faulty callers to not cause math errors.
27 :param size: Number of values participating in this group.
28 :param avg: Population average of the participating sample values.
29 :param stdev: Population standard deviation of the sample values.
34 self.size = size if size >= 0 else 0
35 self.avg = avg if size >= 1 else 0.0
36 self.stdev = stdev if size >= 2 else 0.0
39 """Return string with human readable description of the group.
41 :returns: Readable description.
44 return "size={size} avg={avg} stdev={stdev}".format(
45 size=self.size, avg=self.avg, stdev=self.stdev)
48 """Return string executable as Python constructor call.
50 :returns: Executable constructor call.
53 return "AvgStdevMetadata(size={size},avg={avg},stdev={stdev})".format(
54 size=self.size, avg=self.avg, stdev=self.stdev)