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