The basic data structures are defined here.

class Observable[source]

Observable(callbacks=None) :: ABC

Simple implementation of the observer pattern.

Implements basic observer pattern, with a register and trigger function.

class ObservableList[source]

ObservableList(observable_list:list, callbacks=None) :: Observable

List with observer pattern. The internal list prepresentation can be accessed with the list attribute

Implements a list with the observer patter. If the list changes all registered callbacks will be executed.

class DatasetDescriptor[source]

DatasetDescriptor() :: ABC

Abstract base class for descriptors of datasets. The private name of the descriptor is the defined name with a prefix _. The get function will call the calculate_description function if the value of the descriptor is None and then return the value else it will just return the value of the descriptor. The set function only allows for the attribute to be set to None, which will trigger a recomputation the next time the get function is called. When inheriting this class the function calculate_description needs to be implemented, which defines how the private value should be calculated.

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.

class StringDescriptor[source]

StringDescriptor()

Descriptor for strings

Descriptor for strings. Mainly used for name and description of a dataset (see GenericDataset).

class GenericDataset[source]

GenericDataset(base_data, name:Optional[str]=None, description:Optional[str]=None)

A generic datset that has a name and description. Data is stored under the attribute base_data. The class provides a function reset_infered_data which can be called to reset all descriptors.

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.

Example

Here we create a descriptor that returns a dict with with name and desription of the dataset. Then we create a TestDataset class that uses the new descriptor.

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)