otp.agg.generic#
- generic(query_fun, bucket_delimiter=False, bucket_interval=0, bucket_units='seconds', bucket_time='end', bucket_end_condition=None, running=False, group_by=None, end_condition_per_group=False, boundary_tick_bucket='new')#
Generic aggregation. Aggregation logic is provided in
query_fun
parameter and this logic is applied for ticks in each bucket. Currently, this aggregation can be used only with.apply()
method.- Parameters
query_fun (Callable) – Function that takes
Source
as a parameter, applies some aggregation logic to it and returnsSource
as a result. Note that currently only methods that support dynamic symbol change could be used in the provided function. For example,rename()
can’t be used. If you try to use such methods here, you will get an error during runtime.bucket_delimiter (bool) – When set to
True
an extra tick is created after each bucket. Also, an additional column, called DELIMITER, is added to output ticks. The extra tick has values of all fields set to the defaults (0,NaN,””), except the delimiter field, which is set to “D” All other ticks have the DELIMITER set to string zero “0”.bucket_interval (int) – Determines the length of each bucket (units depends on
bucket_units
).bucket_units (Literal['seconds', 'ticks', 'days', 'months', 'flexible']) –
Set bucket interval units.
If set to flexible
bucket_end_criteria
must be set.bucket_time (Literal['start', 'end']) –
Control output timestamp.
start
the timestamp assigned to the bucket is the start time of the bucket.
end
the timestamp assigned to the bucket is the end time of the bucket.
bucket_end_condition (condition) – An expression that is evaluated on every tick. If it evaluates to “True”, then a new bucket is created. This parameter is only used if
bucket_units
is set to “flexible”running (bool) –
Aggregation will be calculated as sliding window.
running
andbucket_interval
parameters determines when new buckets are created.running
= Trueaggregation will be calculated in a sliding window.
bucket_interval
= N (N > 0)Window size will be N. Output tick wil be generated when tick “enter” window (arrival event) and when “exit” window (exit event)
bucket_interval
= 0Left boundary of window will be binded to start time. For each tick aggregation will be calculated in [start_time; tick_t].
running
= Falsebuckets partition the [query start time, query end time) interval into non-overlapping intervals of size
bucket_interval
(with the last interval possibly of a smaller size). Ifbucket_interval
is set to 0 a single bucket for the entire interval is created.
Default: False - create totally independent buckets. Number of buckets = (end - start) / bucket_interval’)
group_by (list, str or expression) – When specified, each bucket is broken further into additional sub-buckets based on specified field values.
end_condition_per_group (bool) –
Controls application of
bucket_end_condition
in groups.end_condition_per_group
= Truebucket_end_condition
is applied only to the group defined bygroup_by
end_condition_per_group
= Falsebucket_end_condition
applied across all groups
This parameter is only used if
bucket_units
is set to “flexible”boundary_tick_bucket (Literal['new', 'previous']) –
Controls boundary tick ownership.
previous
A tick on which
bucket_end_condition
evaluates to “true” belongs to the bucket being closed.new
tick belongs to the new bucket.
This parameter is only used if
bucket_units
is set to “flexible”
Examples
>>> data = otp.Ticks({'A': [1, 2, 3]}) >>> def agg_fun(source): ... return source.agg({'X': otp.agg.count()}) >>> data = otp.agg.generic(agg_fun).apply(data) >>> data() Time X 0 2003-12-04 3
See also
GENERIC_AGGREGATION OneTick event processor