It is currently May 3rd, 2024, 10:51 am

Determining if a MeasureTemperature variable is empty

Get help with creating, editing & fixing problems with skins
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Determining if a MeasureTemperature variable is empty

Post by neo.nemek »

Hi guys I have some experience understanding the Rainmeter code and I decided to make a Weather Skin.
The fact is that I've been reading topics and help in this forum about Variables and Conditionals for 2 days, and I can't find a way to solve and do or determine if a Dynamic Variable of the Weather Skin is EMPTY, I expose the problem:

I have a file called "Variables.inc" that contains this variable "TempCondition=0" to compare it later.
I have a file called "Measures.inc" that contains this code:

Code: Select all

;Code in file "Measures.inc"
[Variables]
@Include=#SKINSPATH#\MySkin\Resources\Variables\UserVariables.inc
@Include2=#SKINSPATH#\MySkin\Resources\Variables\Variables.inc
.
.
.
[MeasureTemperature]
Measure=WebParser
Url=[MeasureCurrentObservations]
StringIndex=6
MinValue=#TempMinValue#
MaxValue=#TempMaxValue#
IfCondition=MeasureTemperature <= #TempCondition#	;Determines if the value of MeasureTemperature is less than 0 !!! I have not been able to test this condition yet !!!
IfTrueAction=[!SetVariable LiquidColor "23,129,243"]
IfFalseAction=[!SetVariable LiquidColor "255,14,0"]
.
.
.
I have a file called "Weather - Left Tab.ini" that contains this code:

Code: Select all

;Code in file "Weather - Left Tab.ini"
....
[MeterTEMP]
Meter=String
MeasureName=MeasureTemperature
Meter=String
X=292
Y=42
W=350
H=50
FontSize=13.5
FontFace=#Secondary Font#
FontColor=#Secondary Font Color#
FontEffectColor=#FontEffectColor#
StringStyle=#String Style#
StringEffect=SHADOW
StringAlign=Right
AntiAlias=1
Text=%1°
....
My problem is not with this comparison on "0".
This code together shows the value of the current Temperature of my city but does not show any value if the weather server is down or I do not have an Internet connection.
My problem is about what instructions to add to the code written in "Measures.inc" so that in case the weather server is down or I don't have an Internet connection, the Weather Skin shows me "N/A" instead of just "°"
In other words, I don't know how to check and determine if "MeasureTemperature" is empty without data and if this is the case, the Skin shows me "N/A" instead of "°"
I will be very grateful if you help me understand and write this comparison that I don't know how to do, thanks.
User avatar
balala
Rainmeter Sage
Posts: 16195
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Determining if a MeasureTemperature variable is empty

Post by balala »

neo.nemek wrote: February 11th, 2023, 8:47 am In other words, I don't know how to check and determine if "MeasureTemperature" is empty without data and if this is the case, the Skin shows me "N/A" instead of "°"
You have to use IfMatch. For instance, try adding the following options to the [MeasureTemperature] measure, beside the existing ones (don't remove any of them):

Code: Select all

[MeasureTemperature]
...
IfMatch=^$
IfMatchAction=[!SetOption MeterTEMP Text "N/A"][!UpdateMeter "MeterTEMP"][!Redraw]
IfNotMatchAction=[!SetOption MeterTEMP Text "%1[\x00B0]"][!UpdateMeter "MeterTEMP"][!Redraw]
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: Determining if a MeasureTemperature variable is empty

Post by neo.nemek »

Perfect, thank you very much, it worked the first time, I must say that I had already read the help for IfMatchActions but no matter how many times I tried, I did not get the desired result, I am infinitely grateful for your help
User avatar
balala
Rainmeter Sage
Posts: 16195
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Determining if a MeasureTemperature variable is empty

Post by balala »

neo.nemek wrote: February 11th, 2023, 2:19 pm Perfect, thank you very much, it worked the first time, I must say that I had already read the help for IfMatchActions but no matter how many times I tried, I did not get the desired result, I am infinitely grateful for your help
Great!
IfMatch uses regular expressions, which are not quite easy to work with. For instance here the IfMatch=^$ expression check if the string returned by the measure in which it is used (in this case [MeasureTemperature]), contains nothing. ^ means the beginning of the string returned by the measure, while $ representes its end. If these two are used together means the string contains nothing between its beginning and its end, so it's empty.

And one more: in Rainmeter, unlike in a real programming language, you can't add a comment into a line having an option which you'd like to get working. In the posted piece of code, you had a comment added to the end of the IfCondition option of the [MeasureTemperature] measure: IfCondition=MeasureTemperature <= #TempCondition# ;Determines if the value of MeasureTemperature is less than 0 !!! I have not been able to test this condition yet !!!. Rainmeter fails in evaluating any kind of expression, if it has an ending comment. The comments HAVE TO BE ADDED into new line. In the above IfCondition the condition itself (marked green) has to be put into a line, while the red marked comment, has to go to a new line:

Code: Select all

[MeasureTemperature]
...
IfCondition=MeasureTemperature <= #TempCondition#
;Determines if the value of MeasureTemperature is less than 0 !!! I have not been able to test this condition yet !!!
...
In Rinmeter this is the correct procedure. Having the condition in the same line, prevents the IfCondition (or other option) to work. In this case neither the IfTrueAction, nor the IfFalseAction is executed, no matter what value is returned by the measure. In a programming language (Lua, C, Delphi or others) this is possible, in Rainmeter it's not. The explanation is simple: some Rainmeter options (TransformationMatrix for example) use the semicolon and as such there hard to tell Rainmeter which semicolon want you to use to comment and which one is part of the option. Some details here.
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: Determining if a MeasureTemperature variable is empty

Post by neo.nemek »

balala wrote: February 11th, 2023, 3:22 pm And one more: in Rainmeter, unlike in a real programming language, you can't add a comment into a line having an option which you'd like to get working. In the posted piece of code, you had a comment added to the end of the IfCondition option of the [MeasureTemperature] measure: IfCondition=MeasureTemperature <= #TempCondition# ;Determines if the value of MeasureTemperature is less than 0 !!! I have not been able to test this condition yet !!!. Rainmeter fails in evaluating any kind of expression, if it has an ending comment. The comments HAVE TO BE ADDED into new line. In the above IfCondition the condition itself (marked green) has to be put into a line, while the red marked comment, has to go to a new line:

Code: Select all

[MeasureTemperature]
...
IfCondition=MeasureTemperature <= #TempCondition#
;Determines if the value of MeasureTemperature is less than 0 !!! I have not been able to test this condition yet !!!
...
In Rinmeter this is the correct procedure. Having the condition in the same line, prevents the IfCondition (or other option) to work. In this case neither the IfTrueAction, nor the IfFalseAction is executed, no matter what value is returned by the measure. In a programming language (Lua, C, Delphi or others) this is possible, in Rainmeter it's not. The explanation is simple: some Rainmeter options (TransformationMatrix for example) use the semicolon and as such there hard to tell Rainmeter which semicolon want you to use to comment and which one is part of the option. Some details here.
Ok I understand and I will remove that comment from that line, perfect I ike learning things about Rainmeter.
I am very used to working with Regex since I spent about 1 year translating a Japanese game where we used Regex to search for text strings.
Great, now I'm trying to find out how the weather icons are displayed, specifically what data delivers to it or how this code works:

Code: Select all

[MeasureIcon]
Measure=WebParser
Url=[MeasureCurrentObservations]
StringIndex=1
For this I had the idea of ​​putting this Temporary Meter to check that data:

Code: Select all

[MeterTemp-PRUEBA]
Meter=String
MeasureName=MeasureIcon
X=1180 ;270
Y=64 ;74
FontSize=30
FontColor=#Weather Color#
StringStyle=#String Style#
FontFace=#Primary Font#
StringAlign=right
AntiAlias=1
Text=%1=DATA ICON WEATHER
But at this moment I can't test that code because the "Wheather.com" API doesn't return data to me, I suppose that if I make many time requests in a row because I have to do tests, they will ban my public IP for a while.
I would really like to know if this assumption is correct because to position the elements or icons of the weather skin I have to do a lot of tests and requests.
Could you say what data "[MeasureIcon]" delivers? Thanks again
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Determining if a MeasureTemperature variable is empty

Post by eclectic-tech »

neo.nemek wrote: February 12th, 2023, 10:37 am {clip}
But at this moment I can't test that code because the "Wheather.com" API doesn't return data to me, I suppose that if I make many time requests in a row because I have to do tests, they will ban my public IP for a while.
I would really like to know if this assumption is correct because to position the elements or icons of the weather skin I have to do a lot of tests and requests.
Could you say what data "[MeasureIcon]" delivers? Thanks again
Accessing the site multiple times during testing may get your IP blocked for a time.
I use Debug=2 once on my main Webparser measure to create a WebparserDump.txt file. See Debug

This gives me a local file to test RegExp without accessing the site repeatedly; set the URL in the main measure to:
URL=file:///#CurrentPath#WebparserDump.txt

And comment out ; Debug=2

In your case, this does not help determining the icons used, but if you are accessing Weather.com or Yahoo.com as the source, there are plenty of example icons and list of their related weather terms on this forum. If you need help find specific ones just ask.
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: Determining if a MeasureTemperature variable is empty

Post by neo.nemek »

I understand, I'll take it into account and I'll look at the "Debug" I already assumed that repeating several calls to Weather.com would block my IP for a while, I almost have fully developed the Weather Skin and the texts and graphic icons on your place, I just The final touches are left and understand what I said before about the data that Weather.com sends me about the weather icon, thanks for all the help you give me
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Determining if a MeasureTemperature variable is empty

Post by eclectic-tech »

neo.nemek wrote: February 12th, 2023, 1:02 pm I understand, I'll take it into account and I'll look at the "Debug" I already assumed that repeating several calls to Weather.com would block my IP for a while, I almost have fully developed the Weather Skin and the texts and graphic icons on your place, I just The final touches are left and understand what I said before about the data that Weather.com sends me about the weather icon, thanks for all the help you give me
Weather.com returns a number (0~47) to represent their icons.
Here is a list of the numbers and their meaning:

Code: Select all

 0 : Tornado : Day & Night
 1 : Tropical Storm : Day & Night
 2 : Hurricane : Day & Night
 3 : Strong Storms : Day & Night
 4 : Thunderstorms : Day & Night
 5 : Rain / Snow : Day & Night
 6 : Rain / Sleet : Day & Night
 7 : Wintry Mix : Day & Night
 8 : Freezing Drizzle : Day & Night
 9 : Drizzle : Day & Night
10 : Freezing Rain : Day & Night
11 : Showers : Day & Night
12 : Rain : Day & Night
13 : Flurries : Day & Night
14 : Snow Showers : Day & Night
15 : Blowing / Drifting Snow : Day & Night
16 : Snow : Day & Night
17 : Hail : Day & Night
18 : Sleet : Day & Night
19 : Blowing Dust / Sandstorm : Day & Night
20 : Foggy : Day & Night
21 : Haze : Day & Night
22 : Smoke : Day & Night
23 : Breezy : Day & Night
24 : Windy : Day & Night
25 : Frigid / Ice Crystals : Day & Night
26 : Cloudy : Day & Night
27 : Mostly Cloudy : Night 
28 : Mostly Cloudy : Day
29 : Partly Cloudy : Night
30 : Partly Cloudy : Day
31 : Clear : Night
32 : Sunny : Day
33 : Fair / Mostly Clear : Night
34 : Fair / Mostly Sunny : Day
35 : Mixed Rain and Hail : Day
36 : Hot : Day
37 : Isolated Thunderstorms : Day
38 : Scattered Thunderstorms : Day
39 : Scattered Showers : Day
40 : Heavy Rain : Day & Night
41 : Scattered Snow Showers : Day
42 : Heavy Snow : Day & Night
43 : Blizzard : Day & Night
44 : Not Available (N/A) : Day & Night
45 : Scattered Showers : Night
46 : Scattered Snow Showers : Night
47 : Scattered Thunderstorms : Night
There are plenty of example set of icons you can find by downloading any package from this forum that uses Weather.com as the source.
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: Determining if a MeasureTemperature variable is empty

Post by neo.nemek »

Perfect, I now understand how the graphic icons of the weather are represented, this will allow me to execute a code like the one in the second post to determine and send code 44 to the Meter.

Thank you so much everyone.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Determining if a MeasureTemperature variable is empty

Post by eclectic-tech »

Happy to help :welcome: