Trend Sampling Mode

The Trend Sampling mode maximizes performance when retrieving data specifically for plotting.

The Trend Sampling mode identifies significant points and returns them to the caller. These will be raw samples. Significant points are established by finding the raw minimum and raw maximum values within each interval. Note that this is not the same as finding the change in slope direction of a line, as archive compression does.

The Trend Sampling mode approximates a high resolution trend with only as much detail as could be drawn on the screen. For example, say you are about to draw a trend on the screen and you know that the area with the trend graph is only 100 pixels wide. You could not possibly represent any more than 100 points in those 100 pixels. By using the Trend sampling type, you can ensure you retrieve adjacent highs and lows to draw a visually accurate trend with only 100 points, regardless of whether the time period was one year or one hour.

Since the Trend Sampling mode does not need to acquire all data between the specified start and end times, it is a very efficient method of data retrieval, especially for large data sets. Depending on the requested start and end times (and the amount of data stored for that interval), it could be as much as 100 times faster than other methods.

When displaying data for reports or examination, this principle can be applied to other sampling types too. It is highly inefficient to trend data at a higher resolution than can be drawn on screen or printed on hard copy. This is useful even for calculation modes like "Average value". It is not suitable for Interpolated mode, since this results in a loss of detail that ihTrend sampling attempts to recapture.

The ihTrend sampling type returns adjacent highs and lows within each interval. If you ask for 100 samples, you will effectively receive 50 high values and 50 low values over 100 intervals. The retrieval process works as follows:

  1. Divide the query duration into even-length intervals, like other sampling modes.
  2. Determine the raw minimum and raw maximum for each interval. If there is only one point, then that is both the minimum and maximum.
  3. Since we want to return 2 samples per interval (a minimum and a maximum), we need twice as many intervals. Divide each interval in half. For example, a one hour interval of 01:00:00 to 02:00:00 becomes 2 intervals (01:00:00 to 01:30:00) and (01:30:00 to 02:00:00) .
  4. Put the minimum in one half-interval and the maximum in the other. If minimum comes before maximum, put the minimum in the first half-interval and the maximum in second half-interval, and vice versa.

When doing filtered data queries, your maximum returned intervals must pass the throttle, even if only a few intervals actually match the filtered criteria.

Timestamp

There is no difference between full-interval timestamps and half-interval timestamps. Both are valid and all interval timestamps are in ascending order.

The Trend Sampling mode will always have an even number of samples, rounded up when necessary.

For example, if you request num samples = 7 or num samples = 8, you will get 8 samples.

If you request results by interval instead of number of samples, you will get back twice the number of results you expect.

For example, a 5-minute interval for a 40-minute duration is normally 40 / 5 = 8 samples. But with trend sampling, you get 16 evenly-spaced intervals.

Value
The raw minimum or raw maximum of the full interval. There is no indication as to which one you are getting.
Data Quality

Trend sampling uses the same logic as interpolated sampling to determine the percent good quality.

Example: Retrieving trend sample value

Using the data from the interpolated example, execute this query

select timestamp, value, quality from ihrawdata where samplingmode=trend and timestamp >= 
'29-Mar-2002 13:50' and timestamp <= '29-Mar-2002 14:30' and tagname  = tag1 and numberofsamples = 8

The following results are returned:

TimestampValueQualityRaw Samples
29-Mar-200213:55:00.00022.70100.00None
29-Mar-200214:00:00.00022.70100.0013:59:00.000,22.7, Good
29-Mar-200214:05:00.00012.50100.00None
29-Mar-200214:10:00.00012.50100.0014:08:00.000,12.5, Good
29-Mar-200214:15:00.0007.00100.0014:14:00.000,7.0, Good
29-Mar-200214:20:00.0007.00100.00

The interval timestamps are the same as for interpolated. The raw minimum and raw maximum are determined for each interval.

For example, a tag has data every second for 1 year (around 31 million data points). We want to perform a query using ihTrend with StartTime = LastYear, EndTime = now, and NumSamples = 364.

The StartTime to EndTime is broken down into NumSamples/2 pseudo-intervals (182). For each pseudointerval, the min and max value is found. These will be the first two data points. With two data points per pseudo-interval multiplied by NumSamples/2 gives us the desired NumSamples. If the minimum occurs before the maximum, it will be the first of the two samples, and vice versa.

The query:

select timestamp, value, quality from ihrawdata where samplingmode=lab and timestamp >= 
 '29-Mar-2002 13:50' and timestamp <= '29-Mar-2002 14:30' and tagname  = tag1 and numberofsamples = 8

The following results are returned:

TimestampValueQuality
29-Mar-200213:55:00.0000.000.00
29-Mar-200214:00:00.00022.70100.00
29-Mar-200214:05:00.00022.70100.00
29-Mar-200214:10:00.00012.50100.00
29-Mar-200214:15:00.0007.00100.00
29-Mar-200214:20:00.0007.00100.00
29-Mar-200214:25:00.0004.80100.00
29-Mar-200214:30:00.0004.80100.00

Example: Trend Data returned in the wrong interval

Note that, with trend sampling, data can be returned using an interval timestamp that does not contain the sample. A CSV file includes three values for each of 9 days.

[Data] 
Tagname,TimeStamp,Value 
Dfloattag5,01/05/03 8:00,95.00
Dfloattag5,01/05/03 15:00,88.00
Dfloattag5,01/05/03 16:00,80.00
Dfloattag5,01/06/03 7:00,11.00
Dfloattag5,01/06/03 10:00,13.00
Dfloattag5,01/06/03 13:00,93.00
Dfloattag5,01/07/03 8:00,99.0
Dfloattag5,01/07/03 11:00,86.0
Dfloattag5,01/07/03 12:00,16.0
Dfloattag5,01/08/03 8:00,0.00
Dfloattag5,01/08/03 12:00,99.00
Dfloattag5,01/08/03 14:00,100.00

If you use the following query:

Select timestamp,tagname,value Quality from ihrawdata where tagname =dfloattag5
And samplingmode= trend and intervalmilliseconds =24h
And timestamp>  ?1/02/2003 07:00:00 and timestamp<=  ?01/10/2003 12:00:00 ?

then the results include:

TimestampTag NameValueQuality
6-Jan-200319:00:00 Dfloattag513.00100
7-Jan-200307:00:00 Dfloattag593.00100
7-Jan-200319:00:00Dfloattag599.00100
8-Jan-200307:00:00Dfloattag516.00100

It is expected that the value 93 is listed for 1/6/03 19:00:00, since that is where the timestamp of the raw sample occurs. However, the maximum of 1/6/03 07:00:00 to 1/7/03 07:00:00 is:

Dfloattag5,01/06/03 13:00,93.00

which comes after the minimum of:

Dfloattag5,01/06/03 10:00,13.00

Hence, it is placed in the second half-interval, even though its timestamp does not fall into the time range for that half-interval. Raw samples will never be placed in the wrong "real" interval, but may be placed in the wrong "fake" interval.

Anticipated Usage

Trend sampling is designed only for graphical plotting applications.