buzzn / display-app

https://display.buzzn.io
0 stars 0 forks source link

Fix energy calculation #66

Closed scsirdx closed 6 years ago

scsirdx commented 7 years ago

We need to use the correct formula to calculate energy up to a specific point in time for a day.

dottorer commented 7 years ago

Correct formula to use: Sum all values in an hour interval and build mean value. Then add up all hourly kWh results for the day up to this point.

hr1 in kWh = (val1 in kW + val2 + val3 + val4) / vals_in_hour + hr2 = (val1 + val2 + val3 + val4) / vals_in_hour + … current_hr = (val1 + val2 ) / vals_in_hour = total_energy_up_to_moment in kWh

dottorer commented 7 years ago

Peer reviewed with @drthth ; Discovergy uses same approach as do others.

mkristian commented 7 years ago

@dottorer question: vals_in_hour is always 4 in the examples above ? or is the last one current_hr = (val1 + val2 ) / 2 = total_energy_up_to_moment in kWh ?

dottorer commented 7 years ago

@mkristian let's say the current hour is not completed yet and it is 17:35. We have only 2 values of 15-min increments, so we need to build the mean of the 2 values. For all full hour we can use 4 quarter hour values.

scsirdx commented 7 years ago

@mkristian

chunk(data, 4).reduce((sh, h) => (h.reduce((sv, v) => (sv + v.value), 0) / h.length) + sh, 0);

chunk is a function:

 chunk([1, 2, 3, 4, 5, 6], 4)   -> [[1, 2, 3, 4], [5, 6]]
mkristian commented 7 years ago

I got it now. for vals_in_hour look like a variable but it was a description of a number. thanks