Counting gaps between data

Hello,

I will just warn that I’m relatively new to all this so please bear with me.

I have a sensor the sends data to my bucket every couple of seconds. This happens for 30 minutes and then stops for 15 minutes. I would like to create a Task that tracks how many of the cycles there has been. Is this possible in Flux and if so how would I go about it?

For example if my sensor runs for 6 hours without stopping I would like a field that has calculated the number of cycles, which would be 8.

We will have up to 50 sensor all doing this cycle but they will have been started at different points and maybe be paused and restarted. The goal of this is to track the amount cycles each sensor has done.

If you have any questions, please let me known!

Best,
Archie

@ArchieC Just to clarify the pattern you’re looking for:

  • Is 30 minutes on, 15 minutes off the expected pattern or one that you’re trying to identify/troubleshoot?
  • Is there anything in our data that identifies the beginning and/or end of a cycle?

Hi Scott,

Thank you for the reply.

  • Is 30 minutes on, 15 minutes off the expected pattern or one that you’re trying to identify/troubleshoot?

    • Expected.
  • Is there anything in our data that identifies the beginning and/or end of a cycle?

    • Unfortunately no.

To expand on my original question with an example:

This is basic example data (The actual data is more frequent, have more fields and there are multiply sensor each with its own ID).

Time Value (_field) ID (_Tag)
10:29 150 22
10:30 151 22
10:45 154 22
10:46 151 22
11:14 152 22
11:15 149 22
11:30 150 22

Here we have a cycle that runs from 10:00 to 10:30, breaks till 10:45, runs till 11:15, break till 11:30 etc.
I would like to see a extra field and/or bucket generated that looks like the below.

Time Cycle Count(_field) ID (_Tag)
10:45 1 22
11:30 2 22

So its seen that there was a greater than 10 minute gap between a reading so its incremented the cycle count field for ID 22.

I hope that makes sense.

Thank you,

Archie

@ArchieC Perfect. That makes perfect sense. So I think what you can do here is detect that gap as the precursor to a new cycle. To do that:

1.Use elapsed() to returns the time between the current point and the previous point and store it in the elapsed column.
2. Use filter() to filter out rows with elapsed time less than 10-minutes to leave only those rows that represent the beginning of a new cycle.
3. Use map() to assign a new field key and set the _value to 1 (for the next step).
4. Use cumulativeSum() to essentially increment the cycle count:

sensorData
    |> elapsed(unit: 1m)
    |> filter(fn: (r) => r.elapsed > 10)
    |> map(fn: (r) => ({r with _field: "Cycle Count", _value: 1}))
    |> cumulativeSum()

That works great. Thank you!