It is currently April 27th, 2024, 9:23 am

Trying to set a static time variable

Get help with creating, editing & fixing problems with skins
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Trying to set a static time variable

Post by CodeCode »

Hello,

I have a sleep log. It starts once a mouse click = then the end on a different mouse click area. The rest is basic math for totaal for a day and the average when 3 days have transpired (averaging less than 3 is kind of donk).

I have been trying set a start time and end time to a variable then writekeyvalue to the inc file.

The problem is after a refresh - to simulate the skin being loaded or unloaded - the time just sets itself to the current time again, ruining the intended variable state.

Code: Select all

[StaticDay0]
Meter=String
StringAlign=RightCenter
X=154
Y=106
AntiAlias=1
FontFace=#TallFont#
FontSize=27
FontColor=#ShortBars#
StringCase=Upper
LeftMouseUpAction=[!ToggleMeterGroup MON][!SetVariable MON "1"][!WriteKeyValue Variables MON "[#MON]" "#@#Utopia.inc"][!Update]
DynamicVariables=1
Text=MON
Hidden=#awake#

--------------------------------------- MONDAY START --------------------------

[MeasureTimeHour0]
Measure=Time
Format=%H
Paused=#sZeroPause#
DynamicVariables=1

[MeasureTimeMinute0]
Measure=Time
Format=%M
Paused=#sZeroPause#
DynamicVariables=1

[MeasureTimeSeconds0]
Measure=Time
Format=%S
Paused=#sZeroPause#
DynamicVariables=1

[Time0]
Meter=String
MeasureName=MeasureTimeHour0
MeasureName2=MeasureTimeMinute0
MeasureName3=MeasureTimeSeconds0
StringAlign=LeftCenter
X=164
Y=106
AntiAlias=1
FontFace=#TallFont#
FontSize=27
FontColor=#sZeroColor#
StringEffect=Border
FontEffectColor=0,0,0,255
StringCase=Upper
Text=%1:%2:%3
Group=mon
DynamicVariables=1
Hidden=1

[MeasureStart0]
Measure=Calc
IfCondition=(#sZero# = 1)
IfTrueAction=[!SetVariable sZeroColor #StartColor#][!WriteKeyValue Variables sZeroColor "[#sZeroColor]" "#@#Utopia.inc"][!Update]
IfFalseAction=[!SetVariable sZeroColor #CustomOpaque#][!WriteKeyValue Variables sZeroColor "[#sZeroColor]" "#@#Utopia.inc"][!Update]
DynamicVariables=1

[MeterClick0]
Meter=Image
SolidColor=0,0,0,1
X=164
Y=83
W=65
H=40
LeftMouseUpAction=[!SetVariable sZeroPause "((#sZeroPause#+1)%2)"][!WriteKeyValue Variables sZeroPause "[#sZeroPause]" "#@#Utopia.inc"][!SetVariable sZero "((#sZero#+1)%2)"][!WriteKeyValue Variables sZero "[#sZero]" "#@#Utopia.inc"][!Update]
Group=mon
DynamicVariables=1
Hidden=1

-------------------------------------- FINISH MONDAY --------------------------

[MeasureTimeHourF0]
Measure=Time
Format=%H
Paused=#fZeroPause#
DynamicVariables=1

[MeasureTimeMinuteF0]
Measure=Time
Format=%M
Paused=#fZeroPause#
DynamicVariables=1

[MeasureTimeSecondsF0]
Measure=Time
Format=%S
Paused=#fZeroPause#
DynamicVariables=1

[Time0f]
Meter=String
MeasureName=MeasureTimeHourF0
MeasureName2=MeasureTimeMinuteF0
MeasureName3=MeasureTimeSecondsF0
StringAlign=LeftCenter
X=274
Y=106
AntiAlias=1
FontFace=#TallFont#
FontSize=27
FontColor=#fZeroColor#
StringEffect=Border
FontEffectColor=0,0,0,255
StringCase=Upper
Text=%1:%2:%3
Group=mon
DynamicVariables=1
Hidden=1

[MeterClickw]
Meter=Image
SolidColor=0,0,0,1
X=275
Y=82
W=65
H=40
LeftMouseUpAction=[!SetVariable fZeroPause "((#fZeroPause#+1)%2)"][!WriteKeyValue Variables fZeroPause "[#fZeroPause]" "#@#Utopia.inc"][!SetVariable fZero "((#fZero#+1)%2)"][!WriteKeyValue Variables fZero "[#fZero]" "#@#Utopia.inc"][!Update]
Group=mon
DynamicVariables=1
Hidden=1

[MeasureFinishColorf1]
Measure=Calc
IfCondition=(#sZeroPause# = 0) && (#fZeroPause# = 1)
IfTrueAction=[!SetVariable fZeroColor #CustomOpaque#][!WriteKeyValue Variables fZeroColor "[#fZeroColor]" "#@#Utopia.inc"][!SetVariable fZero "0"][!WriteKeyValue Variables fZero "[#fZero]" "#@#Utopia.inc"][!SetVariable fZeroPause "0"][!WriteKeyValue Variables fZeroPause "[#fZeroPause]" "#@#Utopia.inc"][!Update]
IfCondition2=(#sZeroPause# = 1) && (#fZeroPause# = 1)
IfTrueAction2=[!SetVariable fZeroColor #FinishColor#][!WriteKeyValue Variables fZeroColor "[#fZeroColor]" "#@#Utopia.inc"][!SetVariable fZero "1"][!WriteKeyValue Variables fZero "[#fZero]" "#@#Utopia.inc"][!SetVariable fZeroPause "1"][!WriteKeyValue Variables fZeroPause "[#fZeroPause]" "#@#Utopia.inc"][!Update]
IfFalseAction2=[!SetVariable fZeroColor #CustomOpaque#][!WriteKeyValue Variables fZeroColor "[#fZeroColor]" "#@#Utopia.inc"][!Update]
DynamicVariables=1

Code: Select all

[Variables]
Mon=0
sZeroPause=0
fZeroPause=0
etc..
I hope this shows enough to adapt any advice into this (and 6 other similar sections for each day of the week that will essentially be the same as the above, barring meter and measure names).

Thanks,
CC
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Trying to set a static time variable

Post by eclectic-tech »

Not sure what you are trying to do exactly, but you will never be able to calculate the average of days using only hours, minutes, and seconds of time measures. They all reset to zero at midnight!

To measure differences in time you need to use timestamp values of Time measures. They are the easiest way to save and measure time differences for any length of times.

Timestamps represents a precise moment in time. Timestamp values will simplify setting a start time and comparing that time, using simple addition/subtraction of the timestamp values, to any date's timestamp in the past or future. From the timestamp value you can retrieve the year, month, date, hour, minute, and second of that precise time.

The following measure will return the current time as a timestamp for the NUMBER value and a format of HH:MM:SS for the STRING value.

Code: Select all

[MeasureTime]
Measure=Time
Create a start time by setting a variable to the current time measure's timestamp value:
!LeftMouseUpAction=[!WriteKeyValue Variables StartTime "[MeasureTime:Timestamp]"][!SetVariable StartTime "[MeasureTime:Timestamp]"]

Create another time measure to calculate the time elapsed since the StartTime variable was set:

Code: Select all

[MeasureTimeElapsed]
Measure=Time
Timestamp=([MeasureTime:Timestamp]-#StartTime#)
DynamicVariables=1
JSMorley posted tips on using Timestamps that you definitely should read through.

Here's an example skin that will set a StartTime variable and calculate the elapsed time even when refreshed or unloaded and reloaded.

Code: Select all

; ========= Variables ==========
[Variables]
StartTime=13349557110


; ========= Skin Settings ==========
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
Group=#RootConfig#

; ========= Measures ==========
[MeasureTime]
Measure=Time

[MeasureTimeStart]
Measure=Time
Timestamp=#StartTime#
DynamicVariables=1

[MeasureTimeElapsed]
Measure=Time
Timestamp=([MeasureTime:Timestamp]-#StartTime#)
DynamicVariables=1

; ========= Meters ==========
[MeterStart]
Meter=String
SolidColor=0,200,0,100
Text=Click to Set/Reset StartTime
FontWeight=700
LeftMouseUpAction=[!WriteKeyValue Variables StartTime [MeasureTime:TimeStamp]][!SetVariable StartTime [MeasureTime:TimeStamp]]

[MeterCurrentTime]
Meter=String
MeasureName=MeasureTime
SolidColor=0,0,0,1
X=r
Y=R
Text=Current Time: %1

[MeterStartTime]
Meter=String
MeasureName=MeasureTimeStart
SolidColor=0,0,0,1
X=r
Y=R
Text=Start Up Time: %1

[MeterElapsed]
Meter=String
MeasureName=MeasureTimeElapsed
SolidColor=0,0,0,1
X=r
Y=R
Text=Elapsed Time: %1
elapsedtime1.png
Hope this gives you some ideas for your project. Feel free to ask if you have any questions.
You do not have the required permissions to view the files attached to this post.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Trying to set a static time variable

Post by CodeCode »

eclectic-tech wrote: January 12th, 2024, 11:26 pm Not sure what you are trying to do exactly, but you will never be able to calculate the average of days using only hours, minutes, and seconds of time measures. They all reset to zero at midnight!

To measure differences in time you need to use timestamp values of Time measures. They are the easiest way to save and measure time differences for any length of times.

Timestamps represents a precise moment in time. Timestamp values will simplify setting a start time and comparing that time, using simple addition/subtraction of the timestamp values, to any date's timestamp in the past or future. From the timestamp value you can retrieve the year, month, date, hour, minute, and second of that precise time.

The following measure will return the current time as a timestamp for the NUMBER value and a format of HH:MM:SS for the STRING value.

Code: Select all

[MeasureTime]
Measure=Time
Create a start time by setting a variable to the current time measure's timestamp value:
!LeftMouseUpAction=[!WriteKeyValue Variables StartTime "[MeasureTime:Timestamp]"][!SetVariable StartTime "[MeasureTime:Timestamp]"]

Create another time measure to calculate the time elapsed since the StartTime variable was set:

Code: Select all

[MeasureTimeElapsed]
Measure=Time
Timestamp=([MeasureTime:Timestamp]-#StartTime#)
DynamicVariables=1
JSMorley posted tips on using Timestamps that you definitely should read through.

Here's an example skin that will set a StartTime variable and calculate the elapsed time even when refreshed or unloaded and reloaded.

Code: Select all

; ========= Variables ==========
[Variables]
StartTime=13349557110


; ========= Skin Settings ==========
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
Group=#RootConfig#

; ========= Measures ==========
[MeasureTime]
Measure=Time

[MeasureTimeStart]
Measure=Time
Timestamp=#StartTime#
DynamicVariables=1

[MeasureTimeElapsed]
Measure=Time
Timestamp=([MeasureTime:Timestamp]-#StartTime#)
DynamicVariables=1

; ========= Meters ==========
[MeterStart]
Meter=String
SolidColor=0,200,0,100
Text=Click to Set/Reset StartTime
FontWeight=700
LeftMouseUpAction=[!WriteKeyValue Variables StartTime [MeasureTime:TimeStamp]][!SetVariable StartTime [MeasureTime:TimeStamp]]

[MeterCurrentTime]
Meter=String
MeasureName=MeasureTime
SolidColor=0,0,0,1
X=r
Y=R
Text=Current Time: %1

[MeterStartTime]
Meter=String
MeasureName=MeasureTimeStart
SolidColor=0,0,0,1
X=r
Y=R
Text=Start Up Time: %1

[MeterElapsed]
Meter=String
MeasureName=MeasureTimeElapsed
SolidColor=0,0,0,1
X=r
Y=R
Text=Elapsed Time: %1
elapsedtime1.png

Hope this gives you some ideas for your project. Feel free to ask if you have any questions.
I just read through this, Looks great. I am a night owl and only once did I see (and forgot) that the values reset to zero, at midnight.

I'll go through this tonight (Aus time). I also was trying timestamps, but it seems I was using them incorrectly.

Thanks eclectic-tech!
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Trying to set a static time variable

Post by CodeCode »

Heya,
I went through your example eclectic-tech - implemented it - adjusted for functionality e.g. where timeelapsed displays.

Still hashing it through and scrubbin typos and misplaced measurenames. The times start and stop correctly. TimeElapsed shows correctly.

So the hashing over is to try to find out why a refresh resets all times, start, finish, elapsed. I am close to positive that I used all of the variables, and writekeyvalues - which seem to be the key to preserving the variables persistently.
Ok new post for this.

I think this is the problem:

Code: Select all

[MeasureTimeElapsedF0]
Measure=Time
Timestamp=([MeasureTimeF0:Timestamp]-#StartTime0#)
DynamicVariables=1
The TimeStamp is being reset on refresh and is set to the current time.
Just updating progress.

Cheers
CC

EDIT: Everything works perfectly using your examples - this is still progress happening - shortened and less confusing code. :thumbup:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Trying to set a static time variable

Post by eclectic-tech »

Happy to help, looks like you are making progress! :thumbup:

Using Time and Uptime measures, and using and setting Timestamp values takes a bit of practice but in the end it is the only reliable method to calculate time.

I try to learn something new each day! :D
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Trying to set a static time variable

Post by CodeCode »

Hello,

I seem to have a bit of a messed up thing going.

A lot isnt working correctly.

However, I will get back to working correctly without refresh messing things.

Right now the refresh simply sets all - start - stop - result, times to the immediate current time.

Also the result measures are not working any more - not correctly. result1 starts from a 00:00:00 once the start time has been set - that is good.
But the rest of the results meters of consecutive days of the week start from the current time rather 00:00:00.

The goal of this thread was to set and save a static number for all output meters, to that set without using the reset button - to be persistent after a refresh.

I have lost a lot of progress, but understand that timestamps would be better than using individual H:M:S meters. But without those I have not yet worked out how to get those outputs correctly.
:x
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Trying to set a static time variable

Post by CodeCode »

Hello, Updating after my last post.

All of the counters are working correctly - with some caveats.

The clock for start and stop are still not keeping their original start and stop are not preserved in the timestamp, yet. If the skin is refreshed with the values on display, the start and stop are switching to the current time. Upside, the total remains.

Having trouble, adding the totals, for a weekly total - so that is not working at all at the moment.

And, without those totals the skin cannot average the 7 days of sleep time.

The number of days works, bit it does not need or use a timestamp.

If there is a simple way, or not impossible way to get the total of the remainders (total sleep for the day/s) with timestamps, I'd appreciate any advice.

Once that is sorted the rest should be fairly reasonable to finish tweaking those start and stop times to remain until the reset is switched on.


Cheers
CC
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Trying to set a static time variable

Post by CodeCode »

for example, I am currently trying this to get the totals:

Code: Select all

--------------------------------------------- Total Result --------------------

[MeasureTotal]
Measure=Calc
Formula=(([MeasureElapsedF0]+[MeasureElapsedF1]+[MeasureElapsedF2]+[MeasureElapsedF3]+[MeasureElapsedF4]+[MeasureElapsedF5]+[MeasureElapsedF6])%86400)
MaxValue=86400
Substitute="0":"00:00:00"
DynamicVariables=1
When I try to pass the [MeasureTotal} to the output, it does not work. I also tried to ad all of the parts of each total for example;
(#FinishTime0# - #StartTime0#)+(#FinishTime1# - #StartTime1#)+etc. Yields no result either. These are the same seconds values that show corrctly in each day's total. So, I'm confused. Also confusing is the formula logs a logical expression error. Not sure why.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Trying to set a static time variable

Post by CodeCode »

Well, I'm banging away, and making some progress.
This:

Code: Select all

[MeasureTotal]
Measure=Uptime
SecondsValue=([MeasureElapsedF0:TimeStamp]+[MeasureElapsedF1:TimeStamp]+[MeasureElapsedF2:TimeStamp]+[MeasureElapsedF3:TimeStamp]+[MeasureElapsedF4:TimeStamp]+[MeasureElapsedF5:TimeStamp]+[MeasureElapsedF6:TimeStamp])
Format="%3!02i!:%2!02i!:%1!02i!"
DynamicVariables=1
Gets the correct total, but somehow before clicking the finish time, a huge number is there (or not preformatted - not sure how to do that).

So after each finish time is clicked - the total ads up correctly.

So now the thing I am hoping to solve is that, somehow prevent that huge output that shows before clicking the finish time button.

:uhuh:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Trying to set a static time variable

Post by CodeCode »

I did up a gifcam of my sleep diary looks at the moment:
Sleep Diary.gif
Almost there :thumbup:
You do not have the required permissions to view the files attached to this post.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.