Follow

How does Flow calculate an Average?

Have you ever tried to calculate the average of all the data points in a time period and wondered why you arrived at a different value from Flow?

The reason for this is because Flow always uses a time weighted average when determining an average. 

Let's use the sample data that we used when discussing the Basic Aggregation Methods.

 

Point Timestamp Raw Value Duration (seconds) Weighted Value
1 05:55:03 1.6 203 0.090222222
2 06:03:23 2.3 247 0.157805556
3 06:07:30 2.5 172 0.119444444
4 06:10:22 3 330 0.275
5 06:15:52 2.1 288 0.168
6 06:20:40 1.9 273 0.144083333
7 06:25:13 2.5 271 0.188194444
8 06:29:44 2.3 330 0.210833333
9 06:35:14 1.6 360 0.16
10 06:41:14 1.8 289 0.1445
11 06:46:03 2.3 392 0.250444444
12 06:52:35 2.9 171 0.13775
13 06:55:26 2.2 274 0.167444444
14 07:05:40 1.4 N/A N/A

 

You'll notice that we've added two columns to our sample data: Duration and Weighted Value.

For each data point in a time period, Flow will determine how long that data point was valid for - this is shown in the Duration column above. 

The first data point's (which is the "boundary" value) duration is calculated from the start of the time period that is being processed (in this case from 06:00:00) until the next data point's timestamp.

The last data point's (in this case Point 13 and not Point 14, which is outside of the time period being processed) duration is calculated from it's timestamp until the end of the time period (in this case until 07:00:00)

For each data point (including the starting / boundary value, but excluding the last point that is outside of the time period) Flow calculates a weighted value as follows:

Weighted Value = Value * (Duration / Total Time Period Duration)

In the above example, the Total Time Period Duration = 3600s, because Flow is processing an hourly time period.

While the example above demonstrates the concept using seconds, Flow actually does all time-related calculations in milliseconds.

Thereafter, Flow adds all the time-weighted values together to get a time-weighted average.

With the above data points, Average = 2.213722222

When a time weighted average is applied to a rate, the result is effectively a mathematical integration of the rate, which is the total for that time period.  For example, if one performs a time weighted average on a Flow Rate (liters/hr), the result is the total quantity of liters measured in that hour.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments