How to integrate flow data that comes in at irregular times: area under curve

I have flowrate data (liters per minute) coming in from a sensor, but it comes in at irregular times. Every 10 seconds to a minute. The data goes into a InfluxDB v1.8.

I’d like to query for the total flow (liters) in the previous hour. The query I’m using doesn’t seem to be right.

SELECT INTEGRAL(“value”) AS “totalflow” FROM “telegraf”.“autogen”.“data” WHERE time > now() - 1h AND “topic”=‘flow_sensor’

I get a value of a like over 3800 Liters, which isn’t correct. It should be less than 300 Liters I think. I’m not sure what’s wrong with the query.

Hi @jason2

The INTEGRAL() function calculates the area under the curve, but it defaults to a one-second unit of time unless you specify otherwise.

Your data is in Liters per Minute (L/min), but INTEGRAL() (as you have it now) assumes your rate is per second. I believe this explains why your result is roughly 60 times larger than it should be.

To get the correct volume, you need to tell InfluxDB that your data points represent a rate per minute by adding a time duration to the function. Try this and see what you get.

SELECT INTEGRAL("value", 1m) AS "totalflow" 
FROM "telegraf"."autogen"."data" 
WHERE time > now() - 1h 
AND "topic"='flow_sensor'
1 Like

yes, that’s it. Thank you @grant1

Great. Please mark above as solution so others can benefit in the future.