Object - streams : Average

Aggregator to calculate average in streams.

Methods

Fields

  • count int (default 0)
  • description

  • sum float (default 0.0)
  • description

process

(anydata value, EventType eventType)

returns anydata

Returns the calculated average after value being aggregated into current average. If the eventType is streams:CURRENT,value is added to the current sum and count is increase by 1. If the eventType is streams:EXPIRED, value is subtracted from the current sum and count is descreased by 1. If the eventType is streams:RESET, Current summation and count is reset, regardless the value. Then by dividing the sum by count, the average is calculated.

Parameters

  • value anydata
  • The numeric value being aggregated in order to calculate the new average.

  • eventType EventType
  • Type of the incoming event streams:CURRENT, streams:EXPIRED or streams:RESET.

  • Return Type

    (anydata)
  • Updated average value after value being aggregated.

copy

()

returns Aggregator

Returns a copy of the Average aggregator without its current state.

  • Return Type

    (Aggregator)
  • Returns Average aggregator.

saveState

()

returns map

Return current state to be saved as a map of any typed values.

  • Return Type

    (map)
  • A map of any typed values.

restoreState

Restores the saved state which is passed as a map of any typed values.

Parameters

  • state map
  • A map of typed any values. This map contains the values to be restored from the persisted data.