Implements basic observer pattern, with a register and trigger function.
Implements a list with the observer patter. If the list changes all registered callbacks will be executed.
Abstaract base class for dataset descriptors. Inherited classes are required to implement a calculate_description
function, that calculates the specific stats about a dataset one wants. For more information on how they are used see: GenericDataset
.
Descriptor for strings. Mainly used for name and description of a dataset (see GenericDataset
).
Generic base class for datasets that implements the basic control mechanisms. The idea behind the controll mechanism is, that if changes to the underlying data are made the changes to the infered data
can be propagated without explicit calls after each change. To achive this information that is infered from the underlying data needs to be defined as a descriptor. The easiest way is to inherit from DatasetDescriptor
and define the calculate_description
method. To have the changes in the underlying data propagated the reset_infered_data
function is provided. The base_data
should be of a type that has the observer pattern implemented, then the reset_infered_data
method can just be registered.
class DatasetStatsDescriptor(DatasetDescriptor):
"Simpel dataset descriptor that is a dict with the keys: name, description and num_data_points [len(obj.base_data)]"
def calculate_description(self, obj):
return {"name": obj.name, "description": obj.description, "num_data_points": len(obj.base_data)}
class TestDataset(GenericDataset):
stats = DatasetStatsDescriptor()
def __init__(self):
data = ObservableList([1,2,3])
super().__init__(data, name="name", description="description")
self.stats = None
# register the reset hook
self.base_data.register_callback(self.reset_infered_data)
test_dataset = TestDataset()
print("Stats before update: ", test_dataset.stats)
# if we change the data the stats automatically update
test_dataset.base_data.append(4)
print("Stats after update: ", test_dataset.stats)