How to reverse a value?

Having googled a bit this link may be helpful. Calculate percentages with Flux | InfluxDB Cloud (TSM) Documentation.

1 Like

Thank you, I already found that site a couple days ago but couldnā€™t figure out how to do it like described there.
Iā€™ll have another look and see if I can understand now.

With flux being deprecated, do you know what the recommended method of querying in Grafana will be?

I honestly donā€™t know. In influx I go in my bucket, check my datapoint and click on script builder.
Then I have this code:

from(bucket: "boden-wz")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "monstera")
  |> filter(fn: (r) => r["_field"] == "value")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Thatā€™ll just copy-paste in grafana.
Tbh Iā€™m totally new to all this. I just followed some tutorials and failed around.
My target was to play through a tool chain to see if I can do it.
So I hope my answer helps a bit, I wish I could tell more.

Ok so in influx it makes sense I guess. I just donā€™t know how to name the value, everything I tried so far, failed.


  |> map(fn: (r) => ({ r with _value:  100.0 * (2850.0 - "_field") / (2850.0 - 1250.0) }))

Where did you put that? Before the aggregateWindow or after it?
Doesn't the yield at the end name it?

You would save influx a little time by using

{ r with _value: 0.0625 * (2850.0 - "_field")}

Yes, I put it right before that line.

Itā€™s also just a string,:

  |> yield(name: "mean")

Just like that? Not the map before it?

  |> map(fn: (r) => ({ r with _value: 0.0625 * (2850.0 - "_field")})

It doesnā€™t matter btw if itā€™s field or mean, the error stays the same, itā€™s expecting an float but I have no idea what language that is, so I donā€™t know how to google how I convert that string

What else can the name be? I apparently don't understand what you mean by not knowing how to name it.

With the map, I was just suggesting a simpler formula to use (100/(2850-1250) is 0.0625)

You did not say there is an error, I thought it was working but with the wrong name against the line. What is the error?

Well, somehow I have to address the value or the variable itā€™s in. Thatā€™s what I meant with that.

Ah, sorry I didnā€™t get that before.


error @5:58-5:66: expected float but found string

OK, I understand. Try

 |> map(fn: (r) => ({ r with _value: 0.0625 * (2850.0 - r._value) })
1 Like

That gives me a different error:

compilation failed: error @7:6-7:70: expected RPAREN, got EOF

Looks like you have lost a right parenthesis.
If you can't see it post the whole query here

Edit: there should be another one on the end.

1 Like

Yes, now it looks pretty good!
Thank you very much! Hopefully will some noobs (as me) find this thread and get helpful informations. The beginning is pretty harsh!

Excellent

2 Likes

Der einfachste Weg ist vermutlich
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.