It is currently May 24th, 2019, 10:07 pm

Understanding Ifmatch

Help with creating, editing & fixing problems with skins
ms310
Posts: 94
Joined: April 1st, 2015, 7:16 am

Understanding Ifmatch

ms310 » May 14th, 2019, 4:02 am

Hi there - I have stumbled upon some code and I would like to know how it works.

Code: Select all

[MeasureCurrent]
Measure=Plugin
Plugin=WebParser
Url=https://wxdata.weather.com/wxdata/weather/local/#Location#?cc=*&unit=#Unit#
RegExp="(?siU)<head>.*<ut>(.*)</ut>.*<dnam>(.*)</dnam>.*<tmp>(.*)</tmp>.*<t>(.*)</t>.*<hmid>(.*)</hmid>.*<icon>(.*)</icon>"
UpdateRate=900
StringIndex=6
IfMatch=(?si)0
IfMatchAction=[!SetVariable FontColor "133,133,133"]
IfMatch2=(?si)1|2|3|4|17|35|
IfMatchAction2=[!SetVariable FontColor "34,2,101"]
IfMatch3=(?si)5|6|7|8|9|10|11|12|18
IfMatchAction3=[!SetVariable FontColor "93,106,123"]
IfMatch4=(?si)13|14|15|16|25|42|43
IfMatchAction4=[!SetVariable FontColor "226,223,232"]
IfMatch5=(?si)19|20|21|22|23|24
IfMatchAction5=[!SetVariable FontColor "151,147,159"]
IfMatch6=(?si)26|44
IfMatchAction6=[!SetVariable FontColor "58,146,255"]
IfMatch7=(?si)28|29|33|45
IfMatchAction7=[!SetVariable FontColor "44,102,174"]
IfMatch8=(?si)31
IfMatchAction8=[!SetVariable FontColor "3,55,98"]
IfMatch9=(?si)30|32|34|37|38|39|40|41
IfMatchAction9=[!SetVariable FontColor "241,154,16"]
I get that based on some condition set the variable FontColor. What confuses me is the Match statements - what is being compared? Thanks for the help!
User avatar
ikarus1969
Posts: 327
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Understanding Ifmatch

ikarus1969 » May 14th, 2019, 5:12 am

IfMatch compares/matches the result of its measure. In this case the, because it's a Webparser measure, the resulting string is set by the StringIndex-option.
Here StringIndex=6 means that the IfMatch-options match against the sixth capture: the icon-number.
Depending on the icon-number it sets the FontColor used elsewhere.

e.g. for icon numbers 1, 2, 3, 4, 17 or 35 it sets the FontColor to "34,2,101" (IfMatch2)

docu: IfMatchActions

edit: a capture is basially something sourrounded by "(" and ")" (if not escaped by a back-slash). What i use as a reference to regular-expressions is https://www.regular-expressions.info/, but there are tons of sites dealing with regular-expressions...
ms310
Posts: 94
Joined: April 1st, 2015, 7:16 am

Re: Understanding Ifmatch

ms310 » May 14th, 2019, 5:47 am

ikarus1969 wrote:
May 14th, 2019, 5:12 am
IfMatch compares/matches the result of its measure. In this case the, because it's a Webparser measure, the resulting string is set by the StringIndex-option.
Here StringIndex=6 means that the IfMatch-options match against the sixth capture: the icon-number.
Depending on the icon-number it sets the FontColor used elsewhere.

e.g. for icon numbers 1, 2, 3, 4, 17 or 35 it sets the FontColor to "34,2,101" (IfMatch2)

docu: IfMatchActions

edit: a capture is basially something sourrounded by "(" and ")" (if not escaped by a back-slash). What i use as a reference to regular-expressions is https://www.regular-expressions.info/, but there are tons of sites dealing with regular-expressions...
AHHHHHHHH! Thank you so very much! That makes a lot of sense!
User avatar
ikarus1969
Posts: 327
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Understanding Ifmatch

ikarus1969 » May 14th, 2019, 6:43 am

Glad to help!
User avatar
balala
Rainmeter Sage
Posts: 8207
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Understanding Ifmatch

balala » May 14th, 2019, 7:07 am

Just note one more: although the IfConditions are entirely numeric and you can't use them to compare strings, in a such case when the measure returns number, IfConditions also can be used. I don't say it would have any advantage in front of IfMatch, probably it doesn1t have, just to know the possibility, here is another solution to the same problem:

Code: Select all

[MeasureCurrent]
Measure=WebParser
Url=https://wxdata.weather.com/wxdata/weather/local/#Location#?cc=*&unit=#Unit#
RegExp=(?siU)<head>.*<ut>(.*)</ut>.*<dnam>(.*)</dnam>.*<tmp>(.*)</tmp>.*<t>(.*)</t>.*<hmid>(.*)</hmid>.*<icon>(.*)</icon>
UpdateRate=900
StringIndex=6
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!SetVariable FontColor "133,133,133"]
IfCondition2=(((#CURRENTSECTION#>=1)&&(#CURRENTSECTION#<=4))||(#CURRENTSECTION#=17)||(#CURRENTSECTION#=35))
IfTrueAction2=[!SetVariable FontColor "34,2,101"]
IfCondition3=(((#CURRENTSECTION#>=5)&&(#CURRENTSECTION#<=12))||(#CURRENTSECTION#=18))
IfTrueAction3=[!SetVariable FontColor "93,106,123"]
IfCondition4=(((#CURRENTSECTION#>=13)&&(#CURRENTSECTION#<=16))||(#CURRENTSECTION#=25)||(#CURRENTSECTION#=42)||(#CURRENTSECTION#=43))
IfTrueAction4=[!SetVariable FontColor "226,223,232"]
IfCondition5=((#CURRENTSECTION#>=19)&&(#CURRENTSECTION#<=24))
IfTrueAction5=[!SetVariable FontColor "151,147,159"]
IfCondition6=((#CURRENTSECTION#=26)||(#CURRENTSECTION#=44))
IfTrueAction6=[!SetVariable FontColor "58,146,255"]
IfCondition7=((#CURRENTSECTION#=28)||(#CURRENTSECTION#=29)||(#CURRENTSECTION#=33)||(#CURRENTSECTION#=45))
IfTrueAction7=[!SetVariable FontColor "44,102,174"]
IfCondition8=(#CURRENTSECTION#=31)
IfTrueAction8=[!SetVariable FontColor "3,55,98"]
IfCondition9=((#CURRENTSECTION#=30)||(#CURRENTSECTION#=32)||(#CURRENTSECTION#=34)||((#CURRENTSECTION#>=37)&&(#CURRENTSECTION#<=41)))
IfTrueAction9=[!SetVariable FontColor "241,154,16"]
No IfMatches in this case.
Again, probably this solution has no advantages in front of the solution with IfMatch, it's just another approach of the same problem.
Note that in the above (re)posted measure I: EDIT: Fixed this code, after ikarus1969 found a mistake in the originally posted one. Thanks ikarus1969 and sorry for my mistake.
User avatar
ikarus1969
Posts: 327
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Understanding Ifmatch

ikarus1969 » May 14th, 2019, 7:24 am

balala wrote:
May 14th, 2019, 7:07 am

Code: Select all

IfCondition9=((#CURRENTSECTION#=30)||(#CURRENTSECTION#=32)||(#CURRENTSECTION#=34)||((#CURRENTSECTION#=37)||(#CURRENTSECTION#<=41)))
IfTrueAction9=[!SetVariable FontColor "241,154,16"]
Wouldn't the only Color be "241, 154, 16" because of your IfCondition9?
There is "...||(#CURRENTSECTION#<=41)" without combining it with the lower value "37" correctly with an "and"-condition.
User avatar
balala
Rainmeter Sage
Posts: 8207
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Understanding Ifmatch

balala » May 14th, 2019, 9:51 am

ikarus1969 wrote:
May 14th, 2019, 7:24 am
Wouldn't the only Color be "241, 154, 16" because of your IfCondition9?
There is "...||(#CURRENTSECTION#<=41)" without combining it with the lower value "37" correctly with an "and"-condition.
OOPS, you're absolutely right. My mistake. Correctly IfCondition9 is: IfCondition9=((#CURRENTSECTION#=30)||(#CURRENTSECTION#=32)||(#CURRENTSECTION#=34)||((#CURRENTSECTION#>=37)&&(#CURRENTSECTION#<=41))).
I fixed the code I've posted above as well.

Sorry for my mistake.