Hi,
I have the following query returning a table with one row containing the mean liquid level in a tank between time t1 and t2
The flux script is run from Jupyter using influxdb_client v1.24.0 Python library
start_time = "2022-01-14T00:00:00Z"
stop_time = "2022-01-15T00:00:00Z"
q=f'''
level = (t1, t2) =>
from(bucket: "machines")
|> range(start: t1, stop: t2)
|> filter(fn: (r) =>
r._measurement == "SN000022" and
r.equipment == "T5001" and
r.data == "level" and
r._field == "value"
)
|> mean(column: "_value")
|> group()
|> last()
|> keep(columns: ["_value"])
lvl = level(t1: {start_time}, t2: {stop_time})
lvl
'''
data = db_query_api.query(query=q)
data[0].records[0]
for table in data:
for record in table:
print(record.values)
Output:
{‘result’: ‘_result’, ‘table’: 0, ‘_value’: 81.68066269004727}
This works as expected, so far so good:
Then I would like to return just the value of ‘_value’, from within the Flux script, in order to use the value as input to another query, using findColumn:
As per: Extract scalar values in Flux | InfluxDB OSS v1 Documentation and
lvl |> findColumn(fn: (key) => true, column: "_value")
Output:
ApiException: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({‘Content-Type’: ‘application/json’, ‘Request-Id’: ‘6a5216a1-8a70-11ec-8061-a2d2df923187’, ‘X-Influxdb-Build’: ‘OSS’, ‘X-Influxdb-Error’: ‘type error 18:8-18:18: undefined identifier “findColumn”’, ‘X-Influxdb-Version’: ‘1.8.3’, ‘X-Request-Id’: ‘6a5216a1-8a70-11ec-8061-a2d2df923187’, ‘Date’: ‘Thu, 10 Feb 2022 12:53:16 GMT’, ‘Content-Length’: ‘71’})
HTTP response body: b’{“error”:“type error 18:8-18:18: undefined identifier \“findColumn\””}\n’
Then trying to use findRecord instead:
As per: findRecord() function | Flux Documentation
lvl |> findRecord(fn: (key) => true, idx: 0)
Output:
ApiException: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({‘Content-Type’: ‘application/json’, ‘Request-Id’: ‘5162dc08-8a70-11ec-8008-a2d2df923187’, ‘X-Influxdb-Build’: ‘OSS’, ‘X-Influxdb-Error’: ‘type error 20:8-20:18: undefined identifier “findRecord”’, ‘X-Influxdb-Version’: ‘1.8.3’, ‘X-Request-Id’: ‘5162dc08-8a70-11ec-8008-a2d2df923187’, ‘Date’: ‘Thu, 10 Feb 2022 12:52:34 GMT’, ‘Content-Length’: ‘71’})
HTTP response body: b’{“error”:“type error 20:8-20:18: undefined identifier \“findRecord\””}\n’
So what do I do wrong since I am not able to get these functions to work and extract that single value?
Any help is very much appreciated.
Thanx