impulse_query_engine.analyze.query.aggregations.custom_statistic
Descriptors for custom statistics (per-channel and cross-channel).
PerChannelStatistic
class PerChannelStatistic()
Descriptor for a single per-channel custom statistic.
Arguments:
func(Callable): Function with signaturefunc(series: SampleSeries, t_start: float, t_end: float, **params) -> Sequence[float]. Called once per input channel and event interval with the channel's series clipped to the interval. It must return a sequence of scalars whose length equalsaggregation_labels(a single label still requires a one-element sequence, e.g.[value]). The series may be empty; returnfloat("nan")entries for undefined results. The function is cloudpickled to Spark executors, so a module-level importable function is recommended; never capture Spark objects.aggregation_labels(list of str): Output labels this statistic produces. The values returned byfuncare mapped positionally to these labels, which become the keys of the statistic's result maps. Labels must be non-empty, unique strings; changing them changes the aggregation's definition hash.params(dict): Keyword arguments passed tofuncon every invocation (func(series, t_start, t_end, **params)). Keys must be valid Python identifiers matching parameter names offunc. Changing params changes the aggregation's definition hash.
CrossChannelStatistic
class CrossChannelStatistic()
Descriptor for a single cross-channel custom statistic.
Arguments:
func(Callable): Function with signaturefunc(series: list[SampleSeries], t_start: float, t_end: float, **params) -> Sequence[float]. Called once per event interval with the series listed ininputs(clipped to the interval, in declared order). It must return a sequence of scalars whose length equalsaggregation_labels(a single label still requires a one-element sequence, e.g.[value]). Any series may be empty; returnfloat("nan")entries for undefined results. The function is cloudpickled to Spark executors, so a module-level importable function is recommended; never capture Spark objects.aggregation_labels(list of str): Output labels this statistic produces. The values returned byfuncare mapped positionally to these labels, which become the keys of the statistic's result maps. Labels must be non-empty, unique strings; changing them changes the aggregation's definition hash.inputs(list of str): Names of the input channels the function requires, resolved against the aggregator'sinput_names.None(default) passes all input channels in input order.channel_name(str): A channel name applied to all of the statistic's output rows. Consumed by downstream consumers (e.g. the reporting layer) only; ignored by the query engine.None(default) leaves it to the consumer, which typically falls back to each output'saggregation_label.params(dict): Keyword arguments passed tofuncon every invocation (func(series, t_start, t_end, **params)). Keys must be valid Python identifiers matching parameter names offunc. Changing params changes the aggregation's definition hash.
normalize_per_channel_statistics
def normalize_per_channel_statistics(
per_channel_custom_statistics: list[PerChannelStatistic] | None
) -> list[PerChannelStatistic]
Validate a per-channel statistics list.
Arguments:
per_channel_custom_statistics(list or None): List ofPerChannelStatisticdescriptors.
Raises:
TypeError: If the value is not a list, an item is not aPerChannelStatisticwith a callablefunc, or params/labels are invalid.ValueError: If a descriptor'saggregation_labelsare not unique.
Returns:
list of PerChannelStatistic: The validated list; empty when the input is None.
normalize_cross_channel_statistics
def normalize_cross_channel_statistics(
cross_channel_custom_statistics: list[CrossChannelStatistic] | None
) -> list[CrossChannelStatistic]
Validate a cross-channel statistics list.
Arguments:
cross_channel_custom_statistics(list or None): List ofCrossChannelStatisticdescriptors.
Raises:
TypeError: If the value is not a list, an item is not aCrossChannelStatisticwith a callablefunc, or params/labels are invalid.ValueError: If a descriptor'saggregation_labelsare not unique.
Returns:
list of CrossChannelStatistic: The validated list; empty when the input is None.