# Numerical Integration / Area under the curve

**URL:** <https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553>\
**Category:** General\
**Created:** [31 January 2022 14:42 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553 "2022-01-31T14:42:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mufika](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Mufika](https://discourse.nodered.org/u/Mufika)\
**Post date:** [31 January 2022 14:42 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/1 "2022-01-31T14:42:38Z")

</div>

I have an series of points of the phase current values from an ammeter I'm looking for node or code to integrate these values (area under the curve) in order to calculate the energy consumed (kWh).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 January 2022 21:42 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/2 "2022-01-31T21:42:45Z")

</div>

Where are the data coming from? If from a database then you may be able to do it in the query.  
If not, are the time intervals between samples fixed?

---

<div class="post-metadata">

**Author:** ![Mufika](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Mufika](https://discourse.nodered.org/u/Mufika)\
**Post date:** [31 January 2022 23:00 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/3 "2022-01-31T23:00:59Z")

</div>

The data is coming from an influxdb database. I would like to integrate the data for the current day and also for the current month. Is there is a query that can continuously adjust the starting time, i.e. "now() - variableX"

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 February 2022 15:26 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/4 "2022-02-01T15:26:23Z")

</div>

What are the units of the data? Maybe kW or kWH or something similar.

Are the samples regularly spaced and will they all be present over the time range of interest?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 February 2022 21:13 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/5 "2022-02-01T21:13:34Z")

</div>

There is also this node [node-red-contrib-watt2kwh (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-watt2kwh) that may help if you are looking at power... or it may give you some clues

---

<div class="post-metadata">

**Author:** ![Mufika](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Mufika](https://discourse.nodered.org/u/Mufika)\
**Post date:** [1 February 2022 21:45 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/6 "2022-02-01T21:45:00Z")

</div>

The units are current data points. I think I would try integrate using the trapezoidal method (approximation). The time step are for most the same but there may at time a difference.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 February 2022 21:49 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/7 "2022-02-01T21:49:38Z")

</div>

See [influxdb INTEGRAL](https://nodered.org/docs/getting-started/raspberrypi)

---

<div class="post-metadata">

**Author:** ![Mufika](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Mufika](https://discourse.nodered.org/u/Mufika)\
**Post date:** [13 February 2022 18:04 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/8 "2022-02-13T18:04:55Z")

</div>

The integral function of influxdb v2 works quite well indeed with flux language.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 April 2022 18:05 UTC](https://discourse.nodered.org/t/numerical-integration-area-under-the-curve/57553/9 "2022-04-14T18:05:52Z")

</div>

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