0

I have a dashboard where I am viewing the last 24 Hours of data from my Ethereum mining equipment. I am storing: ETH Price and Miner Balance. I have the following code to bring out the data, but I am multiplying by a constant of 1925.25 currently instead of using the actual ETH price.

I want to be able to use the LAST VALUE from the ETH Price as a constant there instead of always typing something in. Here is the current query:

from(bucket: "Mining")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Miner")
  |> filter(fn: (r) => r["_field"] == "balance")
  |> filter(fn: (r) => r["tag1"] == "ethermine")
  |> map(fn: (r) => ({r with _value: (float(v: r._value) / 1000000000000000000.0) * 1925.25 }))
  |> aggregateWindow(every: 1h, fn: last)
  |> derivative(unit: 1h, nonNegative: true, columns: ["_value"])
  |> cumulativeSum(columns: ["_value"])

The field "price" is the ETH Price. I would like to be able to use the last value instead of the constant 1925.25. I can't seem to find any good examples of this out there :(

EDIT: This is what I tried to figure out how to do and use:

eth_value = from(bucket: "Mining")
  |> range(start: -1m)
  |> filter(fn: (r) => r["_measurement"] == "Miner")
  |> filter(fn: (r) => r["tag1"] == "flexpool")
  |> filter(fn: (r) => r["_field"] == "price")
  |> last()

It works without using eth_value = - to get the value I want. But I can't seem to set it to a variable for usage later.

Andrew
  • 437
  • 7
  • 18

1 Answers1

0

You didn't state what the nature of the error was, so I'll go on what I can assume - the issue may be the nature of the eth_value being of either the wrong type or containing more than one value.

Try putting,

|> keep(["_value"]

after the last() in the eth_value assignment and casting eth_value to be a float,

  |> map(fn: (r) => ({r with _value: (float(v: r._value) / 1000000000000000000.0) * float(v: eth_value) }))

(Of course, make sure you define eth_value before you use its value!)

FractalDoctor
  • 2,496
  • 23
  • 32
  • Sorry, didn't see this until now as I'm revisiting the problem. I did the above, but used: |> keep(columns: ["_value"]) That gives me a result, but then I can't use eth_value in the mapping. When I put it in there as you suggest above, I get the error: "An internal error has occurred" :( – Andrew Jul 16 '21 at 18:47
  • That's a pain. I'd encountered internal errors a few times with some versions when I'm talking to external databases or trying queries that are quite complex. Unfortunately I never got to the root of them but a later version often fixed the issue. Might be worth posting it on the Influx community forums perhaps? – FractalDoctor Jul 19 '21 at 12:29