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.