dp3.snapshots.snapshot_hooks ¶
Module managing registered hooks and their dependencies on one another.
SnapshotTimeseriesHookContainer ¶
Container for timeseries analysis hooks
Source code in dp3/snapshots/snapshot_hooks.py
register ¶
register(hook: Callable[[str, str, list[dict]], list[DataPointTask]], entity_type: str, attr_type: str)
Registers passed timeseries hook to be called during snapshot creation.
Binds hook to specified entity_type and attr_type (though same hook can be bound
multiple times).
If entity_type and attr_type do not specify a valid timeseries attribute,
a ValueError is raised.
Args:
hook: hook
callable should expect entity_type, attr_type and attribute
history as arguments and return a list of Task
objects.
entity_type: specifies entity type
attr_type: specifies attribute type
Source code in dp3/snapshots/snapshot_hooks.py
run ¶
Runs registered hooks.
Source code in dp3/snapshots/snapshot_hooks.py
SnapshotCorrelationHookContainer ¶
Container for data fusion and correlation hooks.
Source code in dp3/snapshots/snapshot_hooks.py
register ¶
register(hook: Callable[[str, dict], Union[None, list[DataPointTask]]], entity_type: str, depends_on: list[list[str]], may_change: list[list[str]]) -> str
Registers passed hook to be called during snapshot creation.
Binds hook to specified entity_type (though same hook can be bound multiple times).
If entity_type and attribute specifications are validated
and ValueError is raised on failure.
Args:
hook: hook
callable should expect entity type as str
and its current values, including linked entities, as dict.
Can optionally return a list of DataPointTask objects to perform.
entity_type: specifies entity type
depends_on: each item should specify an attribute that is depended on
in the form of a path from the specified entity_type to individual attributes
(even on linked entities).
may_change: each item should specify an attribute that hook
may change.
specification format is identical to depends_on
.
Returns:
Generated hook id.
Source code in dp3/snapshots/snapshot_hooks.py
run ¶
Runs registered hooks.
Source code in dp3/snapshots/snapshot_hooks.py
GraphVertex
dataclass
¶
Vertex in a graph of dependencies
DependencyGraph ¶
Class representing a graph of dependencies between correlation hooks.
Source code in dp3/snapshots/snapshot_hooks.py
add_hook_dependency ¶
Add hook to dependency graph and recalculate if any cycles are created.
Source code in dp3/snapshots/snapshot_hooks.py
add_edge ¶
Add oriented edge between specified vertices.
Source code in dp3/snapshots/snapshot_hooks.py
calculate_in_degrees ¶
Calculate number of incoming edges for each vertex. Time complexity O(V + E).
Source code in dp3/snapshots/snapshot_hooks.py
topological_sort ¶
Implementation of Kahn's algorithm for topological sorting. Raises ValueError if there is a cycle in the graph.
See https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm