-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Augment history panel with Long Term Statistics #18213
Augment history panel with Long Term Statistics #18213
Conversation
Imho this is a brilliant idea - "augmented" history. Proposals:
|
Now I don't know that much about statistics either but I think you're misunderstanding. All statistics are recorded every 5 minutes, regardless of what time period they get reset at. However, this PR displays the hourly mean. |
Add a new Statistics graph card, choose a period (5minute, hour, ...) and see a difference. |
Yeah I agree there's not really a need to toggle them on/off independently, it's just like that because:
And yes it is fixed to hourly aggregated stats. |
My only comment is that it should be smoothed like it is in the more info panel if possible |
Imho a slightly different coloring which you offered is rather sufficient. But may be there are some other ideas; would be great to see them. (I also agree that 2 different graphs for LTS & history could be simpler to implement as you said).
Could you elaborate? As for more-info. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I think this is a great idea! In the long run we still need to completely overhaul out history and statistics panel, but for now this a great addition. I would also not show 2 labels in the legend, and have the statistics graph follow the visibility of the history graph (probably needs some changes to |
Just curious, is there a vision for what this should look like? I'm not opposed to delivering this current PR, but it does feel a bit of a kludge, so if there's a better long term solution in mind, maybe it's better to invest the time just doing that instead. |
No, there is no design or vision yet, but that is something that is on the list to work on... |
I think I'll keep it to one label per entity, and keep the same colors/styling for stats vs history, but I'll include the data attribution in the tooltip. I think that's fairly unobtrusive, while still conveying the desired information. (The extra source detail will only be shown when LTS are included in the graph) |
Imho a slightly different color (as you did in the 1st version) is better. |
I think I'm happy for now with the current code, it's probably ready for a closer review. Some more testing would be helpful as well. |
We could add Line 5 in d8d16c4
https://www.home-assistant.io/integrations/recorder#purge_keep_days |
Is it worth to consider the case that some user may not have the same keep days for every entity? If for example there is any manual purges happening of select entities, starting the statistics after keep_days would leave a hole in the graph. I don't know if that case is worth designing for or not. If overfetching too much data is a concern, could also consider serializing the fetches instead of doing them in parallel. |
I'm not sure we should try to accommodate manual purges as it will make performance worse for the most common cases to service a few rare cases.
|
This works great. The backend still hits the database for times were we know we have no history since history never ran before the end date of the query. We can probably optimize that away on the backend |
I've made the backend short circuit impossible history queries home-assistant/core#104724 |
Did performance testing with 1 year of stats and everything is solid. I don't see any places we can make it faster as its almost all sqlalchemy or database overhead (and I've already helped optimize sqlalchemy as much as I think it can be for now) |
@@ -265,6 +338,7 @@ class HaPanelHistory extends SubscribeMixin(LitElement) { | |||
changedProps.has("_areaDeviceLookup")))) | |||
) { | |||
this._getHistory(); | |||
this._getStats(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming we call this as part of refreshing data, shouldn't we also have this be called when a user clicks the refresh button?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember if I considered this in the initial pass, but wouldn't refreshing statistics just return the same data a second time? The statistics is not really live updating like the history is, so there's never any "new" data to get. So would we really want to bother querying and fetching it all again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the one case where it's useful is the edge case where a user has the dashboard open permanently, on a period that relies on both statistics and states and hits refresh once a day without ever refreshing the page. So yeah, probably not a big deal.
Proposed change
Was thinking over some ideas for how to better view long term statistics, and I was thinking one possibility is to use them to fill out the history panel for time ranges that are not present in the recorder, so you could easily look at the history of a sensor in the history panel much longer than the typical recorder purge window.
Basically I'm grabbing both the history and statistics data for an entity in history panel, and then merging them together into a single plot, where we use the history data in the near history, and the hourly statistics from the long term history.
This probably isn't fully finished and I'm sure still has some bugs and rough edges to clean up, but just thought I'd solicit for some feedback and see if this is a style and direction that we'd like to go in before spending too much more time on it.
Check out the screengrab and let me know what you think,
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: