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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
14 """Module holding BitCountingGroup class."""
16 from RunGroup import RunGroup
19 class BitCountingGroup(RunGroup):
20 """RunGroup with BitCountingMetadata.
22 Support with_run_added() method to simplify extending the group.
23 As bit content has to be re-counted, metadata factory is stored.
26 def __init__(self, metadata_factory, values=[]):
27 """Create the group from metadata factory and values.
29 :param metadata_factory: Factory object to create metadata with.
30 :param values: The runs belonging to this group.
31 :type metadata_factory: BitCountingMetadataFactory
32 :type values: Iterable of float or of AvgStdevMetadata
34 self.metadata_factory = metadata_factory
35 metadata = metadata_factory.from_data(values)
36 super(BitCountingGroup, self).__init__(metadata, values)
38 def with_run_added(self, value):
39 """Create and return a new group with one more run that self.
41 :param value: The run value to add to the group.
42 :type value: float or od AvgStdevMetadata
43 :returns: New group with the run added.
44 :rtype: BitCountingGroup
46 values = list(self.values)
48 return BitCountingGroup(self.metadata_factory, values)
49 # TODO: Is there a good way to save some computation
50 # by copy&updating the metadata incrementally?