Aggregators#
- class AppendixAggregator(max_deque_lenght=None)[source]#
This aggregator hold the results in a deque and performs the aggregation at the time querying the results instead. Compared to SerialAggregator provides the flexibility of aggregating within a certain number of past entries.
- Parameters
max_deque_lenght (int, optional) -- maximum lenght of deque to hold the aggregation entries. Defaults to None.
- append(key, value, weight=1, step=0)[source]#
Appends a new weighted entry timestamped by step.
- Parameters
key (Hashable) -- key to the aggregation entry.
value (Any) -- value of the aggregation entry.
weight (int, optional) -- weight of the aggregation for the current entry. Defaults to 1.
step (int, optional) -- timestamp of the current entry. Defaults to 0.
- append_all(entry_dict: Dict[str, float], weight=1, step=0)[source]#
To apply
append
on several entries given by a dictionary.- Parameters
entry_dict (Dict[Hashable, Any]) -- dictionary of the entries.
weight (int, optional) -- weight of the entries. Defaults to 1.
step (int, optional) -- timestamp of the current entries. Defaults to 0.
- get(key: str, k: Optional[int] = None)[source]#
fetches the weighted result
- Parameters
key (str) -- the name of the variable
k (int, optional) -- limits the number of points to aggregate.
- Returns
Any -- the result of the aggregation
- get_steps(key)[source]#
fetches the timestamps of the aggregation.
- Parameters
key (Hashable) -- aggregation key.
- Raises
Exception -- key not in the aggregator.
- Returns
List[Any] -- list of timestamps appended up to the maximum lenght of the internal deque.
- get_values(key)[source]#
fetches the values of the aggregation.
- Parameters
key (Hashable) -- aggregation key.
- Raises
Exception -- key not in the aggregator.
- Returns
List[Any] -- list of values appended up to the maximum lenght of the internal deque.
- get_weights(key)[source]#
fetches the weights of the aggregation.
- Parameters
key (Hashable) -- aggregation key.
- Raises
Exception -- key not in the aggregator.
- Returns
List[Any] -- list of weights appended up to the maximum lenght of the internal deque.
- items()[source]#
Generator of (key, result) to get aggregation result of all keys in the aggregator.
- Yields
Tuple[Hashable, Any] -- pair of key, aggregation result.
- keys()[source]#
fetches the keys of entries aggregated so far.
- Returns
Iterable -- all aggregation keys.
- class SerialAggregator[source]#
Serially aggregats arbitrary number of weighted or unweigted variables.
- add(key, value, weight=None)[source]#
adds a new item to the aggregation
- Parameters
key (Hashable) -- key of the entry
value (Any) -- current value of the entry. Type of this value must support addition. Support for division is required if the aggregation is weighted.
weight (float, optional) -- weight of the current entry. If not specified, aggregation becomes unweighted (equal to accumulation). Defaults to None.
- get(key)[source]#
Fetches the current result of the aggregation. If the aggregation is weighted the returned value is weighted average of the entry values.
- Parameters
key (Hashable) -- key to the entry.
- Raises
Exception -- key does not exist in the aggregator.
- Returns
Any -- result of the aggregation.
- get_sum(key)[source]#
Fetches the weighted sum (no division).
- Parameters
key (Hashable) -- key to the entry.
- Raises
Exception -- key does not exist in the aggregator.
- Returns
Any -- result of the weighted sum of the entries.
- get_weight(key)[source]#
Fetches the sum of weights of the weighted averaging.
- Parameters
key (Hashable) -- key to the entry.
- Raises
Exception -- key does not exist in the aggregator.
- Returns
Any -- sum of weights of the aggregation.
- items()[source]#
Generator of (key, result) to get aggregation result of all keys in the aggregator.
- Yields
Tuple[Hashable, Any] -- pair of key, aggregation result.
- keys()[source]#
fetches the keys of entries aggregated so far.
- Returns
Iterable -- all aggregation keys.