144f5a87803e77b6be0792958c02607ce41720fa
[csit.git] / resources / tools / presentation / new / jumpavg / BitCountingGroup.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 RunGroup import RunGroup
15
16
17 class BitCountingGroup(RunGroup):
18
19     def __init__(self, metadata_factory, values=[]):
20         """Create the group from metadata factory and values.
21
22         :param metadata_factory: Factory object to create metadata with.
23         :param values: The runs belonging to this group.
24         :type metadata_factory: BitCountingMetadataFactory
25         :type values: Iterable of float or of AvgStdevMetadata
26         """
27         self.metadata_factory = metadata_factory
28         metadata = metadata_factory.from_data(values)
29         super(BitCountingGroup, self).__init__(metadata, values)
30
31     def with_run_added(self, value):
32         """Create and return a new group with one more run that self.
33
34         :param value: The run value to add to the group.
35         :type value: float or od AvgStdevMetadata
36         :returns: New group with the run added.
37         :rtype: BitCountingGroup
38         """
39         values = list(self.values)
40         values.append(value)
41         return BitCountingGroup(self.metadata_factory, values)
42         # TODO: Is there a good way to save some computation
43         # by copy&updating the metadata incrementally?