The $alpha is the exponential decay of data: from zero (inclusive) to one (exclusive): the lower values cause the effect of data to decay more quickly, the higher values cause the effect of data to decay more slowly . Specifically, weights on older data decay exponentially with a characteristic time of -1/log(alpha) (log being the natural logarithm).

The $max_gap is the maximum time gap after which the data is considered lost. If the time interval between updates is dt, using a $max_gap of N*dt will cause each update to fill in up to N-1 of any preceeding skipped updates with the current data value. Use a $max_gap of dt to prevent such filling.

Return the current completeness: how well based the current average and standard deviation are on actual data. Any time intervals between updates greater than $max_gap reduce this value. A series of updates at time intervals of less than $max_gap will gradually increase this value from its initial, minimum, value of 0 to its maximum value of 1.

The $time should represent the current time. It must be >= the time of the last update.

The idea and the code are from the September 1998 Doctor Dobb's Journal Algorithm Alley article "Discontiguous Exponential Averaging" by John C. Gunther, used with permission. JCG also provided valuable feedback for the documentation -- and even fixed a bug in the code without knowing Perl as such. This is just a Perlification of the pseudocode in the article, all errors in transcription are solely mine.