STATETIME Calculation Mode

The STATETIME calculation mode retrieves the duration that a tag was in a given state within an interval.

Value

The STATETIME calculation mode retrieves the total number of milliseconds during the interval for which the data was in the state value.

Quality

The percent good is 100 if the data is good quality for the entire the time interval.

Import this data to use in the examples.

[Tags]
Tagname,DataType,HiEngineeringUnits,LoEngineeringUnits
STATECOUNTTAG,SingleInteger,60,0
STATEBADTAG,SingleInteger,60,0
STATEBADTAG2,SingleInteger,60,0
[Data]
Tagname,TimeStamp,Value,DataQuality
STATECOUNTTAG,06-Aug-2012 8:59:00.000,2,Good
STATECOUNTTAG,06-Aug-2012 9:08:00.000,4,Good
STATECOUNTTAG,06-Aug-2012 9:14:00.000,4,Good
STATECOUNTTAG,06-Aug-2012 9:22:00.000,2,Good
STATEBADTAG,06-Aug-2012 8:59:00.000,2,Good
STATEBADTAG,06-Aug-2012 9:08:00.000,0,Bad
STATEBADTAG,06-Aug-2012 9:14:00.000,2,Good
STATEBADTAG,06-Aug-2012 9:22:00.000,4,Good
STATEBADTAG2,06-Aug-2012 8:59:00.000,2,Good
STATEBADTAG2,06-Aug-2012 9:08:00.000,0,Bad
STATEBADTAG2,06-Aug-2012 9:14:00.000,4,Good
STATEBADTAG2,06-Aug-2012 9:22:00.000,2,Good
Example: Calculating the state time of good quality data

Run this query in the Historian Interactive SQL:

set starttime='08/06/2012 8:00:00',endtime='08/06/2012 10:00:00'
select timestamp,value,quality from ihrawdata where tagname = STATECOUNTTAG and samplingmode=Calculation and 
CalculationMode=StateTime and IntervalMilliseconds=20m and statevalue=4

The following results are returned:

Time StampValueQuality
8/6/2012 08:20:000.0000000000000.0000000
8/6/2012 08:40:000.0000000000000.0000000
8/6/2012 09:00:000.0000000000005.0000000
8/6/2012 09:20:00720,000.000000000000100.0000000
8/6/2012 09:40:00120,0.000000000000100.0000000
8/6/2012 10:00:000.000000000000100.0000000

A 20 minute interval is 20*60*1000=1200000 milliseconds. In the 9:00 to 9:20 interval the value was in state 4 from 9:08 to 9:20 which is 12 minutes * 60 *1000 = 720000 milliseconds.

In the 9:20 to 9:40 interval the value was in state 4 from 9:20 to 9:22 which is 2*60*1000 = 120000 milliseconds.

Example: Calculating the state time of bad quality data

This tag has a bad data sample such as when the collector was restarted. A new value is recorded when the collector is started.

set starttime='08/06/2012 8:00:00',endtime='08/06/2012 10:00:00'
select timestamp,value,quality from ihrawdata where tagname = STATEBADTAG2 and samplingmode=Calculation and 
CalculationMode=StateTime and IntervalMilliseconds=20m and statevalue=4

Tagname,TimeStamp,Value,DataQuality
STATEBADTAG2,06-Aug-2012 8:59:00.000,2,Good
STATEBADTAG2,06-Aug-2012 9:08:00.000,0,Bad
STATEBADTAG2,06-Aug-2012 9:14:00.000,4,Good
STATEBADTAG2,06-Aug-2012 9:22:00.000,2,Good

The following results are returned:

Time StampValueQuality
8/6/2012 08:20:000.0000000000000.0000000
8/6/2012 08:40:000.0000000000000.0000000
8/6/2012 09:00:000.0000000000005.0000000
8/6/2012 09:20:00360,000.00000000000070.0000000
8/6/2012 09:40:00120,000.000000000000100.0000000
8/6/2012 10:00:000.000000000000100.0000000

In the interval between 9:00 to 9:20, the value was in state 4 from 9:14 to 9:20 = 6 minutes * 60 * 1000 = 360000 milliseconds.

In the interval between 9:20 to 9:40, the value was in state 4 from 9:20 to 9:22 = 2 minutes * 60 * 1000 = 120000 milliseconds.

Anticipated Usage

The STATETIME calculation mode is useful to determine the duration the tag was in a particular state. For example, if a tag records the state of a motor you can use state count to determine the duration a motor was in idle state.