It is currently April 27th, 2024, 4:49 pm

Using Uptime with IfActions

Get help with creating, editing & fixing problems with skins
Harley Gorillason
Posts: 4
Joined: July 10th, 2012, 2:56 am

Using Uptime with IfActions

Post by Harley Gorillason »

I'm working on a skin that has a system uptime display. It's currently displaying the uptime in the following format which is working fine.
Uptime: 2 Days, 11 Hours, 36 Minutes
However while playing around I started thinking about the fact that all the words (Days, Hours, Minutes) are in the plural format. This means that if one of the values is 1 then it would look weird. e.g.
Uptime: 1 Days, 1 Hours, 1 Minutes
So I decided to take a look at how IfActions work to see if I could change the output format based on the value of each of the parts. So if the system has been up for 1 minute it will display as Minute instead of Minutes.

However I ran into a bit of a snag while playing around with using UpTime and IfActions.
I'm not sure if it's because of how UpTime returns each of the values, or if I'm using the IfActions incorrectly but my IfAction doesn't appear to be called when the values match.

Code: Select all

[Rainmeter]
Update=1000
Background=#@#Background.png
BackgroundMode=3
BackgroundMargins=0,34,0,14

[Variables]
fontName=Trebuchet MS
textSize=8
colorText=255,255,255,205
CurrentState="%3!i! Wakka"

;-------------------------------------------------

[MeasureUpTime]
Measure=UpTime
AddDaysToHours=0
IfEqualValue=6
IfEqualAction=!Execute [!RainmeterSetVariable CurrentState "%3!i! Day"]
Format=#CurrentState#

;-------------------------------------------------

[styleLeftText]
StringAlign=LEFT
StringCase=NONE
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

;-------------------------------------------------

[MeterUpTime]
Meter=String
MeterStyle=styleRightText
MeasureName=MeasureUpTime
X=10
Y=40
W=190
H=14
Text="Uptime: %1"
Running the above code results in it display "Uptime: <hour value of uptime> Wakka" even if the hour value is the same as my IfEqualsValue.
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Using Uptime with IfActions

Post by Mordasius »

Uptime outputs the number as text therefore you have to run it through a CALC measure to be able to do any math on it. The number is the number of seconds Uptime so you can't just use an IfEqualValue=1. In your case you could do something like this:

Code: Select all

[MeasureUpDays]
Measure=UpTime
Format=%4!i!

[CalcUpDays]
Measure=CALC
Formula=( [MeasureUpDays] % 5184000)
IfBelowValue=1
IfBelowAction=[!SetVariable DayText Days]
IfequalValue=1
IfequalAction=[!SetVariable DayText Day]
IfaboveValue=1
IfaboveAction=[!SetVariable DayText Days]
DynamicVariables=1


[MeasureUpHours]
Measure=UpTime
Format=%3!i!

[CalcUpHours]
Measure=CALC
Formula=( [MeasureUpHours] % 216000)
IfBelowValue=1
IfBelowAction=[!SetVariable HourText Hours]
IfequalValue=1
IfequalAction=[!SetVariable HourText Hour]
IfaboveValue=1
IfaboveAction=[!SetVariable HourText Hours]
DynamicVariables=1

[MeasureUpMinutes]
Measure=UpTime
Format=%2!i!

[CalcUpMinutes]
Measure=CALC
Formula=( [MeasureUpMinutes] % 3600 )
IfBelowValue=1
IfBelowAction=[!SetVariable MinText Minutes]
IfequalValue=1
IfequalAction=[!SetVariable MinText Minute]
IfaboveValue=1
IfaboveAction=[!SetVariable MinText Minutes]
DynamicVariables=1

[MeterUpTimeModded]
Meter=String
MeterStyle=styleLeftText
MeasureName=MeasureUpDays
MeasureName2=MeasureUpHours
MeasureName3=MeasureUpMinutes
Text="%1 #DayText#, %2 #HourText#, %3 #MinText#"
DynamicVariables=1
Or ... much simpler and cleaner way by Poiru see this post:

Code: Select all

[MeasureUpTime]
Measure=UpTime
Format=".%4!i! days and .%3!i! hours and .%2!i! minutes"
Substitute=".0 days and ":"",".1 days":"1 day",".0 hours and ":"",".1 hours":"1 hour"," and .0 minutes":"",".1 minutes":"1 minute",".":""
Sometimes pays to search before posting an answer :headbang:
Harley Gorillason
Posts: 4
Joined: July 10th, 2012, 2:56 am

Re: Using Uptime with IfActions

Post by Harley Gorillason »

I thought it might have been something to do with how UpTime returned the time. After making my post I started looking at the log and noticed that it was reporting values in the range of 0.0 to 1.0, so I started playing around with thinking they were in various percents. Didn't occur to me to see if it was returned as a text value.

That link to Poiru's post is very nice. I had a bit of a search through the forums but must have missed that one. Thanks for your help, works perfectly now.