Mini-graph-card: Graph shows Incorrect values (caching)

Created on 28 Oct 2019  路  16Comments  路  Source: kalkih/mini-graph-card

Something is not right. When I hover last bar the value shown is not correct. I was thinking that maybe cached values messed up when I was switching between branches so I deleted DB. But it didn't help (it reduces the difference slightly but it progresses over time)

ezgif com-video-to-gif (2)

bug

All 16 comments

Are you sure you're using an aggregate function in that graph? If it's set to default (average) it could be correct as it's shown.

I don't appear to see this behaviour in my graphs.
This is an illumination sensor with aggregate function set to max and it's now 01:30 am.

Kapture 2019-10-28 at 1 30 19

I need to use aggregate:max as the value comes from energy_daily sensor so I want to get max value from particular day. Anyway I have switched to avg and the issue is still there (and of course values everywhere are not what I was expecting)

Yes, I understand you want to use the aggregate function max in the graph, what I meant to ask was if you'd actually set it.

Sorry misread. Yes it is set to max.

Actually I have noticed that most of the bars on hover show incorrect value - will try to find out what is going on.

+1, i noticed the same issue. It seems that issue can be temporarily solved cleaning browser cache, but after some hour issue appears again. It seems even that changing "hours_to_show" to a lower value (example from 240 hours to 168) temporarily solve the issue, but i don't know if is due to the recalculation or to the lower number of hours..
Here is an example
20191104_232042

I have some question about this issue:

  1. what do you think about it?
  2. why it is not labeled as a bug?
  3. this type of graph shows incorrect values not only on the last point, but in all the days of the week. The only way to make it working is to change something in the card setting, in a way that force a recalculation. This temporarily solve, but then next values becomes wrong again.
  1. If it doesn't correct itself with a normal page refresh but requires emptying of cache or changing hours_to_show it's most likely related to the caching of history data.
  2. No real reason, I guess I forgot

Could possibly be these lines:
https://github.com/kalkih/mini-graph-card/blob/2156633f1f3f4d456899e4feabc725af805eb8bc/src/main.js#L797-L799

With the recent changes to how calculate the end date we should probably base the start date on the end date, instead of now.

    const end = this.getEndDate();
    const start = end;
    start.setHours(start.getHours() - config.hours_to_show);

Quoted from @tomlut #205

Incorrect data shown in bar graph:

aggregate_func: max
color_thresholds:
  - color: '#039BE5'
    value: 0
  - color: '#0da035'
    value: 5
  - color: '#e0b400'
    value: 7.5
  - color: '#e45e65'
    value: 10
entities:
  - entity: sensor.total_cost_today
group_by: date
hours_to_show: 168
name: Energy Cost Per Day
show:
  graph: bar
  labels: true
type: 'custom:mini-graph-card'

Screenshot_2019-11-12 Home Assistant(1)

Seems to be some sort of caching issue as a when opened in private browsing mode the graph displays correctly:
Screenshot_2019-11-12 Home Assistant

Actual last seven days data (newest to oldest):

4.64
5.29
6.08
5.81
6.49
5.95
5.17

Interestingly a line graph shows the same incorrect values:

color_thresholds:
  - color: '#039BE5'
    value: 0
  - color: '#0da035'
    value: 5
  - color: '#e0b400'
    value: 7.5
  - color: '#e45e65'
    value: 10
color_thresholds_transition: hard
entities:
  - sensor.total_cost_today
group: false
hour24: true
hours_to_show: 168
line_width: 4
name: Daily energy cost
points_per_hour: 1
show:
  extrema: true
  fill: fade
  icon: true
  labels: false
  name: true
  state: true
type: 'custom:mini-graph-card'

Screenshot_2019-11-12 Home Assistant(3)

Compare to built in graph:
Screenshot_2019-11-12 Home Assistant(2)

Or the mini graph opened in a private browsing window (values are slightly off due to number of points per hour, but not as bad as above):
Screenshot_2019-11-12 Home Assistant(4)

I found the same issue and the same workaround. Visualizing a time in state aggregated by day causes the bar graph to show random data. Changing the value of hours_to_show temporarily will cause a reload and fix it, but it returns as quickly.

Please try the latest beta release v0.9.0-beta, should hopefully resolve these issues.
You might want to force clear the cache (change hours_to_show, refresh the page and change it back) after getting the beta release, or just wait it out as future data should cache correctly.

I installed the beta and upgraded home assistant soon after (0.102.3) then did a Ctrl+Shift+R to reload but see no improvement:
Screenshot_2019-12-01 Home Assistant

Ctrl+Shift+R won't clear stored history data unfortunately, I'm not sure what you're trying to show with your screenshot but it looks like it's more related to #194 #200, where the graphs are "out of sync"? Or is there missing/invalid data as well?

Yeah sorry I got updates for both issues and replied to the wrong one.

Yes the misalignment over time issue. I'll comment in the other issue.

I have just reinstated my weekly energy use bar graph and will test this one too.

As for this issue it does not appear to have been rectified either. Issue visible after only one day:

Untitled

Clearing browser history and restarting produces:

Screenshot_2019-12-03 Home Assistant

can confirm bug. deleting indexedDB in devtools temporary fixes issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simonwood0609 picture simonwood0609  路  7Comments

gerard33 picture gerard33  路  6Comments

gerard33 picture gerard33  路  3Comments

balloob picture balloob  路  4Comments

WhistleMaster picture WhistleMaster  路  3Comments