Skip to main content

Aggregations

Aggregations compute summary results over channels, optionally scoped to an event. Impulse provides three aggregation types: Histogram, Histogram2D, and Statistics.

Aggregations are organized into Pages, which group related visuals within a report.


Page

A Page is a logical container for aggregations. Pages are numbered for ordering and attached to the report.

from mda_reporting.core.page import Page

page = Page(page_number=1)
my_report.add_page(page)

page.add_aggregation(my_histogram)
page.add_aggregation(my_statistics)
ParameterTypeDescription
page_numberintPage number for logical ordering within the report.

The page_number is stored in dimension tables so downstream consumers can reconstruct report layout.


Histogram

Histogram is an abstract base class. Use one of the concrete variants:

ClassBin weight
HistogramDurationSample duration. Default; makes results independent of sampling rate.
HistogramCustomWeightsA second weights_expr time series (any TSAL expression).
HistogramDistanceDistance. Subclass of HistogramCustomWeights with distance weights.

The example below uses HistogramDuration. Bin counts are weighted by sample duration (not sample count), making results independent of sampling rate.

from mda_reporting.aggregations.histogram import HistogramDuration

rpm_hist = HistogramDuration(
name="rpm_hist",
base_expr=eng_rpm,
bins=[0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000],
event=eng_rpm_event,
desc="RPM distribution during high-RPM event",
channel_name="Engine RPM",
values_unit="s",
bins_unit="rpm",
)
page.add_aggregation(rpm_hist)

Parameters

ParameterTypeRequiredDescription
namestrYesUnique aggregation name.
base_exprTimeSeriesExpressionYesSignal expression to histogram.
binslist[float]YesBin edges. N edges produce N-1 bins.
eventEventNoEvent to scope the aggregation. If provided, only data within event instances is included.
descstrNoDescription stored in the dimension table.
agg_typestrNoAggregation type label. Default: "histogram_duration".
channel_namestrNoDisplay name for the signal (stored as channel_name in the dimension table).
values_unitstrNoUnit of histogram values (e.g. "s" for seconds).
bins_unitstrNoUnit of bin edges (e.g. "rpm").

Output schema

histogram_fact:

ColumnTypeDescription
container_idintContainer identifier.
visual_idintForeign key to histogram_dimension.
event_idintForeign key to event_dimension (null if no event).
bin_idintBin index (0-based).
hist_valuedoubleDuration-weighted bin count.
lower_bounddoubleLower edge of the bin.
upper_bounddoubleUpper edge of the bin.
bin_namestrLabel: "lower_bound-upper_bound".

histogram_dimension:

ColumnTypeDescription
visual_idintUnique aggregation identifier.
report_idintReport identifier.
namestrAggregation name.
page_numberintPage number.
descriptionstrDescription.
agg_typestrAggregation type label.
binsarray[double]Bin edges.
channel_namestrSignal display name.
signal_expressionstrString representation of the TSAL expression.
weights_channel_namestrReserved for future use.
weights_expressionstrReserved for future use.
values_unitstrUnit of values.
bins_unitstrUnit of bins.
definition_hashlongHash of the aggregation definition; used by incremental processing to detect definition changes.

Example: generating bin edges

bins = [float(i) for i in range(0, 5000, 250)]

This creates 20 bins from 0 to 4750 in steps of 250.


Histogram2D

Histogram2D is an abstract base class. Use one of the concrete variants:

ClassBin weight
Histogram2DDurationSample duration. Default.
Histogram2DCustomWeightsA user-supplied weights_expr time series.
Histogram2DDistanceDistance. Subclass of Histogram2DCustomWeights with distance weights.

Both signals are synchronized so they are comparable even when sampling frequencies differ.

from mda_reporting.aggregations.histogram2d import Histogram2DDuration

heatmap = Histogram2DDuration(
name="rpm_vs_speed",
x_expr=eng_rpm,
y_expr=veh_spd,
x_bins=[0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000],
y_bins=[0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200],
event=container_event,
desc="RPM vs Vehicle Speed heatmap",
x_channel_name="Engine RPM",
y_channel_name="Vehicle Speed",
values_unit="s",
x_bins_unit="rpm",
y_bins_unit="km/h",
)
page.add_aggregation(heatmap)

Parameters

ParameterTypeRequiredDescription
namestrYesUnique aggregation name.
x_exprTimeSeriesExpressionYesSignal expression for the x-axis.
y_exprTimeSeriesExpressionYesSignal expression for the y-axis.
x_binslist[float]YesBin edges for the x-axis.
y_binslist[float]YesBin edges for the y-axis.
eventEventNoEvent to scope the aggregation.
descstrNoDescription.
agg_typestrNoAggregation type label. Default: "histogram_duration".
x_channel_namestrNoDisplay name for the x-axis signal.
y_channel_namestrNoDisplay name for the y-axis signal.
values_unitstrNoUnit of histogram values.
x_bins_unitstrNoUnit of x-axis bins.
y_bins_unitstrNoUnit of y-axis bins.

Output schema

histogram2d_fact:

ColumnTypeDescription
container_idintContainer identifier.
visual_idintForeign key to histogram2d_dimension.
event_idintForeign key to event_dimension.
x_bin_idintX-axis bin index.
y_bin_idintY-axis bin index.
hist_valuedoubleDuration-weighted bin count.
x_lower_bounddoubleLower edge of the x bin.
x_upper_bounddoubleUpper edge of the x bin.
y_lower_bounddoubleLower edge of the y bin.
y_upper_bounddoubleUpper edge of the y bin.
x_bin_namestrX-axis bin label.
y_bin_namestrY-axis bin label.

histogram2d_dimension:

ColumnTypeDescription
visual_idintUnique aggregation identifier.
report_idintReport identifier.
page_numberintPage number.
namestrAggregation name.
descriptionstrDescription.
agg_typestrAggregation type label.
x_binsarray[double]X-axis bin edges.
y_binsarray[double]Y-axis bin edges.
x_channel_namestrX-axis signal display name.
x_signal_expressionstrX-axis TSAL expression.
y_channel_namestrY-axis signal display name.
y_signal_expressionstrY-axis TSAL expression.
weights_channel_namestrReserved.
weights_expressionstrReserved.
values_unitstrUnit of values.
x_bins_unitstrUnit of x-axis bins.
y_bins_unitstrUnit of y-axis bins.
definition_hashlongHash of the aggregation definition; used by incremental processing to detect definition changes.

StatsAggregator

Computes descriptive statistics for one or more signals within an event. Statistics are computed per event instance, allowing per-interval breakdowns.

from mda_reporting.aggregations.stats_aggregator import StatsAggregator

stats = StatsAggregator(
name="signal_stats",
input_expressions=[eng_rpm, veh_spd, avg_temp],
channel_names=["Engine RPM", "Vehicle Speed", "Avg Temperature"],
statistics=["min", "median", "mean", "max"],
event=container_event,
desc="Basic statistics per container",
)
page.add_aggregation(stats)

Parameters

ParameterTypeRequiredDescription
namestrYesUnique aggregation name.
input_expressionslist[TimeSeriesExpression]YesSignal expressions to compute statistics for.
channel_nameslist[str]YesDisplay names for each signal. Must match length of input_expressions.
statisticslist[str]YesStatistics to compute.
eventEventNoEvent to scope the aggregation. If None, statistics cover the entire series.
descstrNoDescription.
agg_typestrNoAggregation type identifier. Defaults to "stats_aggregator".
values_unitstrNoUnit of the statistic values.

Supported statistics

LabelDescription
"min"Minimum value across the event instance.
"max"Maximum value across the event instance.
"mean"Duration-weighted mean value.
"median"Duration-weighted median value.
"start"First value in the interval.
"end"Last value in the interval.

A ValueError is raised if unsupported statistics are provided.

Output schema

stats_aggregator_fact:

ColumnTypeDescription
container_idintContainer identifier.
visual_idintForeign key to stats_aggregator_dimension.
channel_namestrSignal display name.
event_idintEvent identifier.
event_instance_idlongForeign key to event_instance_fact.
aggregation_labelstrStatistic label (e.g. "mean").
statistic_valuedoubleComputed statistic value.

stats_aggregator_dimension:

ColumnTypeDescription
visual_idintUnique aggregation identifier.
report_idintReport identifier.
namestrAggregation name.
page_numberintPage number.
descriptionstrDescription.
agg_typestrAggregation type identifier.
statisticsarray[str]Requested statistic labels.
channel_namesarray[str]Signal display names.
signal_expressionsarray[str]TSAL expression strings.
values_unitstrUnit of statistic values.
definition_hashlongHash of computation definition.

Example: statistics with different event types

Per-container statistics (full measurement):

container_stats = StatsAggregator(
name="full_run_stats",
input_expressions=[eng_rpm, veh_spd],
channel_names=["Engine RPM", "Vehicle Speed"],
statistics=["min", "max", "mean"],
event=container_event,
)

Per-event-instance statistics (within operating band):

band_stats = StatsAggregator(
name="band_stats",
input_expressions=[eng_rpm, veh_spd],
channel_names=["Engine RPM", "Vehicle Speed"],
statistics=["min", "median", "mean", "max"],
event=eng_rpm_event,
)