"Zeroing" around a base value (SnapTo)
- Last UpdatedFeb 07, 2025
- 2 minute read
This analog filter lets you force values in a well-defined range around one or more base values to "snap to" that base value. For example, you can use this filter when a tank is known to be empty, but the tag that stores the tank level returns a "noisy" value close to zero.
The filter can be used with all retrieval modes, but its main benefits are in the aggregate retrieval modes: average, integral, minimum, and maximum.
To zero values around the base value, specify the SnapTo() filter in the wwFilter column of the query.
The syntax for this filter is:
SnapTo([tolerance[,base_value_1[, base_value_2]…]])
This filter has two parameters:
|
Parameter |
Valid Values |
Default Value |
|---|---|---|
|
Tolerance |
any double value |
0.01 |
|
BaseValue |
zero, one, or up to 100 comma-separated double values |
single base value of 0.0 |
The following are supported syntaxes.
-
SnapTo() – Same as SnapTo(0.01, 0.0)
-
SnapTo(3.7) – Same as SnapTo(3.7, 0.0)
-
SnapTo(3,) – Syntax Error
-
SnapTo(,0) – Syntax error
-
SnapTo(,) – Syntax error
-
SnapTo(3, 4, -5) – Tolerance=3, Base Values 4 and -5.
When the Snap to filter is specified, point values falling inside any of the ranges [Base value – Tolerance, Base value + Tolerance] will be forced to the base value before the point goes into further retrieval processing. The result is undefined if the base value +/- tolerance exceeds the range of the double data type. The range is calculated using this expression:
If (x <= Base value + Tolerance AND x >= Base value – Tolerance)
x = Base value
where x is the value of the point then if ranges overlap, the first matching base value will be used.
A query example from the History table looks like this:
SELECT DateTime, Value, wwFilter
FROM History
WHERE TagName = ('TankLevel')
AND DateTime >= '2008-01-15 15:00:00'
AND DateTime <= '2008-01-15 17:00:00'
AND wwRetrievalMode = 'Average'
AND wwResolution = 3600000
AND wwFilter = 'SnapTo(0.01, 0, 1000)'
The following rows might be returned:
|
DateTime |
Value |
wwFilter |
|---|---|---|
|
2008-01-15 15:00:00.000 |
0 |
SnapTo(0.01, 0, 1000) |
|
2008-01-15 16:00:00.000 |
875.66 |
SnapTo(0.01, 0, 1000) |
|
2008-01-15 17:00:00.000 |
502.3 |
SnapTo(0.01, 0, 1000) |
When a value is snapped, the QualityDetail bit flag 0x2000 is set.
If the filter syntax is not correct, a syntax error is returned and no rows are returned.