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 from RunGroup import RunGroup
17 class BitCountingGroup(RunGroup):
19 def __init__(self, metadata_factory, values=[]):
20 """Create the group from metadata factory and values.
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
27 self.metadata_factory = metadata_factory
28 metadata = metadata_factory.from_data(values)
29 super(BitCountingGroup, self).__init__(metadata, values)
31 def with_run_added(self, value):
32 """Create and return a new group with one more run that self.
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
39 values = list(self.values)
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?