Hi,
I want to make easy ‘if’ on my historical data using kapacitor replay
if Status1 > 0 and Status2 > 0 then 2
else if Status1 > 0 then 1
else 0
Due to it I join two batch data:
time Status1
2019-09-28T00:00:41.546Z 0
2019-09-28T00:01:41.546Z 0
2019-09-28T00:02:41.546Z 0
2019-09-28T00:03:41.546Z 0
2019-09-28T00:04:31.746Z 1
2019-09-28T00:04:41.546Z 1
2019-09-28T00:05:41.546Z 1
and
time Status2
2019-09-28T02:58:00.000Z 1
2019-09-28T03:02:00.000Z 0
2019-09-28T06:52:00.000Z 1
2019-09-28T06:58:00.000Z 0
2019-09-28T14:12:00.000Z 1
2019-09-28T15:18:00.000Z 0
2019-09-28T16:08:00.000Z 1
2019-09-28T16:36:00.000Z 0
And my script is that:
var Status1 = batch
|query(' SELECT Status1 AS "BB" FROM "chronograf"."autogen".S1')
.period(1m)
.every(1m)
.fill(0.0)
var Status2 = batch
|query(' SELECT Status2 AS "S2" FROM "chronograf"."autogen".S2')
.period(1m)
.every(1m)
.fill(0.0)
Status1
|join(Status2 )
.tolerance(1m)
.as('Status1', 'Status2')
.fill(2.0)
|default()
.field('Status1', 0)
.field('Status2', 'previous') //information only with status change
|eval(
lambda: if("Status1.S1" > 0, if("Status2.S2" > 0, int(1), int(2)), int(0)),
lambda: "Status1.S1",
lambda: "Status2.S2"
)
.as('3LevelFlag', 'S1', 'S2')
.keep('3LevelFlag', 'S1', 'S2')
|influxDBOut()
.create()
.database('chronograf')
.retentionPolicy('autogen')
.measurement('3LevelStatus')
In 3LevelStatus result is that:
- ‘if’ result is incorrectly, I observe only 2 and 0.
- S1 and S2 is different from Status1 and Status2, and when I manipulate the tolerance and default field I observe sometimes S1 is correct and S2 is 2, sometimes S2 is correct and S1 is 2 or 0, but never both.
It is a bug, or maybe I do something wrong?
I use kapacitor version 1.5.3 on docker on Ubuntu 18.04.
The result of the script is:
> time 3LevelFlag S2 S1 Status1 Status2
> 2019-09-28T02:57:41.551Z 0
> 2019-09-28T02:58:00.000Z 0 0 0 1
> 2019-09-28T02:58:41.551Z 0
> 2019-09-28T02:59:31.751Z 0
> 2019-09-28T02:59:41.551Z 0
> 2019-09-28T03:00:00.000Z 0 0 0
> 2019-09-28T03:00:41.551Z 0
> 2019-09-28T03:01:41.551Z 0
> 2019-09-28T03:02:00.000Z 0 0 0 0
> 2019-09-28T03:02:41.551Z 0
> 2019-09-28T03:03:41.551Z 0
and it is no matter if i join Status1 to Status2 or vice versa the result is the same, S2 is not filled with Status2 value.