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_funparameter 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
Sourceas a parameter, applies some aggregation logic to it and returnsSourceas 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
Truean 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_criteriamust 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_unitsis set to “flexible”running (bool) –
Aggregation will be calculated as sliding window.
runningandbucket_intervalparameters 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_intervalis 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_conditionin groups.end_condition_per_group= Truebucket_end_conditionis applied only to the group defined bygroup_byend_condition_per_group= Falsebucket_end_conditionapplied across all groups
This parameter is only used if
bucket_unitsis set to “flexible”boundary_tick_bucket (Literal['new', 'previous']) –
Controls boundary tick ownership.
previous
A tick on which
bucket_end_conditionevaluates to “true” belongs to the bucket being closed.new
tick belongs to the new bucket.
This parameter is only used if
bucket_unitsis 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