Repeating Motif Plot in Graph: Query Assistance Needed

I’m currently working on visualizing motifs in a time-series data set using InfluxDB, and I’m facing a challenge in repeating a specific motif plot throughout the entire graph. Below is the query I’ve attempted:

from(bucket: "motifs_1")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "motifs_per_signal")
  |> filter(fn: (r) => r["_field"] == "sensor_reading")
  |> filter(fn: (r) => r["sensor_name"] == "[3:25]")
  |> filter(fn: (r) => r["motif_name"] == "Motifs_1")
  |> window(every: 40s)
  |> fill(column: "_value", usePrevious: true)

I’d like to repeat this motif plot throughout the entire graph, but my attempts haven’t been successful. Could someone please guide me on how to properly structure the query to achieve this? Any insights or suggestions would be greatly appreciated. Thank you!

Hi - Could you please share more info on what you are seeing (screenshot of your output maybe?)?

Yes, sure here is the output I am getting:

Here, I want to repeat this same pattern in the whole graph but it is not getting repeated currently.

Can you click on the view raw data and see if the data exists throughout that time period? Or are you saying that you want to fill the gaps with generated data through that time period?

Also - BTW - using a window function without an aggregate isn’t common. And the fill function operates on a row level, not a window level.

Yes, I simply want to plot this same pattern throughout the graph. So I was trying to fill out the gaps with this generated data which is just the actual data for the plot which I am trying to repeat.

The tricky part her is that you’re trying to fill both forwards and backwards. While it think it’s possible, it’s a trick thing to pull off. A few questions:

  • What is your use case here?
  • Is it important that the existing data keep its timestamp or is the timestamp arbitrary?
  • The screenshot of the graph you provided appears to have two separate series (blue and purple)? Or is that a single series split across two windows?

My use case here is to repeat the graph. The timestamps are arbitrary. I only have data for a time range of 40 seconds and I just want to repeat this for the entire graph.

I’ve tried a few different approaches to solve this problem with Flux, but have run into road blocks each time. The closest thing that I think could would work would be to somehow use the returned result to generate an algorithm to seed generate.from(), but I’m not sure how feasible that is either.

Can you please provide me any query based on my use case for this. I will try it to see if it works for me or not.

This isn’t something you’ll be able to do at query time with any of the available query languages for InfluxDB v2. The challenge is taking existing data and using it to synthetically fill the queried time range. I was getting close using Flux, but ran into an issue with Flux having to re-read and union the same table more than once. It’s a blocker that I can’t find a way around.

I’ve attempted a different approach to display the same graph across the entire dashboard range. I tried transforming the data with time intervals using a query, but it’s only showing a straight line. My inspiration came from plotting a sine wave with a similar query. In that case, I passed a static array, transformed it, and the graph remained consistent regardless of the time range. I aim to achieve the same outcome with this query.

This is the query for the sine plot:


import "experimental/array"

import "math"

import "date"

start = v.timeRangeStart

end = v.timeRangeStop

duration = int(v: end) - int(v: start)

x_values = [

{x: 0.0},

{x: 0.1},

{x: 0.2},

{x: 0.3},

{x: 0.4},

{x: 0.5},

{x: 0.6},

{x: 0.7},

{x: 0.8},

{x: 0.9},

{x: 1.0},

{x: 1.1},

{x: 1.2},

{x: 1.3},

{x: 1.4},

{x: 1.5},

{x: 1.6},

{x: 1.7},

{x: 1.8},

{x: 1.9},

{x: 2.0},

]

array.from(rows: x_values)

>> map(fn: (r) => ({ _time: time(v: int(v: start) + int(v: r.x * float(v: duration))), _value: math.sin(x: 2.0 * math.pi * r.x) }))

>> keep(columns: ["_time", "_value"])

This is the query I attempted:


import "math"

import "date"

start_time = () => {

timeRecord = from(bucket: "motifs_timestamp")

>> range(start: 0)

>> filter(fn: (r) => r["sensor_name"] == "[3:25]")

>> filter(fn: (r) => r["timestamp"] == "start")

>> findRecord(fn: (key) => true, idx: 0)

return timeRecord._time

}

end_time = () => {

timeRecord = from(bucket: "motifs_timestamp")

>> range(start: 0)

>> filter(fn: (r) => r["sensor_name"] == "[3:25]")

>> filter(fn: (r) => r["timestamp"] == "end")

>> map(fn: (r) => ({_time: r._time}))

>> findRecord(fn: (key) => true, idx: 0)

return timeRecord._time

}

data = from(bucket: "motifs_timestamp")

>> range(start: start_time(), stop: end_time())

>> filter(fn: (r) => r["_measurement"] == "motifs_per_signal")

>> filter(fn: (r) => r["_field"] == "sensor_reading")

>> filter(fn: (r) => r["sensor_name"] == "[3:25]")

>> filter(fn: (r) => r["motif_name"] == "Motifs_1")

>> map(fn: (r) => ({ r with x: r._value }))

duration = int(v: end_time()) - int(v: start_time())

x_values = data

>> map(fn: (r) => ({ _time: time(v: int(v: start_time()) + int(v: r.x * float(v: duration))), _value: r.x }))

>> keep(columns: ["_time", "_value"])

>> yield()

Can you suggest what can be the issue with this query and how can I fix it. Also if any better approach exists for this, please let me know.