CSIT-1110: Integrate anomaly detection into PAL
[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
15 class AvgStdevMetadata(object):
16     """Class for metadata specifying the average and standard deviation."""
17
18     def __init__(self, size=0, avg=0.0, stdev=0.0):
19         """Construct the metadata by setting the values needed.
20
21         The values are sanitized, so faulty callers to not cause math errors.
22
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.
26         :type size: int
27         :type avg: float
28         :type stdev: float
29         """
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
33
34     def __str__(self):
35         """Return string with human readable description of the group.
36
37         :returns: Readable description.
38         :rtype: str
39         """
40         return "size={size} avg={avg} stdev={stdev}".format(
41             size=self.size, avg=self.avg, stdev=self.stdev)
42
43     def __repr__(self):
44         """Return string executable as Python constructor call.
45
46         :returns: Executable constructor call.
47         :rtype: str
48         """
49         return "AvgStdevMetadata(size={size},avg={avg},stdev={stdev})".format(
50             size=self.size, avg=self.avg, stdev=self.stdev)