slgobinath / SafeEyes

Protect your eyes from eye strain using this simple and beautiful, yet extensible break reminder
http://slgobinath.github.io/SafeEyes/
GNU General Public License v3.0
1.46k stars 164 forks source link

Reset statistics at a fixed time #384

Closed AdamPS closed 3 years ago

AdamPS commented 3 years ago

The health statistics plug-in resets by default every 24 hours. However the reset appears to happen at an arbitrary time unrelated to actual days - probably based on the time the program was started or something like that.

I would prefer to know how many hours I had used my computer on an actual calendar day. Please could we have an extra option something like "reset statistics at midnight". If hours is a multiple of 24 then it always resets at midnight. If hours divides exactly into 24 then the breaks are spaced starting from midnight, e.g. 0400, 0800, 1200, etc. In other cases the option probably makes no sense and could be disabled.

AdamPS commented 3 years ago

I will donate €30 for this.

AdamPS commented 3 years ago

Maybe better to let the user pick the time. So there could be a box "reset time" which is optional.

slgobinath commented 3 years ago

@AdamPS I have implemented this feature using cron expression.

I would appreciate it if you can test the https://github.com/slgobinath/SafeEyes/tree/feature-reset-health-stats-cron-expr branch and let me know if that meets your requirements.

Before running from source, please install the new dependency:

pip3 install croniter

Expected Behavior: The default cron expression to reset the time is midnight 0 0 * * *. The expected behavior is if you are running Safe Eyes passing midnight (say you started working by 10.00 PM and now it is 12.00 Midnight), Safe Eyes will reset your stats. Suppose you started working by 8.00 AM and shutdown the computer by 6.00 PM, your status will be reset when you start the computer next time.

You can use https://crontab.guru to generate your desired cron expression

Thanks

AdamPS commented 3 years ago

Great many thanks I am testing it now. The link you gave for generating/understanding cron expressions seems essential so I would suggest to link to it from the settings dialog - the words "cron expression" could be the link.

Presumably once you have built a proper release then people would not need to run pip3 for themselves??

slgobinath commented 3 years ago

The link you gave for generating/understanding cron expressions seems essential so I would suggest to link to it from the settings dialog - the words "cron expression" could be the link.

That's a great idea. I don't have the mechanism to include hyperlinks in the message. I will include it.

Presumably once you have built a proper release then people would not need to run pip3 for themselves??

Yup you are right. Once Safe Eyes is released, croniter will be installed along with other dependencies automatically

AdamPS commented 3 years ago

Unfortunately it's not giving the right results for me. Now it is 13:56 and I have 13h56 screen time. I think the reset might have worked, but then it counts all the time that my PC is suspended as screen time.

AdamPS commented 3 years ago

Ah it looks like there is already an issue #328 it would be great to fix that please because otherwise the statistics don't really work.

slgobinath commented 3 years ago

I see! In my testing, I never suspended the machine. I will test it and fix the issue. Thanks

AdamPS commented 3 years ago

I think you can commit this one - as far as I can tell this code works and the other problem is separate. Thanks!

slgobinath commented 3 years ago

Sure I am thinking to do so. I've already started working on a prototype to detect suspend but it takes more time. I will merge this and work on #328 next.

slgobinath commented 3 years ago

Closing this issue as it has been released in 2.1.0 Merry Christmas!

AdamPS commented 3 years ago

Great many thanks