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.
- 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.
- 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.
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
- 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.
OPCQOR and OPCQAND Calculation Modes:
The OPCQOR calculation mode is a bit-wise OR operation of all the 16 bit OPC qualities of the raw samples stored in the specified interval. This calculation mode can be used only if you have set the ”Store OPC Quality” to ”Enabled” in Historian Administrator and your data is coming from an OPC Collector.
The OPCQAND calculation mode is a bit wise AND operation of all the 16 bit OPC qualities of the raw samples stored in the specified interval. This calculation mode can be used only if you have set the ”Store OPC Quality” to Enabled in Historian Administrator and your data is coming from an OPC Collector.
When collecting data from OPC servers, the Historian OPC collector will convert the 16 bits of OPC quality to a Historian quality and subquality. When ”Store OPC Quality” is enabled, the 16 bits are also stored with the data and can be retrieved here.
Use the returned value from OPCQOR like a data quality. By using OPCQOR and OPCQAND values, you can see if a condition occurred during an interval and therefore know how trustworthy your returned data is.
- Value: The 16 bits are in the following format:
VVVVVVVVQQSSSSSS
The first 16 bits are for vendor to fill in. The next two are the actual quality, good, bad,uncertain. The rest of the bits are subquality.
- OPC good is a decimal 192 which is binary 0000000011000000.
- OPC bad is all zeros 0000000000000000.
- Quality: The percent good is 100 if all the samples have good Historian quality. The Historian quality is based on the OPC quality but both the qualities are not the same.
- Anticipated usage:
The OPCQOR and OPCQAND calculation modes are useful if you want to the know the quality of your samples between a time interval. For example,if you want to know how many of your samples from 3pm to 4pm had the following quality:
- All good - If you do an OPCAND from 3 P.M. to 4 P.M and get the result as 0000000011000000 which is 192 decimal, it means that the value was good for the whole time.
- All bad - If OPCOR returns 0, then the data was bad the whole time.
- Some bad - If you do a OPCOR and get the result as 0000000011000000 which is 192 decimal, it means that there were at least some good values. If you do an OPCAND and get the result as 0000000000000000, it means that at least some data was bad.
tag1
the result will be tag1.Min
which is the
result of the minimum calculation mode and tag1.Max
, the result of the
maximum calculation mode. The calculation mode is appended to the tagname. - Value: A query will return multiple values for the same timestamp. They are the results of each individual calculation mode. For more information on different Calculation Modes, refer to the corresponding sections
- Quality: There is no single overall quality for the query, only a quality per calculation mode.
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 Stamp | Value | Quality |
---|---|---|
8/6/2012 08:20:00 | 0.000000000000 | 0.0000000 |
8/6/2012 08:40:00 | 0.000000000000 | 0.0000000 |
8/6/2012 09:00:00 | 0.000000000000 | 5.0000000 |
8/6/2012 09:40:00 | 1.000000000000 | 100.0000000 |
8/6/2012 09:40:00 | 0.000000000000 | 100.0000000 |
8/6/2012 10:00:00 | 0.000000000000 | 100.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.
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 Stamp | Value | Quality |
---|---|---|
8/6/2012 08:20:00 | 0.000000000000 | 0.0000000 |
8/6/2012 08:40:00 | 0.000000000000 | 0.0000000 |
8/6/2012 09:00:00 | 0.000000000000 | 5.0000000 |
8/6/2012 09:20:00 | 0.000000000000 | 70.0000000 |
8/6/2012 09:40:00 | 1.000000000000 | 100.0000000 |
8/6/2012 10:00:00 | 0.000000000000 | 100.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 Stamp | Value | Quality |
---|---|---|
8/6/2012 08:20:00 | 0.000000000000 | 0.0000000 |
8/6/2012 08:40:00 | 0.000000000000 | 0.0000000 |
8/6/2012 09:00:00 | 0.000000000000 | 5.0000000 |
8/6/2012 09:20:00 | 1.000000000000 | 70.0000000 |
8/6/2012 09:40:00 | 0.000000000000 | 100.0000000 |
8/6/2012 10:00:00 | 0.000000000000 | 100.0000000 |
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 Stamp | Value | Quality |
---|---|---|
8/6/2012 08:20:00 | 0.000000000000 | 0.0000000 |
8/6/2012 08:40:00 | 0.000000000000 | 0.0000000 |
8/6/2012 09:00:00 | 0.000000000000 | 5.0000000 |
8/6/2012 09:20:00 | 1.000000000000 | 100.0000000 |
8/6/2012 09:40:00 | 0.000000000000 | 100.0000000 |
8/6/2012 10:00:00 | 0.000000000000 | 100.0000000 |
Calculating the state time of good quality data
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
Time Stamp | Value | Quality |
---|---|---|
8/6/2012 08:20:00 | 0.000000000000 | 0.0000000 |
8/6/2012 08:40:00 | 0.000000000000 | 0.0000000 |
8/6/2012 09:00:00 | 0.000000000000 | 5.0000000 |
8/6/2012 09:20:00 | 720,000.000000000000 | 100.0000000 |
8/6/2012 09:40:00 | 120,0.000000000000 | 100.0000000 |
8/6/2012 10:00:00 | 0.000000000000 | 100.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.
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 Stamp | Value | Quality |
---|---|---|
8/6/2012 08:20:00 | 0.000000000000 | 0.0000000 |
8/6/2012 08:40:00 | 0.000000000000 | 0.0000000 |
8/6/2012 09:00:00 | 0.000000000000 | 5.0000000 |
8/6/2012 09:20:00 | 360,000.000000000000 | 70.0000000 |
8/6/2012 09:40:00 | 120,000.000000000000 | 100.0000000 |
8/6/2012 10:00:00 | 0.000000000000 | 100.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.
Calculating the OPCQOR
The following is the data set used to run the query on.
TagName,Timestamp,Value
DATA1:Bad-0 OPC-(60)(08/09/12 18:00:01.000,Val=10
DATA2:Bad-0 OPC-(59)(08/09/12 18:00:02.000,Val=10
DATA3:Bad-0 OPC-(58)(08/09/12 18:00:03.000),Val=10
DATA4:Bad-0 OPC-(57)(08/09/12 18:00:04.000),Val=10
DATA5:Bad-0 OPC-(56)(08/09/12 18:00:05.000),Val=10
DATA6:Bad-0 OPC-(55)(08/09/12 18:00:06.000),Val=10
DATA7:Bad-0 OPC-(54)(08/09/12 18:00:07.000),Val=10
DATA8:Bad-0 OPC-(53)(08/09/12 18:00:08.000),Val=10
DATA9:Bad-0 OPC-(52)(08/09/12 18:00:09.000),Val=10
DATA10:Bad-0 OPC-(51)(08/09/12 18:00:10.000),Val=10
DATA11:Bad-0 OPC-(50)(08/09/12 18:00:11.000),Val=10
The following query retrieves the OPCQOR data with a start time of 18:00:00 and end time of 18:00:10 with a 2 second time interval.
set starttime='08/09/2012 18:00:00',endtime='08/09/2012 18:00:10'
select tagname,timestamp,value,Quality from ihrawdata where tagname like OPCQualityDataTag and samplingmode=Calculated
and calculationmode=OPCQOR and IntervalMilliseconds=2S
The following output is retrieved.
Tag Name | Time Stamp | Value | Quality |
---|---|---|---|
OPCQualityDataTag | 8/9/2012 18:00:02 | 63.000000000000 | 50.0000000 |
OPCQualityDataTag | 8/9/2012 18:00:04 | 59.000000000000 | 100.0000000 |
OPCQualityDataTag | 8/9/2012 18:00:06 | 63.000000000000 | 100.0000000 |
OPCQualityDataTag | 8/9/2012 18:00:08 | 55.000000000000 | 100.0000000 |
OPCQualityDataTag | 8/9/2012 18:00:10 | 55.000000000000 | 100.0000000 |
Calculating the OPCQAND
The following query retrieves the OPCQAND data with a start time of 18:00:00 and end time of 18:00:10 with a 2 second time interval.
set starttime='08/09/2012 18:00:00',endtime='08/09/2012 18:00:10'
select tagname,timestamp,value,Quality,opcquality from ihrawdata where tagname like OPCQualityDataTag and
samplingmode=Calculated and calculationmode=OPCQAND and IntervalMilliseconds=2S
he following output is retrieved.
Tag Name | Time Stamp | Value | Quality |
---|---|---|---|
OPCQualityDataTag | 8/9/2012 18:00:02 | 50.0000000 | 0 |
OPCQualityDataTag | 8/9/2012 18:00:04 | 100.0000000 | 0 |
OPCQualityDataTag | 8/9/2012 18:00:06 | 100.0000000 | 0 |
OPCQualityDataTag | 8/9/2012 18:00: | 100.0000000 | 0 |
OPCQualityDataTag | 8/9/2012 18:00:10 | 100.0000000 | 0 |
Using TagStats Calculation Mode
This image displays the TagStats calculation mode example in the Proficy Historian Interactive SQL Application.
In this example we perform the calculations
for a single interval by giving numberofsamples=1
.