efc1a90cd4c0920891625c31137e7f17052d5ae1
[csit.git] / resources / tools / presentation / new / jumpavg / AvgStdevMetadata.py
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """Module for holding AvgStdevMetadata class."""
15
16 from AbstractGroupMetadata import AbstractGroupMetadata
17
18
19 class AvgStdevMetadata(AbstractGroupMetadata):
20     """Class for metadata specifying the average and standard deviation."""
21
22     def __init__(self, size=0, avg=0.0, stdev=0.0):
23         """Construct the metadata by setting the values needed.
24
25         The values are sanitized, so faulty callers to not cause math errors.
26
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.
30         :type size: int
31         :type avg: float
32         :type stdev: float
33         """
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
37
38     def __str__(self):
39         """Return string with human readable description of the group.
40
41         :returns: Readable description.
42         :rtype: str
43         """
44         return "size={size} avg={avg} stdev={stdev}".format(
45             size=self.size, avg=self.avg, stdev=self.stdev)
46
47     def __repr__(self):
48         """Return string executable as Python constructor call.
49
50         :returns: Executable constructor call.
51         :rtype: str
52         """
53         return "AvgStdevMetadata(size={size},avg={avg},stdev={stdev})".format(
54             size=self.size, avg=self.avg, stdev=self.stdev)