Community
OpenEnergyMonitor

Community

Enhancements to the graph module


(Frogmore42) #1

I have heard if I say IoTaWatt some of you will stop listening. I really hope that isn’t true. I bought my first IoTaWatt from your store and still use the emoncms service and generally find it useful.

One thing that really bugged me when I first started using emoncms, which was years ago, was that following the example of creating a feed I was unable to see my data and it looked like it wasn’t working. Now I figured it out pretty quickly, but the graph defaults to showing 7 day’s worth of data. So there is no way the typically small amount of data will show up. Over the years I figured out how to zoom, but never liked the experience.

In the last year I have been using Grafana and really like its experience for selecting time periods. There was some discussion in the IoTaWatt forum about allowing more time selections. This was something I had always wanted. So, I said how hard could it be :wink:?

I first added more buttons, which was pretty easy. But got feedback that a drop-down might be better. So I researched that and sure enough it does look better.

I just took a look at the code for emoncms and while it has moved on, it looks like the basic technique will work with the current code. Is this something you would be interested in?

If so, I can create a PR for it.


(Anthony Vassallo) #2

@Frogmore42 - just to be sure, you know that once you setup a graph for showing eg 1 day, and save it (i.e. name it) it will always load the last 24 hours when you select it again from the mygraphs dropdown. It took me a while to realise this!


(Frogmore42) #3

If your point about is that loading a saved graph will cause the graph to be updated to the saved time window, yes I knew that. But you are also correct that the code as it is does not invalidate (or correctly set) the time window selector. I will fix that.


(Greebo) #4

The best way to initiate discussion about a new feature or feature update that you’re prepared to add/make is to get a PR into Github, then add a link to it to your thread here and tag people like Trystan and Glyn…


(Trystan Lea) #5

@Frogmore42 sounds like a nice feature, happy to accept a pull request


(Frogmore42) #6

Great, I’ll see if I can get something to show this weekend.


(Frogmore42) #7

Okay, I got my RPi3B+ running the SD Card image 9.9.5 and I have ssh enabled (with a non-default password) so I can use SCP to copy the files I need over to it. I cloned the graph repo and copied it over to my instance and this is what I get:
image

I got this after I made my changes, so I reverted all of my changes and went back to what is published on GitHub and get the same error.

This is the function that is erroring:

function addFeedlistData(response){
// loop through feedlist and add response data to data property
var valid = false;
for (i in feedlist) {
let feed = feedlist[i];
for (j in response) {
let item = response[j];
if (parseInt(feed.id) === parseInt(item.feedid)) {
feed.data = item.data;
}
if (typeof item.data.success === ‘undefined’) {
valid = true;
}
}
}
// alter feedlist base on user selection
if (valid) set_feedlist();
}

The line that is failing is this one:

if (typeof item.data.success === ‘undefined’) {

My guess is that either item or item.data is undefined and so this is erroring. My guess is also that the code’s expectation is that should never happen. Git says this code was added 12 days ago so I am also guessing that it is dependent on one or more of the many other changes that are in the master branches of the various components. So, any idea what else I need to update to get this to work?


(Frogmore42) #8

answering my own question, it looks like the feed controller API has changed and/or the graph module is using it differently.

The code in the repo is using data.json?ids=1,2,3 in the query string to get all the data at once.
The code in the stable image is using data.json?id=1 and gets a single channel at a time, but I am guessing this means I need to update the feed engine. It is not clear how much else I need to update and what else will be incompatible.


(Paul) #9

hopefully you spotted the pointers in the other thread Problems with graphs module in local emoncms you will need to checkout master on both the emoncms and graph repos to have the latest graph module code running until this is merged into the stable branches.