# Repeating Motif Plot in Graph: Query Assistance Needed

**URL:** <https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834>\
**Category:** Fluxlang\
**Tags:** influxdb, grafana, query\
**Created:** [April 5, 2024, 10:39am UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834 "2024-04-05T10:39:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Madhurima\_Rawat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/madhurima_rawat/32/15370_2.png) [@Madhurima\_Rawat](https://community.influxdata.com/u/Madhurima_Rawat)\
**Post date:** [April 5, 2024, 10:39am UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/1 "2024-04-05T10:39:28Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![gfowler](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/gfowler/32/18561_2.png) [@gfowler](https://community.influxdata.com/u/gfowler)\
**Post date:** [April 6, 2024, 12:13am UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/2 "2024-04-06T00:13:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Madhurima\_Rawat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/madhurima_rawat/32/15370_2.png) [@Madhurima\_Rawat](https://community.influxdata.com/u/Madhurima_Rawat)\
**Post date:** [April 6, 2024, 5:41am UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/3 "2024-04-06T05:41:05Z")

</div>

Yes, sure here is the output I am getting:

 ![Screenshot 2024-04-06 110559](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/a2d3cbcb9d491775a8b1aec25fc5685038689966.png)

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

---

<div class="post-metadata">

**Author:** ![gfowler](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/gfowler/32/18561_2.png) [@gfowler](https://community.influxdata.com/u/gfowler)\
**Post date:** [April 10, 2024, 6:52pm UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/4 "2024-04-10T18:52:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Madhurima\_Rawat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/madhurima_rawat/32/15370_2.png) [@Madhurima\_Rawat](https://community.influxdata.com/u/Madhurima_Rawat)\
**Post date:** [April 11, 2024, 6:36am UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/5 "2024-04-11T06:36:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 11, 2024, 2:20pm UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/6 "2024-04-11T14:20:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Madhurima\_Rawat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/madhurima_rawat/32/15370_2.png) [@Madhurima\_Rawat](https://community.influxdata.com/u/Madhurima_Rawat)\
**Post date:** [April 12, 2024, 4:40am UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/7 "2024-04-12T04:40:24Z")

</div>

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.

 ![Actual Plot to Repeat.png](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/4/42bb4ce273bfad6437bc6f7614a17d87e18b4460.png)

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 16, 2024, 5:26pm UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/8 "2024-04-16T17:26:01Z")

</div>

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()`](https://docs.influxdata.com/flux/v0/stdlib/generate/from/), but I’m not sure how feasible that is either.

---

<div class="post-metadata">

**Author:** ![Madhurima\_Rawat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/madhurima_rawat/32/15370_2.png) [@Madhurima\_Rawat](https://community.influxdata.com/u/Madhurima_Rawat)\
**Post date:** [April 17, 2024, 1:49pm UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/9 "2024-04-17T13:49:47Z")

</div>

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.

 ![98DDEDA5F538441C87FBF7EA5FA3F250.png](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/7/7e4f006e600be0e52228c99518845515fe779e3e.png)

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 17, 2024, 3:00pm UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/10 "2024-04-17T15:00:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Madhurima\_Rawat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/madhurima_rawat/32/15370_2.png) [@Madhurima\_Rawat](https://community.influxdata.com/u/Madhurima_Rawat)\
**Post date:** [April 17, 2024, 3:47pm UTC](https://community.influxdata.com/t/repeating-motif-plot-in-graph-query-assistance-needed/33834/11 "2024-04-17T15:47:58Z")

</div>

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:

```auto

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:

```auto

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.
