It is possible to run queries that analyse time series of data obtained from TSD streams that are linked to objects in the network. This is achieved using time series expressions as described in detail in Theory of time series expressions.
The time series expressions approach to analysing time series data is very different from the approach taken for analysing time series results. In particular:
The two basic operations that are required for use of time series data in InfoAsset Manager are loading of a time series (from a TSD data stream) and aggregation of a time series (to obtain a single number that can then be displayed or used in other calculations). In between, there can be any number of time series expressions to combine and transform the loaded data.
Data loading is done by the TSLOAD function, which loads data from one of the TSD streams listed in the time series links associated with an object. The link to use is identified by its description and the start and end times to load are specified explicitly. The units of measurement must also be specified explicitly. For example, if the object has a time series link named FFT that points to a TSD stream containing flow data, then data for the past week can be loaded into a variable $flow by the statement:
SET $now = NOW(); get the current time
SET $flow = TSLOAD("FFT", "m/s",$now-7,$now);
Aggregation is done by the TSAGGREGATE function, which calculates a specified statistic over a specified time period. For example, to find the maximum flow during the past day for the data loaded above:
SET $maxflow = TSAGGREGATE($flow, $now-1, $now, "MAX", 1);
A more complex and complete example would be:
Choose a period to analyse :
LET $end = NOW();
SET $start = $end - 7;
Load H2S data for this period :
SET $h2s = TSLOAD("H2S", "mg/l", $start, $end);
Get maximum H2S and time of maximum
SET $maxh2s = TSAGGREGATE($h2s, $start, $end, "max", 1.0);
SET $maxtimeh2s = TSAGGREGATE($h2s, $start, $end, "maxtime", 1.0);
We want to look at what was happening in the 3 hours before the peak H2S
SET $maxtimeh2sminus3 = $maxtimeh2s - 3.0/24.0;
Load flow data for this period and calculate the mean:
SET $prevfft = TSLOAD("FFT", "l/s", $maxtimeh2sminus3 , $maxtimeh2s);
SET $prevfftmean = TSAGGREGATE($prevfft, $maxtimeh2sminus3 , $maxtimeh2s, "mean", 1.0);
Present the results for all objects that have links to H2S data:
SELECT asset_id, DATETIMEFORMAT($maxtimeh2s ,"dd/MM/yyyy", "HH:mm") AS 'Time of Max H2S', $maxh2s AS 'Max H2S', $prevfftmean AS 'Mean FFT in previous 3 hours' WHERE $maxh2s IS NOT NULL;
Time series expressions can be used to combine and transform the loaded time series, as shown in the following (slightly contrived) example using time series links called A, B and C to streams that have no units:
LET $end = NOW();
SET $start = $end - 7;
SET $a = TSLOAD("A", "", $start, $end);
SET $b = TSLOAD("B", "", $start, $end);
SET $c = TSLOAD("C", "", $start, $end);
SET $d = 5.4 + $a + 2*$b*$b + POW($c, 3);
SET $maxd = TSAGGREGATE($d, $start, $end, "max", 1.0);
As can be seen, the time series expression looks identical to an equivalent expression that might be used to combine individual values from a single time step of each of the series. Because this expression includes whole time series, the calculations are instead carried out using the entire set of values within each time series, yielding a new time series. See Theory of time series expressions for more details.