9a7277bc3e356bf0171b02f9a46b463b19155494
[csit.git] / resources / tools / presentation / new / jumpavg / ClassifiedBitCountingMetadata.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 from BitCountingMetadata import BitCountingMetadata
15
16
17 class ClassifiedBitCountingMetadata(BitCountingMetadata):
18     """Class for metadata which includes classification."""
19
20     def __init__(
21             self, max_value, size=0, avg=0.0, stdev=0.0, prev_avg=None,
22             classification=None):
23         """Delegate to ancestor constructors and set classification.
24
25         :param max_value: Maximal expected value.
26         :param size: Number of values participating in this group.
27         :param avg: Population average of the participating sample values.
28         :param stdev: Population standard deviation of the sample values.
29         :param prev_avg: Population average of the previous group.
30             If None, no previous average is taken into account.
31             If not None, the given previous average is used to discourage
32             consecutive groups with similar averages
33             (opposite triangle distribution is assumed).
34         :param classification: Arbitrary object classifying this group.
35         :type max_value: float
36         :type size: int
37         :type avg: float
38         :type stdev: float
39         :type prev_avg: float
40         :type classification: object
41         """
42         super(ClassifiedBitCountingMetadata, self).__init__(
43             max_value, size, avg, stdev, prev_avg)
44         self.classification = classification
45
46     def __str__(self):
47         """Return string with human readable description of the group.
48
49         :returns: Readable description.
50         :rtype: str
51         """
52         # str(super(...)) describes the proxy, not the proxied object.
53         super_str = super(ClassifiedBitCountingMetadata, self).__str__()
54         return super_str + " classification={classification}".format(
55             classification=self.classification)
56
57     def __repr__(self):
58         """Return string executable as Python constructor call.
59
60         :returns: Executable constructor call.
61         :rtype: str
62         """
63         return ("ClassifiedBitCountingMetadata(max_value={max_value}," +
64                 "size={size},avg={avg},stdev={stdev},prev_avg={prev_avg}," +
65                 "classification={cls})").format(
66                     max_value=self.max_value, size=self.size, avg=self.avg,
67                     stdev=self.stdev, prev_avg=self.prev_avg,
68                     cls=self.classification)