home-assistant / frontend

:lollipop: Frontend for Home Assistant
https://demo.home-assistant.io
Other
3.97k stars 2.71k forks source link

Weekly period in statistics-graph card breaks at year change #15635

Closed osmaa closed 1 year ago

osmaa commented 1 year ago

Checklist

Describe the issue you are experiencing

The statistics-graph card, when configured to chart with weekly period, will overlay two data points on the same week at New Year, as demonstrated by the screenshot. This is typically caused by using the calendar year (date.getYear()) in combination of week numbers. date.getWeekYear() is the correct method when combining with week numbering.

image

Config of the chart (I don't yet have 370 days of data, which explains the discrepancy in the graph span)

chart_type: line
period: week
days_to_show: 370
type: statistics-graph
entities:
  - entity: sensor.aranet4_09957_carbon_dioxide
    name: Olkkari
stat_types:
  - mean
  - min
  - max
title: CO2

Describe the behavior you expected

The year 2022, when grouped over ISO weeks, ended on Sunday Jan 1st 2023 (last day of week 52/2022). The year 2023 accordingly started on Monday Jan 2nd (first day of week 1/2023). The charts should not have overlapping graphs on those two weeks.

The error will not reproduce in a year's time, because it happens that ISO week 52 will end on Sunday Dec 31st. It will reproduce again in 2025, as there will be two days of 2024 (Monday and Tuesday) in the first week of 2025.

Steps to reproduce the issue

  1. chart any long term statistic that has history past the New Year with a weekly period.

What version of Home Assistant Core has the issue?

core-2023.2.5

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

Safari, Chrome and the app

Which operating system are you using to run this browser?

No response

State of relevant entities

No response

Problem-relevant frontend configuration

No response

Javascript errors shown in your browser console/inspector

No response

Additional information

No response

karwosts commented 1 year ago

Personally I don't see this in 2023.3. Does it happen for every one of your entities? Does it still happen now? Maybe something related to your locale settings, like first day of the week?

image

chart_type: line
period: week
days_to_show: 120
type: statistics-graph
entities:
  - sensor.thermostat_air_temperature
stat_types:
  - mean
  - min
  - max
osmaa commented 1 year ago

This no longer reproduces in 2023.3. I haven't changed any locale-related configuration in the meantime.