Skip to main content
InSource Solutions

TN HistClient128 Understanding how Averages are Calculated in the Historian Client

InSource_Logo_Transparent.png

Description

 

This article from InSource shows how to get a Understanding how Averages are Calculated in the Historian Client.

  • Author: Glenn Yancey
  • Published: 08/30/2016
  • Applies to: Historian Client (Query)

Details

Before you Begin 

To test this out, you will need Historian Client, Historian Server, as well as an analog tag that has been recorded for at least a day in the Historian.  

Detailed Steps 

When queries are calculated to find an average over a given period of time, they have to rely upon samples between a specified duration.  To gather those samples, we must choose between two different Time Domain extensions which state how many samples get returned to calculate the average.  Understanding the use of these two Time Domain extensions will help us understand how averages are performed.  

 

Resolution (Values Spaced Every X ms) (wwResolution)  

 

In retrieval modes that use cycles, the resolution is the sampling interval for retrieving data, that is, the length of each cycle.
The number of cycles, therefore, depends on the time period and the resolution: 
number of cycles = time period / resolution
The number of actual return values is not always identical with this cycle count. In “truly cyclic” modes (Cyclic, Interpolated, Average, and Integral), a single data point is returned for every cycle boundary. However, in other cycle-based modes (Best Fit, Minimum, Maximum, Counter, and ValueState), multiple or no data points may be returned for a cycle, depending on the nature of the data.
Note: The rowset is guaranteed to contain one row for each tag in the normalized query at every resolution interval, regardless of whether a physical row exists in history at that particular instance in time. The value contained in the row is the last known physical value in history, at that instant, for the relevant tag.
Instead of specifying a resolution, you can specify the cycle count directly. In that case, the resolution is calculated based on the cycle count and the query duration. 

 

Cycle Count (X Values over Equal Time Intervals) (wwCycleCount

 

In retrieval modes that use cycles, the cycle count determines the number of cycles for which data is retrieved. The number of actual return values is not always identical with this cycle count. In “truly cyclic” modes (Cyclic, Interpolated, Average, and Integral), a single data point is returned for every cycle boundary. However, in other cycle-based modes (Best Fit, Minimum, Maximum, Counter, ValueState, and RoundTrip), multiple or no data points may be returned for a cycle, depending on the nature of the data.
The length of each cycle (the “resolution” of the returned values) is calculated as follows:
DC = DQ / (n – 1)
Where DC is the length of the cycle, DQ is the duration of the query, and is the cycle count.
Instead of specifying a cycle count, you can specify the resolution. In that case, the cycle count is calculated based on the resolution and the query duration. ​

 

Resolution (wwResolution) and Cycle Count (wwCycleCount) are mutually exclusive.  Although they can both be used in the same query, they can cancel one another out based on the values for their settings.      

 

Values chosen:
•  If wwResolution and wwCycleCount are not specified, then a default of 100 cycles are chosen. 

•  If wwResolution and wwCycleCount are set to 0, then a default of 100000 cycles are chosen. 

•  If wwResolution and wwCycleCount are both set, then wwCycleCount is ignored. 

•  If wwCycleCount is specified and is less than 0, then a default of 100 cycles are chosen. 

 

EXAMPLE 

 

In this example, I am using the Historian Client Query as the tool to perform my average over an 8 hour period.  

 

Note the Start and End Time below as well as the duration.   My Query Type has been set as Aggregate so that I can choose my Calculations tab to state Average.  This pulls back just one average value over the given time span.   

 

 

wwCycleCount

In this first scenario, I choose "x" values over equal time intervals.   Here I define "x" take 100 records evenly-spaced over 8 hours to calculate the average. My result is 1802.45.

 

 

OR

 

wwResolution

In this second scenario, I choose "Values spaced every 1000 Milliseconds" as my resolution instead of choosing values over equal  time intervals.   They take a sample every second over 8 hours to calculate the average.

28000 records (60 seconds x 60 minutes x 8 hrs).   My result is 1880.90552411375.  

 

Conclusion 

Averages are purely based on the the values stored in the Historian over time.  However, based on the way that they are retrieved in terms of Resolution vs Cycle Count will determine the average.