It is currently March 29th, 2024, 9:21 am

Reset Stats on a daily basis

Get help with creating, editing & fixing problems with skins
Rainetto
Posts: 5
Joined: November 21st, 2020, 8:20 am

Reset Stats on a daily basis

Post by Rainetto »

Hello,

I modified for my personal needs the CircuitousTwo Skins a bit, and also the Network usage.
Please note, that I'm no programmer, nor I'm a Rainmeter expert ... I just experimented a bit.


So, I have the Network Usage currently to reset each month, what is working with this code:

[ResetMonth]
Measure=Time
Format=%d
IfEqualValue=1
IfEqualAction=!RainmeterResetStats


But I really'd like to have it reset on a daily basis!
I tried similar to the above to reset when hour is zero (or any other value), but that means, my computer has to run at this time.

Short question now:
Is there any code which could reset Rainmeter Stats on a daily basis, regardless if the computer is on at a specific time or not?


Would be very happy if someone has a solution!
thx!
Netto
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Reset Stats on a daily basis

Post by FreeRaider »

I don't use that skin, perhaps a code like this one could work

Code: Select all

[ResetMonth]
Measure=Time
Format=%d
IfAboveValue=1
IfAboveAction=!RainmeterResetStats
Have a look at https://docs.rainmeter.net/manual/measures/general-options/ifactions/
Rainetto
Posts: 5
Joined: November 21st, 2020, 8:20 am

Re: Reset Stats on a daily basis

Post by Rainetto »

thx for answering,

but that was exact one of the solutions I tried ...

I do not know what happened exactly as I tried several approaches. But with some I needed to let the computer run at the exact time, and others simply have done nothing.



Will test it again ... maybe I have made sth wrong



EDIT: wait ... you have format %d (day), overseen this. This is what I haven't reid indeed.
I experimented with %H (hours)

Can you explain the logic using %d and the "Above".... why should it reset daily then?
thx!!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reset Stats on a daily basis

Post by balala »

Rainetto wrote: November 21st, 2020, 9:18 am Can you explain the logic using %d and the "Above".... why should it reset daily then?
With FreeRaider's code it resets only once, on day 2 of each month. This is the moment when the condition becomes true. If the skin is loaded continuously, it doesn't reset anymore once again, because this to happens, the condition should become first false, then true again. This doesn't happen during the month.
The simplest solution is to remove the IfAboveValue conditon and replace the IfAboveAction with an OnChangeAction option, which is executed every time the value of the measure changes, so every time day changes. So replace the IfAboveValue=1 and IfAboveAction=!RainmeterResetStats options with OnChangeAction=[!ResetStats].
Note that I also removed the !Rainmeter deprecated bang prefix, which is not needed anymore.
Rainetto
Posts: 5
Joined: November 21st, 2020, 8:20 am

Re: Reset Stats on a daily basis

Post by Rainetto »

Ah Great!

Seems to work now!
Have changed date of PC manually and it has made the reset, what was not possible before!

many thanks!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reset Stats on a daily basis

Post by balala »

Rainetto wrote: November 21st, 2020, 12:53 pm Seems to work now!
Have changed date of PC manually and it has made the reset, what was not possible before!
Great, I'm glad you got it working.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Reset Stats on a daily basis

Post by jsmorley »

Do be aware that this is a bit sensitive to when your skin is running. (when the computer is actually on in other words)

The change will never happen until the day "changes" from one day to the next, while the skin is actually running. So in theory, if you have your computer off, and turn it back on, it can and will be up to 23 hours 59 minutes and 59 seconds before the stats are reset. Depends on what time of day it is when you start the computer.

I think what you would have to do is "write" the full date to a variable in the skin or a .inc include file each time the action "fires" that resets the stats. Then have the skin check that value when loaded or refreshed, and fire the action if the current date is not the same as the saved one. I'd suggest full year/month/day date, as depending on how long the computer is off, you can't strictly depend on any individual component of the date, like year, month, day, or hour.

So while I'm fine with the OnChange approach, to be technically correct I think you need to buttress that with something more.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Reset Stats on a daily basis

Post by jsmorley »

I would think something like this would work more reliably.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
SavedDate=2020-11-21

[MeasureReset]
Measure=Time
Format=%F
DynamicVariables=1
IfMatch=#SavedDate#
IfNotMatchAction=[!ResetStats][!WriteKeyValue Variables SavedDate "[MeasureReset]"][!SetVariable SavedDate "[MeasureReset]"]
The variable SavedDate must exist, but can be set to anything to start with, when you first create the skin. Set it to None or something.

This will reset the stats if the date changes while the skin is running, but will also do it if the date changes while the skin is NOT running.
Rainetto
Posts: 5
Joined: November 21st, 2020, 8:20 am

Re: Reset Stats on a daily basis

Post by Rainetto »

thx morley,


what happens in your code?
There is a start date set and then,if it does not match (when date changes), the stats reset and it will be written a new variable (next day) and if this does not match again, chnages, rewrites and so on?
Do I understand this correct?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Reset Stats on a daily basis

Post by jsmorley »

Rainetto wrote: November 21st, 2020, 2:09 pm thx morley,


what happens in your code?
There is a start date set and then,if it does not match (when date changes), the stats reset and it will be written a new variable (next day) and if this does not match again, chnages, rewrites and so on?
Do I understand this correct?
In my code, what happens is that once a second, today's date is matched against the date set in the variable SavedDate. If they don't match, then the following happens:

1) The stats are reset
2) The current date is physically "written" to the variable SavedDate, which makes it "persistent". It will survive a refresh or reload of the skin
3) The in-memory value of the variable SavedDate is also changed to the current date, which means that if the date again changes while the skin is running, it will react to that.

All of this can only ever happen one time per day, only when the date stored in the variable SavedDate is not the same as today's date. IfNotMatchAction is only fired when the match changes from "true" to "false".

Nothing at all will happen as long as the value of SavedDate and the current date are the same. As soon as they are different, either while the skin is running, or when the skin is loaded or refreshed, it will reset the stats and set the value of SavedDate to "today".

This is a more reliable and in my personal view only reliable way to come at this, unless you just never turn off your computer or refresh or reload the skin. If you use OnChangeAction and do any of those, you are going to wait up to 23 hours for anything to happen.

Einstein tells us that time only moves in one direction. If the current full date is not the same as the date saved in the variable, it's time to reset. There is no point in futzing with any "math" on this.

I would use the same thing if I was wanting to reset the stats once an hour, once a day, once a month or once a year. Just change the Format option in the Time measure to capture the least amount of the year-month-day-hour date required to reliably detect a change. The key is that you want the skin to "remember" when it was last reset, no matter if the skin is running or not.