It is currently April 26th, 2024, 11:01 am

Help Formula

Get help with creating, editing & fixing problems with skins
User avatar
xenium
Posts: 867
Joined: January 4th, 2018, 9:52 pm

Help Formula

Post by xenium »

Hi,
I want to make a skin about the moon, which displays for each percentage of illumination, an image.

For the first part it is ok, The values returned by the webparser measure are increasing from 0 to 100. The images will be ...97.png, 98.png, 99.png ...
The formula can be for example:

Code: Select all

[MeasureA]
Measure=Calc
Formula=(((MeasureValue >= 97) && (MeasureValue < 98)) ? 97 : (((MeasureValue >= 98) && (MeasureValue < 99)) ? 98
For the second part, the return values will decrease from 100 to 0. The images will be 199.png, 198.png, 197.png ...
But the problem appears in the formula. There will be the same formula as the first part only the number of the picture you will be different.

Code: Select all

[MeasureB]
Measure=Calc
Formula=(((MeasureValue >= 97) && (MeasureValue < 98)) ? 197 : (((MeasureValue >= 98) && (MeasureValue < 99)) ? 198
But it did not work because there is already this formula for the first part.

Any idea how could the formula be for the second part?

Thanks
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help Formula

Post by balala »

What is the source of the information you're parsing? The site probably are returning, beside the percentage, the moon age as well? Does it? Because if it is, this age can be used to know which formula should have to be used.
Let's say the [MeasureMoonAge] WebParser measure returns the age of the Moon (the number of days since last New Moon). You have to create another Calc measure, which returns the appropriate number. Something like:

Code: Select all

[MeasureMoonAge]
Measure=WebParser
...
;This measure returns the age of the Moon

[MeasureImage]
Measure=Calc
Formula=(( [MeasureMoonAge] <= 14 ) ? MeasureA : MeasureB )
DynamicVariables=1
The above measure returns the value of [MeasureA] measure in the first 14 days after new moon (so before Full Moon) and the value of [MeasureB] measure after that moment.
But there is one more update I'd do to the posted Formula options. Both formulas should have to have 99 conditions, for each possible percentage, right? A much simpler solution would be:

Code: Select all

[MeasureA]
Measure=Calc
Formula=( Floor ( [MeasureValue] ))
DynamicVariables=1

[MeasureB]
Measure=Calc
Formula=( 100 + Floor ( [MeasureValue] ))
DynamicVariables=1
(If [MeasureValue] is a WebParser measure, probably you have to add a DynamicVariables=1 option to both measures and include the name of measure, into brackets.)
I think these formulas are much simpler and convenient.
If this didn't help, please post the whole code of your skin.
User avatar
xenium
Posts: 867
Joined: January 4th, 2018, 9:52 pm

Re: Help Formula

Post by xenium »

balala wrote:What is the source of the information you're parsing? The site probably are returning, beside the percentage, the moon age as well? Does it? Because if it is, this age can be used to know which formula should have to be used.
Let's say the [MeasureMoonAge] WebParser measure returns the age of the Moon (the number of days since last New Moon). You have to create another Calc measure, which returns the appropriate number. Something like:

Code: Select all

[MeasureMoonAge]
Measure=WebParser
...
;This measure returns the age of the Moon

[MeasureImage]
Measure=Calc
Formula=(( [MeasureMoonAge] <= 14 ) ? MeasureA : MeasureB )
DynamicVariables=1
The above measure returns the value of [MeasureA] measure in the first 14 days after new moon (so before Full Moon) and the value of [MeasureB] measure after that moment.
But there is one more update I'd do to the posted Formula options. Both formulas should have to have 99 conditions, for each possible percentage, right? A much simpler solution would be:

Code: Select all

[MeasureA]
Measure=Calc
Formula=( Floor ( [MeasureValue] ))
DynamicVariables=1

[MeasureB]
Measure=Calc
Formula=( 100 + Floor ( [MeasureValue] ))
DynamicVariables=1
(If [MeasureValue] is a WebParser measure, probably you have to add a DynamicVariables=1 option to both measures and include the name of measure, into brackets.)
I think these formulas are much simpler and convenient.
If this didn't help, please post the whole code of your skin.
:17good
Thanks a lot !
It works!
At least for the first 99 images.
For the rest, I can test them in about 12 days after Full Moon :D

I have a question about your formula from [MeasureB]:
The images for[ MeasureB] are numbered, depending on the percentage (199.png, 198.png, 197.png ...... 101.png).
So if the percentages are for example 98%, 97%, the images 198.png, 197.png will be displayed ?
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help Formula

Post by balala »

xenium wrote:I have a question about your formula from [MeasureB]:
The images for[ MeasureB] are numbered, depending on the percentage (199.png, 198.png, 197.png ...... 101.png).
So if the percentages are for example 98%, 97%, the images 198.png, 197.png will be displayed ?
I can't test it (especially that I don't even know the whole code), but I hope it will.
That's why I ask you to post the whole code.
User avatar
xenium
Posts: 867
Joined: January 4th, 2018, 9:52 pm

Re: Help Formula

Post by xenium »

balala wrote:I can't test it (especially that I don't even know the whole code), but I hope it will.
That's why I ask you to post the whole code.
I think it works. :)
I changed the names of measures A and B, with B and A, and displays images numbered over 100.
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help Formula

Post by balala »

xenium wrote:I think it works. :)
I changed the names of measures A and B, with B and A, and displays images numbered over 100.
But I think there are a few other things I'd improve. For example I think I could reduce the number of measures. But for this I'd need the whole code.
If you think so, post the code, please.
User avatar
xenium
Posts: 867
Joined: January 4th, 2018, 9:52 pm

Re: Help Formula

Post by xenium »

balala wrote:But I think there are a few other things I'd improve. For example I think I could reduce the number of measures. But for this I'd need the whole code.
If you think so, post the code, please.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1


[Variables]
Updaterate=600



[MeasureMoonPercent]
Measure=WebParser
Url=http://iohelix.net/moon/moonlite.xml
RegExp=(?siU)<moon>.*<elongationToSun>.*</elongationToSun>.*<percentIlluminated>(.*)</percentIlluminated>.*<age>(.*)</age>.*<phase>(.*)</phase>.*<length>.*</length>
UpdateRate=#Updaterate#
StringIndex=1

[MeasureMoonAge]
Measure=WebParser
Url=[MeasureMoonPercent]
StringIndex=2

[MeasureMoonPhase]
Measure=WebParser
Url=[MeasureMoonPercent]
StringIndex=3

[MeasureA]
Measure=Calc
Formula=( Floor ( [MeasureMoonPercent] ))
DynamicVariables=1

[MeasureB]
Measure=Calc
Formula=( 100 + Floor ( [MeasureMoonPercent] ))
DynamicVariables=1

[MeasureImage]
Measure=Calc
Formula=(( [MeasureMoonAge] <= 14 ) ? MeasureA : MeasureB )
DynamicVariables=1



[MeterMoonPhase]
Meter=String
MeasureName=MeasureMoonPhase
X=100
Y=0
W=150
H=14
FontSize=10
FontColor=255,255,255,190
StringStyle=Bold
StringEffect=SHADOW
FontFace=arial
StringAlign=left
FontEffectColor=0,0,0,50
AntiAlias=1
Text="%1"

[MeterMoonIlluminated]
Meter=String
MeasureName=MeasureMoonPercent
X=100
Y=50r
W=150
H=14
FontSize=10
FontColor=255,255,255,190
StringStyle=Bold
StringEffect=SHADOW
FontFace=arial
StringAlign=left
FontEffectColor=0,0,0,50
AntiAlias=1
Text="illuminated: %1 %"

[MeterMoonImage]
Meter=Image
X=50
Y=50
W=128
H=128
ImageName=#@#MoonFrame\[MeasureImage].jpg
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help Formula

Post by balala »

Here is a new code. I made the following modifications:
  • I removed the [MeasureA] and [MeasureB] measures. I think they are not needed, [MeasureImage] can do the needed calculations.
  • Based on the previous point, I updated the Formula of [MeasureImage] measure.
  • The [MeasureMoonAge] and [MeasureMoonPercent] measures, being WebParser measures, when the skin is refreshed, they get their values just after the measure(s) parse the data. This means the [MeasureImage] measure gives a "Calc: Extra operation" error message in the log. To avoid it, I disabled the [MeasureImage] measure and added a FinishAction option to the parent WebParser measure, to enable and update the [MeasureImage] measure, once the WebParser measures finish parsing the data.
  • I applied a regular expression substitution to the [MeasureImage] measure. This substitution makes the measure to return the full path of the image. According to this, I removed the ImageName and added a MeasureName option to the [MeterMoonImage] meter. This way the Image meter doesn't require to set up the dynamic variables.
  • I added a [StringStyle] style section and modified the String meters to use this style.
  • I also applied a few other small updates. For example I removed the not needed quotations from the Text options of both String meters (https://forum.rainmeter.net/viewtopic.php?p=137635#p137635) and added an invisible background to the whole skin, to make it easier clickable.
Please test this updated code and let me know if it does work:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,1

[Variables]
Updaterate=600

[StringStyle]
X=100
W=150
H=14
FontSize=10
FontColor=255,255,255,190
StringStyle=Bold
StringEffect=SHADOW
FontFace=arial
StringAlign=left
FontEffectColor=0,0,0,50
AntiAlias=1

[MeasureMoonPercent]
Measure=WebParser
Url=http://iohelix.net/moon/moonlite.xml
RegExp=(?siU)<moon>.*<elongationToSun>.*</elongationToSun>.*<percentIlluminated>(.*)</percentIlluminated>.*<age>(.*)</age>.*<phase>(.*)</phase>.*<length>.*</length>
UpdateRate=#Updaterate#
FinishAction=[!EnableMeasure "MeasureImage"][!UpdateMeasure "MeasureImage"]
StringIndex=1

[MeasureMoonAge]
Measure=WebParser
Url=[MeasureMoonPercent]
StringIndex=2

[MeasureMoonPhase]
Measure=WebParser
Url=[MeasureMoonPercent]
StringIndex=3

[MeasureImage]
Measure=Calc
Formula=(( 100 * ( [MeasureMoonAge] > 14 )) + ( Floor ( [MeasureMoonPercent] )))
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(\d{1,2})$":"#@#MoonFrame\\1.jpg"
Disabled=1

[MeterMoonPhase]
Meter=String
MeasureName=MeasureMoonPhase
MeterStyle=StringStyle
Y=0
Text=%1

[MeterMoonIlluminated]
Meter=String
MeasureName=MeasureMoonPercent
MeterStyle=StringStyle
Y=50r
Text=Illuminated: %1%

[MeterMoonImage]
Meter=Image
MeasureName=MeasureImage
X=50
Y=50
W=128
H=128
User avatar
xenium
Posts: 867
Joined: January 4th, 2018, 9:52 pm

Re: Help Formula

Post by xenium »

It works! :thumbup:
Just a small change I made to [MeasureImage] -Substitute: 0.jpg instead of 1.jpg.
(to stop showing up, an error message in the Log ,"ImageName: Unable to open: C: \ Users \ HOME \ Documents \ RainMeter \ Skins \ MOON \ @Resources \ MoonFrame0.jpg" )

I'll keep track of how it works, especially after Full Moon.

Thank you very much for your help ! :bow:
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help Formula

Post by balala »

xenium wrote:Just a small change I made to [MeasureImage] -Substitute: 0.jpg instead of 1.jpg.
(to stop showing up, an error message in the Log ,"ImageName: Unable to open: C: \ Users \ HOME \ Documents \ RainMeter \ Skins \ MOON \ @Resources \ MoonFrame0.jpg" )
That's a regular expression substitution (Substitute="^(\d{1,2})$":"#@#MoonFrame\\1.jpg"). There is nothing substituted with 1.jpg. ":"#@#MoonFrame\[color=#FF0000]\1.jpg[/color] means the first found expression in (\d{1,2})$.
I'm sorry, but I don't think you get an error message, because the [MeasureImage] measure is disabled in the very first moment, being enabled when the WebParser measures get their values. But after this, the value of the [MeasureImage] measure is never 0 again.

However let me know how does it work, after the Full Moon too.