Hi Everyone!
I’m quite new to Flux/Influx and need some help some help with an appropriate query that can rank incoming values and then assign one of several possible categories based on the specific rank order.
To provide some background, we have Bluetooth tags attached to pigs in several pens at an indoor farm, where each pen has five gateways positioned around its edges. Each tag broadcasts a unique identifier (MAC address) which is recorded by each gateway that is in range, and every two seconds each gateway will upload to InfluxDB the tags it has seen during that period along with a signal strength value (RSSI) for each broadcast received. We require the flux query to identify the five gateways with the highest RSSI values for each tag during a given time interval, and then determine which pen the tag is in based on a lookup table or similar (e.g. if gateways with highest reported RSSI are A,B,C,D, and E, the tag is in pen 1, if F,G,H,I,J, the tag is in pen 2, etc.). This would then be outputted to another bucket.
The example query and screenshot below detail the RSSI value (r[“_field”] == “r”), tag id (r[“d”]), and gateway id (r[“g”]).
from(bucket: "pilot")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "x")
|> filter(fn: (r) => r["_field"] == "r")
|> filter(fn: (r) => r["d"] == "24C3")
|> aggregateWindow(every: 300s, fn: mean, createEmpty: false)
Any guidance here would be greatly appreciated, thank you!