Hi,
I’m trying to write a TICKscript that replaces missing values with average of last 5 points and write the new data to a bucket. Here is my code:
var currentDB = 'myDB'
var currentRP = 'autogen'
var measurement = 'machine26'
var field = 'sensor155'
var defval = batch
|query('select mean("sensor155") as "sensor155" from "myDB".autogen.machine26 limit 5')
.every(10s)
.period(10s)
.align()
var realdata = batch
|query('select "sensor155" as "sensor155" from "myDB".autogen.machine26')
.every(10s)
.period(10s)
.align()
realdata
|join(defval)
.as('realdata', 'defval')
.tolerance(15s)
|eval(lambda: if(isPresent("realdata.sensor155"), float("realdata.sensor155"), float("defval.sensor155")))
.as(sensor)
|influxDBOut()
.database('testDB')
.retentionPolicy(currentRP)
.measurement(measurement)
The thing I’m missing seems like the batch part that calculates the mean creates only one point. So join only creates one data point, whereas I want to check all points and if missing replace with the average. Also the first batch takes 5 points rather than last 5 valid points. I want to evaluate the last 5 valid points. I’m sure there must be a better way. How can I achieve this?
But still, this won’t replace null values, in fact I didn’t see any null values logged here even though I logged the data in different tickscript and it has null values. I guess I didn’t understand the null value condition here. At what interval Stream node checks the data? For example the script above logs data like in every one second. On the other hand:
this one logs data nearly at every one nanosecond(not sure if it’s called nanosecond). So which one is true? Should InfluxDB has data at every nanosecond or at every second or can we change this behavior? How does it decides if the value is null?