influxdata / influxdata/kapacitor

How to define a constant from the result of a query

Open
#1,883 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

Hello

from a newbie :

how to define a constant ( aka NOT time stamped) , declined from values returned by a select / query .
I wish to "normalized" data series, so I need to tranform the values of a given interval, via the max / min on the same interval.
So firts I query the data set to extract the min and max , I get two values , but time stamped ( at the beginning of the interval)

then I query the data set
and then try to "eval" the normalized data ( value - min) / ( max -min).

in order to avodi issue , variable min, max are set to 1.0 before their query

As I go no return with the formaul above, , for testing I remove the (max - min) factor.

Thhe I get the result , value - 1 , ( teh initial constant) .
I suspect taht the fatc that my min and max are time stamp prevents to use them with other time satpned data , not with teh same time stamp.

hence the question on how to set a constant , from data issue of a query with time stamp.

part of the code :

var period = 15m
var every = 1m
var CustTag = 'app'
var Object = 'devaddr'
var groupBy = [CustTag, Object]
var indicator = 'rssi'
var db = 'telegraf'
var rp = 'autogen'
var measurement = 'mqtt_consumer'

//set constant variable names
var indicator_mean = 1.0
var indicator_stddev = 1.0
var indicator_min = 1.0
var indicator_max = 1.0
var indicator_normed = indicator+'-normalized'

var last_period_stat = batch
|query('SELECT mean('+indicator+') AS indicator_mean, stddev('+indicator+') AS indicator_stddev, max('+indicator+') AS indicator_max , min('+indicator+') AS indicator_min from '+db+'.'+rp+'.'+measurement)
.groupBy(groupBy)
.period(period)
.every(every)
.align()
.offset(1m)
|log()
// shift data back from beginning of period
// for debugging purpose, log into /var/log/kapacitor/kapacitor.log
|shift(period)
|log()

// normalize the data
var last_period = batch
|query('SELECT ('+indicator+') from '+db+'.'+rp+'.'+measurement)
.groupBy(groupBy)
.period(period)
.every(every)
.align()
|shift(period)
|log()
// the retunr filed is "rssi" , 15 value ( period = 15m)

last_period
|union(last_period_stat)
.rename('lpf')
|log()
// use diretcly the name of the filed, as not having found the way to parameterize it so far
|eval(lambda: ((float("rssi") - float(indicator_min))))
.as(indicator_normed)

|log()

thanks in advance
Philippe

Contributor guide

Open the contributing guide

Research direction

No file, test, or entry point is named. Start by reviewing the batch query, union, shift, and eval usage in the issue, then determine whether timestamp alignment or variable scoping causes the result. Done means documenting a supported way to reuse query-derived min and max values in the normalization expression.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
stream-processing
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.