Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph shows Incorrect values (caching) #193

Closed
maxwroc opened this issue Oct 28, 2019 · 17 comments · Fixed by #213
Closed

Graph shows Incorrect values (caching) #193

maxwroc opened this issue Oct 28, 2019 · 17 comments · Fixed by #213
Labels
bug Something isn't working

Comments

@maxwroc
Copy link
Contributor

maxwroc commented Oct 28, 2019

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)

@kalkih
Copy link
Owner

kalkih commented Oct 28, 2019

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

@maxwroc
Copy link
Contributor Author

maxwroc commented Oct 28, 2019

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)

@kalkih
Copy link
Owner

kalkih commented Oct 28, 2019

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.

@maxwroc
Copy link
Contributor Author

maxwroc commented Oct 29, 2019

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.

@gio-dot
Copy link

gio-dot commented Nov 4, 2019

+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

@gio-dot
Copy link

gio-dot commented Nov 6, 2019

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.

@kalkih
Copy link
Owner

kalkih commented Nov 6, 2019

  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

@kalkih kalkih added the bug Something isn't working label Nov 6, 2019
@kalkih
Copy link
Owner

kalkih commented Nov 6, 2019

Could possibly be these lines:

mini-graph-card/src/main.js

Lines 797 to 799 in 2156633

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

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);

@kalkih kalkih changed the title [dev branch] Bar graph shows incorrect value when hovering last point Graph shows Incorrect values (caching) Nov 12, 2019
@kalkih
Copy link
Owner

kalkih commented Nov 12, 2019

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)

@jannylund
Copy link

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.

@kalkih
Copy link
Owner

kalkih commented Dec 1, 2019

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.

@tomlut
Copy link

tomlut commented Dec 1, 2019

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

@kalkih
Copy link
Owner

kalkih commented Dec 1, 2019

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?

@tomlut
Copy link

tomlut commented Dec 1, 2019

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.

@tomlut
Copy link

tomlut commented Dec 3, 2019

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

@CyanoFresh
Copy link

can confirm bug. deleting indexedDB in devtools temporary fixes issue

@domborovicova
Copy link

Can confirm the bug.

Browsers:

  • Chrome (Cleared Cache, Private)
  • Brave

Type of sensor:
utility_meter: main_daily_energy: source: sensor.home_energy_meter_gen_5_electric_consumed_kwh cycle: daily

I cleared cache on Chrome, Brave, FF and got the same results - graph shows wrong values:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants