Skip to content

Refine usage fallback logic with 1-day threshold#57

Open
alv-cor wants to merge 1 commit intoaload0:mainfrom
alv-cor:fix/max-usage-stat-for-a-day
Open

Refine usage fallback logic with 1-day threshold#57
alv-cor wants to merge 1 commit intoaload0:mainfrom
alv-cor:fix/max-usage-stat-for-a-day

Conversation

@alv-cor
Copy link
Contributor

@alv-cor alv-cor commented Mar 8, 2026

Days from past weeks show sometimes a usage higher than 24 hours, what is physically impossible. This PR aims to hide usage for those days where stats are not precise.

Add a Map.totalTime() helper and ONE_DAY_MS constant; use a mutable `usage` variable to prefer event-based usage only when it's non-empty and the summed time is <= one day. If that check fails, fall back to stats-based calculation and return it only if it's <= one day; otherwise return an empty map. Also change exception handling to return an empty map instead of falling back to stats. This avoids returning large/invalid aggregates and makes the fallback behavior more explicit.
@alv-cor
Copy link
Contributor Author

alv-cor commented Mar 9, 2026

Note that this is only a dirty patch. I think this happens because stats are calculated each time the menu is accessed, and since the calculation is based on past events/intents, it is possible that logs from +1 week are deleted arbitrarily by the phone.

A feasible solution could be saving statistics from past days in some way, so error prone calculation is avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant