Other Calculation Modes

STATECOUNT

The STATECOUNT calculation mode counts the number of times a tag has transitioned to another state from a previous state. A state transition is counted when the previous good sample is not equal to the state value and the next good sample is equal to state value.

The STATECOUNT calculation mode cannot be used on tags of BLOB data type.

Value

The number of transitions into the state in a given time interval.

Quality

The percent good is 100 if there are no bad samples within the time interval. Otherwise, the percent good is the percent of interval time that the value was of good quality.

Example: Calculating the state count of good quality data

This example shows a simple case of counting state transitions. In this example, the value 4 means that a machine is running so we want to count the number of times the tag transitioned from some other value to 4.

Import the following data.

[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

Execute the following query in 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=StateCount 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:40:001.000000000000100.0000000
8/6/2012 09:40:000.000000000000100.0000000
8/6/2012 10:00:000.000000000000100.0000000

Note that the transition from 2 to 4 (machine started running) happened at 9:08, so it is included in the 9:00 to 9:20 interval.

The data was of bad quality until 8:59:00 which is for 1 minute of the 20 minute interval. The percent good for that interval is 5.

There are two samples with the value 4. We do not count the number of times the statevalue occurred, but the number of transitions from some other value to the state value.

We only count transitions into the state value not out of the state value. So, the transition from 4 to 2 is not counted.

Example: Calculating the state count of bad quality data

Note that this tag had a bad data sample when the collector was restarted. This does not, however, affect the state count.

Run the following query:

set starttime='08/06/2012 8:00:00',endtime='08/06/2012 10:00:00'
select timestamp,value,quality from ihrawdata where tagname = STATEBADTAG and samplingmode=Calculation and 
CalculationMode=StateCount 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:000.00000000000070.0000000
8/6/2012 09:40:001.000000000000100.0000000
8/6/2012 10:00:000.000000000000100.0000000

Note that the bad value is ignored and the state change that happened at 9:22 is counted. We do not know if the machine had started and stopped while the collector was shutdown.

If the value did change to running while the collector was shut down then that change is counted as in shown in the following example:

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=StateCount and IntervalMilliseconds=20m and statevalue=4
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:001.00000000000070.0000000
8/6/2012 09:40:000.000000000000100.0000000
8/6/2012 10:00:000.000000000000100.0000000
Note: The state change at 9:14 is counted and returned in the 9:20 interval.
Example: Calculating the state count of enumerated set data

When querying a tag that uses enumerated sets, use the string state name as the state value.

Using the data from previous example, assume that the STATECOUNTTAG had an enumerated set with the values as 2=Stopped and 4=Running.

You should use this query with statevalue of Running instead of the native value 4.

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=StateCount and IntervalMilliseconds=20m and statevalue='Running'

The results match with the results when statevalue=4 is used.

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:001.000000000000100.0000000
8/6/2012 09:40:000.000000000000100.0000000
8/6/2012 10:00:000.000000000000100.0000000
Anticipated Usage
The STATECOUNT calculation mode is useful to determine the number of times a value transitioned to a certain state such as when a digital state was turned on or the enumerated value was of certain value. It should mostly be used with integer values because it may not exactly match a float state value due to rounding.