Bar graph - improvements

Hi,

I just discovered here that the "new" bargraph visualization can pull out daily kWh from a "total kWh" feed. In fact, you can choose any interval, but it can't show monthly/yearly kWh as the number of day per month/year is variable.

So, I made some modifications to be able to pull out the exact monthly and yearly kWh.
When configuring the bar graph, enter a interval code : "d" for daily kWh, "m" for monthly kWh and "y" for yearly kWh. It is still needed to set the "delta" parameter to "1". Entering an interval in seconds is still possible.

This view (daily/monthly/yearly) can also be modified dynamically by clicking on the kWh/D, kWh/M, kWh/Y buttons. Like for the zoom visualization, you can zoom-in/zoom-out by clicking on/outside a bar.

But, there is still a bug that need to be fixed. When calculating the daily kWh, it returns the kwh elapsed in 24h starting from an erratic time (20:13:30 in my example). It's the same erratic time for all days.  This time seems depend on the feed itself. THis comes from the return of the ajax request.

As a consequence, one can see on the graph (see attached), that there is a shift between the day on the x-axis and the bar of the corresponding day. According to me, the ajax request should return the kwh elapsed in 24h from midnight to midnight. This will align the bar on the x-axis.

Please find attached in a zip the two files I modified.

Eric

TrystanLea's picture

Re: Bar graph - improvements

Thanks Eric, that's brilliant, I was wondering where to start with getting the exact month/year data. Il take a look at the code.

Eric_AMANN's picture

Re: Bar graph - improvements

Hi,

I didn't put any comments ... but it's quite simple. How it works :

When the interval code is 'd' or 'm' or 'y', the interval in seconds is set to 84600 which correspond to 24h. Then, monthly/yearly kWh are just sums of the daily values of the corresponding month/year.

If you can, have a look on the problem explained above. (ajax request)

Eric

bodiroga's picture

Re: Bar graph - improvements

Hi guys!

Are this changes pushed to github? It seems that they are not added to the emoncms repository, but perhaps I haven't look at it correctly. Anyway, I have copied the two files manually to my emoncms installation (Ubuntu server running in a x86 box) and I have restarted my box, but I'm still seeing the same problem that Eric comments in his first post. Bars are not aligned to the corresponding day and if you pass the mouse over the bar, the date displayed corresponds to the previous day.

Eric, did I misunderstand your post or do your modified files should also fix the shifted bars problem?

Trystan, do you know how to fix the shifted bars problem? :(

Many thanks for your help and I'm looking forward to hearing from you, I wish I could solve this problem as soon as possible.

Best regards,

Aitor

Eric_AMANN's picture

Re: Bar graph - improvements

Hi,

I didn't push my modifications to github (I need to learn how to do it) but one can just overwrite the original file as you did (.../emoncms/Modules/vis/visualisations/bargraph.php and ../emoncms/Modules/dashboard/Views/js/widgets/vis/vis_render.js). No need to restart.

My modified files do NOT fix  the shifted bars problem. It only brings the daily/montly/yealy view. The bars are shifted because the kwh/d are calculated from 18:00 to 18:00 the day after (as an example) instead of from 00:00 to 00:00 the day after. If you want to align the bars, you can just uncomment lines 266 to 268 in bargraph.php. This will move the bars on the x-axis BUT the calculation of the kWh/d will still be wrong (from 18:00 to 18:00).

I don't know how to fix that bug which seems to be related to the ajax request.

Eric

bodiroga's picture

Re: Bar graph - improvements

Hi Eric!

Many thanks for your answer and your help, I really appreciate that you have answered my comment!

Let's see then if Trystan has enough time to fix the ajax problem and we can have correctly aligned bars ;)

Thanks again for your help and best regards,

Aitor

darrepac's picture

Re: Bar graph - improvements

Sounds great! it would permit to have dailly, weekly, monthly consumption in one graph which I never succeed to do...

TrystanLea's picture

Re: Bar graph - improvements

Hello Eric, I've added in your changes above to the bargraph visualisation, these changes are now in the master branch of emoncms:

https://github.com/emoncms/emoncms/commit/0a50c63808e94e60b756641a04d574...
https://github.com/emoncms/emoncms/commit/fdcb0a55551684368e17bda17426a3...

Looking into the AJAX issue next

TrystanLea's picture

Re: Bar graph - improvements

I think the error Im seeing is not an arbitrary time offset but that the daily values when the delta flag is applied are labeled as one day ahead so I see the 4th of October as 20kWh where that is actually the consumption for the 3rd..

The bargraph vis makes use of the browser's timezone setting so that 20kWh is correct for british summer time for me.

Eric_AMANN's picture

Re: Bar graph - improvements

Hi,

The time offset is different for each of my feeds (PHPTimestore) : 22:27:00, 17:58:00, 18:08:00, ...

I read that time values on my emoncms server (modifying the bargraph php file).

That's is also the case on my emoncms.org acount.

Eric

TrystanLea's picture

Re: Bar graph - improvements

Hello Eric, Ah that might explain it, the issue might be PHPTimestore and I've been testing on PHPFina/Fiwa. I will try and look into why that is.

bodiroga's picture

Re: Bar graph - improvements

Hi Trystan!

Any update on this issue? ;)

Many thanks for all your hard work!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.