Time Weighted Calculation Modes
The ihAverage and ihTotal and ihStandardDeviation modes use time-weighted calculations of interpolated and raw samples. The following example illustrates this concept using the ihAverage mode.
Import the following data
* Example for Interpolated Data Documentation
*
[Tags]
Tagname,DataType,HiEngineeringUnits,LoEngineeringUnits
TAG2,SingleFloat,60,0
[Data]
Tagname,TimeStamp,Value,DataQuality
TAG2,29-Mar-2002 14:00:00.000,30.0,Good
TAG2,29-Mar-2002 14:01:00.000,40.0,Good
TAG2,29-Mar-2002 14:01:10.000,50.0,Good
TAG2,29-Mar-2002 14:01:15.000,20.0,Bad
TAG2,29-Mar-2002 14:01:45.000,25.0,Good
Attributes for each data sample are Tagname, TimeStamp, Value, and DataQuality. The data can also be organized by duration:
Value | Duraation |
---|---|
30 | 60 seconds |
40 | 10 seconds |
50 | 5 seconds |
20 | 30 seconds |
25 | 15 seconds |
We want to analyze the data over the following interval. The time begins at the timestamp for the first sample and ends 15 seconds after the timestamp of the last sample.
3/29/2002 14:00:00 - start time
3/29/2002 14:02:00 - end time
Calculating a raw average over these two minutes produces the following:
(40 + 50 + 25) / 3 = 38.33
You can also calculate it with the following query:
select timestamp, value, quality from ihrawdata where samplingmode=calculated and calculationmode=RawAverage and timestamp >=
'29-Mar-2002 14:00' and timestamp <= '29-Mar-2002 14:02' and tagname = tag2 and numberofsamples = 1
Time Stamp | Value | Quality |
---|---|---|
29-Mar-200214:02:00.000 | 38.33 | 100.00 |
The value of 30 is not used because the RawAverage mode uses only samples whose timestamps are greater than the interval's start time. A value whose timestamp is 14:00 would be associated with the previous interval.
In a time-weighted average, the values are multiplied by the durations. The two-minute time weighted average is:
((30 * 59.999) + (40 * 10) + (50 * 5) + (25*15)) / (60 + 10 + 5 + 15) = 31.38
You can calculate this with the following query:
select timestamp, value, quality from ihrawdata where samplingmode=calculated and calculationmode=Average and timestamp >=
'29-Mar-2002 14:00' and timestamp <= '29-Mar-2002 14:02' and tagname = tag2 and numberofsamples = 1
This more closely describes the real situation, the value was 30 during most of the queried interval. The value of 30 is assigned to a timestamp of 14:00:00.001, which is the first possible timestamp greater than the interval start time (up to a resolution of milliseconds).