Raw Calculation Modes

The calculation modes use only collected raw samples to determine the value for each interval.

Count Mode:
  • Value: The count of raw samples with good quality in the interval. The values of the each sample are ignored. The Count does not include any samples with bad quality, including the start and end of collection markers.
  • Quality: Percent good is always 100, even if the interval does not contain any raw samples or contains only bad quality samples.
  • Anticipated Usage: Count is useful for analyzing the distribution of the raw data samples to determine the effect of compression deadbands. It is also useful to determine which tags are consuming the most archive space.
RawTotal Mode: Retrieves the arithmetic total (sum) of sampled values for each interval.
  • Value: The sum of the good quality values of all raw samples in the interval. All bad quality samples are ignored.
  • Quality: Percent good is always 100, even if the interval does not contain any raw samples or it contains only bad quality samples.
  • Anticipated Usage: RawTotal mode is useful for calculating an accurate total when a sufficient number of raw samples are collected. Note that unlike ihTotal, this is a simple sum with no assumption that the values are rate values.
RawAverage Mode: The arithmetic average (mean) of all good quality raw samples in the interval.
  • Value: The sum of all good quality samples in the interval, divided by the number of good quality samples in the interval. All bad quality samples are ignored. That is, RawAverage is equivalent to the RawTotal divided by Count.
  • Quality: If there are no raw samples in the interval or they all have bad quality, then the percent good is 0.  Otherwise, percent good is always 100, even if the interval contains bad quality samples.
    select timestamp, value, quality from ihrawdata where samplingmode=calculated 
    and calculationmode=rawaverage and timestamp >= '29-Mar-2002 13:30' and 
    timestamp <= '29-Mar-2002 14:30' and tagname  = counttag and intervalmilliseconds = 10M
  • Anticipated Usage: The RawAverage mode is useful for calculating an accurate average when a sufficient number of raw samples are collected.
RawAverage Mode:
  • Value:
  • Quality:
  • Anticipated Usage:

RawStandardDeviation Mode: Retrieves the arithmetic standard deviation of raw values for each calculation interval.

  • Value: Any raw point of bad data quality is ignored.
  • Quality: If there are no raw samples in the interval or they all have bad quality, then the percent good is 0. Otherwise, percent good is always 100, even if the interval contains bad quality samples.
  • Anticipated Usage: The RawStandardDeviation mode is useful for calculating an accurate standard deviation when a sufficient number of raw samples are collected.
FirstRawValue/FirstRawTime Modes: Retrieve the first good raw sample value and timestamp for a given time interval, respectively.
  • Value: The value of the raw sample or zero if there are no good raw samples in the interval. The timestamp of the sample or the year 1969 if there are no good raw samples in the interval.
  • Quality: The quality is the same for FirstRawValue and First RawTime. If there are no good raw samples in the interval, then the percent good is 0. Otherwise, the percent good is always 100, even if the interval contains bad quality samples.

    The Raw sample has a quality of Good, Bad or Uncertain, and that is converted to a 0 or 100 percent.

  • Anticipated Usage:
LastRawValue/LastRawTime Modes: Retrieve the last good raw sample value and timestamp for a given time interval, respectively.
  • Value: The value of the raw sample or zero if there are no good raw samples in the interval. The timestamp of the sample or the year 1969 if there are no good raw samples in the interval.
  • Quality:

    The quality is the same for LastRawValue and LastRawTime. If there are no good raw samples in the interval, then the percent good is 0. Otherwise, percent good is always 100, even if the interval contains bad quality samples.

    The Raw sample has a quality of Good, Bad or Uncertain, and that is converted to a 0 or 100 percent.

  • Anticipated Usage:

Calculating the count of raw samples

The following example demonstrates that only good samples are counted. Importing the following data ensures that at least one interval has 0 samples.

[Tags]
Tagname,DataType,HiEngineeringUnits,LoEngineeringUnits
COUNTTAG,SingleInteger,100,0
[Data]
Tagname,TimeStamp,Value,DataQuality
COUNTTAG,29-Mar-2002 13:59:00.000,22,Good
COUNTTAG,29-Mar-2002 14:08:00.000,12,Bad
COUNTTAG,29-Mar-2002 14:22:00.000,4,Good

The following query retrieves data with a start time of 14:00 and an end time of 14:30 with a 10-minute interval.

select timestamp, value, quality from ihrawdata where samplingmode=calculated and calculationmode=count and timestamp >='29-Mar-2002 14:00' and timestamp <= '29-Mar-2002 14:30' and tagname  = counttag and intervalmilliseconds = 10M
Time Stamp Value Quality
29-Mar-200214:10:00.000 0.00 100.00
29-Mar-200214:20:00.000 0.00 100.00
29-Mar-200214:30:00.000 1.00 100.00
Note: The bad raw sample at 14:08 is not counted, but the good sample at 14:22 is counted. The 14:11 to 14:20 interval has no raw samples, but still has a percent good of 100 percent.

Calculating the Raw Total

The following example demonstrates that only good quality samples are included in the sum. Perform the fol- lowing query on the same data set as that in the Count example above:

select timestamp, value, quality from ihrawdata where samplingmode=calculated and calculationmode=rawtotal and timestamp >= '29-Mar-2002 13:30' and timestamp <= '29-Mar-2002 14:30' and tagname  = counttag and intervalmilliseconds = 10M                                                                                                                                                                                                                                             
Time Stamp Value Quality
29-Mar-200213:40:00.000 0.00 100.00
29-Mar-200213:50:00.000 0.00 100.00
29-Mar-200214:00:00.00 22.00 100.00
29-Mar-200214:10:00.000 0.00 100.00
29-Mar-200214:20:00.000 0.00 100.00
29-Mar-200214:30:00.000 4.00 100.00

If the same start and end time are used, but the time span is treated as a single interval, then all values are added together:

select timestamp, value, quality from ihrawdata where samplingmode=calculated and calculationmode=rawtotal and timestamp >= '29-Mar-2002 13:30' and timestamp <= '29-Mar-2002 14:30' and tagname  = counttag 
and numberofsamples=1
Time Stamp Value Quality
29-Mar-200214:30:00.000 26.00 100.00

Even though the time span covers all raw samples, only the two good quality samples are used in the calculation: 26 = 22 + 4

Calculating RawAverage

The following example demonstrates that only good quality samples are included in RawAverage. Perform the following query on the same data set as that in the Count example above. This query retrieves data using RawAverage, with a start time of 13:30 and an end time of 14:30 at 10-minute intervals.
select timestamp, value, quality from ihrawdata where samplingmode=calculated and calculationmode=rawaverage and 
timestamp >= '29-Mar-2002 13:30' and timestamp <= '29-Mar-2002 14:30' and tagname  = counttag and intervalmilliseconds = 10M
Time Stamp Value Quality
29-Mar-200213:40:00.000 0.00 0.00
29-Mar-200213:50:00.000 0.00 0.00
29-Mar-200214:00:00.000 22.00 100.00
29-Mar-200214:10:00.000 0.00 0.00
29-Mar-200214:30:00.000 4.00 100.00

The interval from 14:11 to 14:20 has no raw samples. The percent good quality of 0.

The interval from 14:01 to 14:10 has 0 good and 1 bad samples. It also has a percent good quality of 0.

The interval from 14:21 to 14:30 has 1 good and 0 bad samples. It has a percent good quality of 100.

If the same start and end time are used, but the time span is treated as a single interval, then all values are averaged together:

select timestamp, value, quality from ihrawdata where samplingmode=calculated and calculationmode=rawaverage 
and timestamp >= '29-Mar-2002 13:30' and timestamp <= '29-Mar-2002 14:30' and tagname  = counttag and 
numberofsamples=1
Time Stamp Value Quality
29-Mar-200214:30:00.000 13.00 100.00

Even though the time span covers all raw samples, but only the two good samples are used in the calculation:  13 = (22+4)/2 Since the interval includes at least one good quality sample, percent good for the interval is 100, even though 33% of the samples are of bad quality.

Calculating the Raw Standard Deviation

The following example demonstrates that only good samples are included in the standard deviation. Perform the following query on the same data set as that in the Count example above:

select timestamp, value, quality from ihrawdata where samplingmode=calculated and calculationmode=rawstandarddeviation and 
timestamp >= '29-Mar-2002 13:30' and timestamp <= '29-Mar-2002 14:30' and tagname  = counttag and numberofsamples=1
Time Stamp Value Quality
29-Mar-200214:30:00.000 12.73 100.00

Retrieving the FirstRawValue/FirstRawTime Values

Import this data to Historian:

[Tags]
Tagname,DataType,HiEngineeringUnits,LoEngineeringUnits
Tag1,SingleFloat,60,0
[Data]
Tagname,TimeStamp,Value,DataQuality
Tag1,07-05-2011 17:24:00,29.72,Bad
Tag1,07-05-2011 17:25:00,29.6,Good
Tag1,07-05-2011 17:26:00,29.55,Good 
Tag1,07-05-2011 17:27:00,29.49,Bad
Tag1,07-05-2011 17:28:00,29.53,Bad
Tag1,07-05-2011 17:29:00,29.58,Good
Tag1,07-05-2011 17:30:00,29.61,Bad
Tag1,07-05-2011 17:31:00,29.63,Bad
Tag1,07-05-2011 18:19:00,30,Good
Tag1,07-05-2011 18:20:00,29.96,Good
Tag1,07-05-2011 18:21:00,29.89,Good
Tag1,07-05-2011 18:22:00,29.84,Good
Tag1,07-05-2011 18:23:00,29.81,Bad

Using FirstRawValue Calculation Mode

set starttime='07-05-2011 16:00:00', endtime='07-05-2011 19:00:00'
select timestamp,value,quality from ihrawdata where tagname like 'Tag1' and samplingMode=Calculated and 
CalculationMode=FirstRawValue and intervalmilliseconds=1h

The output is as follows:

Time Stamp Value Quality
07-05-201117:00:00 0.0000000 0.0000000
07-05-201118:00:00 29.6000000 100.0000000
07-05-201119:00:00 30.0 100.0000000

For the time interval 16:00 to 17:00 there are no raw values so a value and quality of 0 is returned for both FirstRawValue and FirstRawTime. The first raw sample from17:00 to 18:00 is 29.72 but it is a bad data quality so it is skipped and the 29.6 is returned and its timestamp of 17:25 is returned in FirstRawTime. FirstRawValue calculation mode considers only good quality data. In the last interval the first good raw sample is 30 and is returned and its timestamp is returned as FirstRawTime.

Retrieving the LastRawValue/LastRawTime Values

Import this data into Historian

[Tags]Tagname,DataType
DecimatedOneHour,DoubleInteger
[Data]
Tagname,Timestamp,Value,DataQuality
Tag1,07-05-2011 17:29:00,29,Good
Tag1,07-05-2011 20:00:00,0,Good
Tag1,07-05-2011 20:12:00,12,Good
Tag1,07-05-2011 20:15:00,0,Bad

Using LastRawValue Calculation Mode

set starttime='07-05-2011 17:00:00',endtime=' 07-05-2011 21:00:00'
select timestamp,value,quality from ihrawdata where tagname like Tag1 and samplingmode=Calculated and 
CalculationMode=LastRawValue and Intervalmilliseconds=1h

The output is as follows:

Time Stamp Value Quality
07-05-201118:00:00 29 100.0000000
07-05-201119:00:00 0 0.0000000
07-05-201120:00:00 0 100.0000000
07-05-201121:00:00 12 100.0000000

In the interval from 17:00 to 18:00 the last good value is 29. The 18:00 to 19:00 has no raw samples so the quality is bad. The 20:00 sample is returned as the last good value in the 19:00 to 20:00. In the final interval, the last raw sample is bad quality so it is ignored and the previous sample is returned.

Using LastRawTime Calculation Mode

set starttime='07-05-2011 17:00:00',endtime=' 07-05-2011 21:00:00'
select timestamp,value,quality from ihrawdata where tagname like Tag1 and samplingmode=Calculated and CalculationMode=
LastRawTime and Intervalmilliseconds=1h

The output is as follows:

Time Stamp Value Quality
07-05-201117:00:00 07-05-201117:29:00 100.0000000
07-05-201118:00:00 01-01-197005:30:00 0.0000000
07-05-201119:00:00 07-05-201120:00:00 100.0000000
07-05-201120:00:00 07-05-201120:12:00 100.0000000
Note: You can also use the INCLUDEBAD query modifier to include bad quality data.