Elapsed Function - Multiple rows

Hi all,
I’m working with sensor data to calculate cycle times for an assembly process. For a given station, the cycle time starts and ends with given sensor readings, with one or more intermediate steps taken. I am currently querying data from influxdb using the python client and calculating the cycle times using pandas using a combination of for loops and if conditions.

I am working to port this work to flux, so that cycle time data can be displayed in a histogram on dashboard. Any thoughts on how I can incorporate this workflow? The sticking point for me is including multiple rows within a map function. Ultimately I will likely use this as influx task to push cycle times to a new bucket.

Psuedocode below- In this example cycles start at sensor 1 and end at sensor 4 and must pass through 2 and 3 between.

cycletimes = new list
sensordata = data from query

for rows in sensordata:
if sensordata.row.property = sensor1:
starttime = sensordata.row.time
while sensordata.row.property != sensor2:
continue
while sensordata.row.property != sensor3:
continue
while sensordata.row.property != sensor 4:
continue
endtime = sensordata.row.time
cycletimes.append(endtime-starttime)

Hello @coste082,
So flux doesn’t have for loops, but this might still be possible.
Can you share some more detail about the structure of your data? Is sensor[1-4] a tag or a field?
Are you asking for non time-based windowing?

It would be helpful if you shared your input data like sensordata and what you want in your output. It would be extra helpful if you could export that to CSV from the UI in the Data Explorer and share that here.

I’ll sort of psuedo translate your psuedocode:

sensordata = from(bucket:"mybucket") |>range(start: <far back enough to contain all of your data) |> filter(...top most level filter to include everything you want to filter by later). 

sensor1 = sensordata |>filter(...for sensor1) |> first() findRecord(fn: (key) => true), idx: 0)

starttime = sensort1._time 

passthrough = I'm confused here about the while and continue statements

stoptime = passthrough |> last() findRecord(fn: (key) => true), idx: 0)