Skip to main content
Version: Java (Groovy)

RollingWAvg

RollingWAvg calculates a window-based rolling weighted average for an updateBy table operation. The rolling weighted average can be calculated using forward and/or backward windows.

Syntax

RollingWAvg(revTicks, fwdTicks, weightCol, pairs...)
RollingWAvg(revTicks, weightCol, pairs...)
RollingWAvg(timestampCol, revTime, fwdTime, weightCol, pairs...)
RollingWAvg(timestampCol, revTime, weightCol, pairs...)
RollingWAvg(timestampCol, revDuration, fwdDuration, weightCol, pairs...)
RollingWAvg(timestampCol, revDuration, weightCol, pairs...)

Parameters

ParameterTypeDescription
weightColString

The column containing the weight values.

revTickslong

The look-behind window size in ticks (rows).

fwdTickslong

The look-forward window size in ticks (rows).

pairsString...

The input/output column name pairs.

timestampColString

The name of the DateTime column.

revTimelong

The look-behind window size in nanoseconds.

fwdTimelong

The look-forward window size in nanoseconds.

revDurationDuration

The look-behind window size in Duration.

fwdDurationDuration

The look-forward window size in Duration.

Returns

An UpdateByOperation to be used in an updateBy table operation.

Examples

The following example performs an updateBy on the source table using three row-based RollingWAvg operations. Each operation gives varying revTicks and fwdTicks values to show how they affect the output. The windows for each operation are as follows:

  • opBefore: The window contains two rows. It starts two rows before the current row, and ends at the row before the current row.
  • opAfter: The window contains three rows. It starts one row after the current row, and ends three rows after the current row.
  • opMiddle: The window contains three rows. It starts one row before the current row, and ends one row ahead of the current row.
source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = i", "Y = randomInt(2,10)")

opPrior = RollingWAvg(3, -1, "Y", "WindowPriorX = X")
opPosterior = RollingWAvg(-1, 3, "Y", "WindowPosteriorX = X")
opMiddle = RollingWAvg(2, 1, "Y", "WindowMiddleX = X")

result = source.updateBy([opPrior, opPosterior, opMiddle], "Letter")

The following example performs an updateBy on the source table using three time-based RollingWAvg operations. Each operation gives varying revTime and fwdTime values to show how they affect the output. The windows for each operation are as follows:

  • opBefore: The window starts five seconds before the current row, and ends one second before the current row.
  • opAfter: The window starts one second after the current row, and ends five seconds after the current row.
  • opMiddle: The window starts three seconds before the current row, and ends three seconds after the current row.
baseTime = parseInstant("2023-01-01T00:00:00 ET")

source = emptyTable(10).update("Timestamp = baseTime + i * SECOND", "Letter = (i % 2 == 0) ? `A` : `B`", "X = i * 2", "Y = randomInt(2,10)")

opBefore = RollingWAvg("Timestamp", 5 * SECOND, -1 * SECOND, "Y", "WindowBeforeX = X")
opAfter = RollingWAvg("Timestamp", -1 * SECOND, 5 * SECOND, "Y", "WindowAfterX = X")
opMiddle = RollingWAvg("Timestamp", 3 * SECOND, 3 * SECOND, "Y", "WindowMiddleX = X")

result = source.updateBy([opBefore, opAfter, opMiddle], "Letter")