It is currently April 23rd, 2024, 5:44 pm

decimal symbol problems in webparser

Get help with creating, editing & fixing problems with skins
User avatar
jacobus60
Posts: 7
Joined: November 24th, 2017, 6:10 pm

decimal symbol problems in webparser

Post by jacobus60 »

Hi there,
I have created my own skin with some stocks, currencies and the Amsterdam Index displaying their respective data.

Name, Price, Price Change, Change Percentage and a symbol Up, Steady, Down. Also Red and Green colors for Up or Down.
Honestly I am proud to have achieved this already but there is a small problem which I am not able to figure out just yet.
Using the webparser RegExp to retrieve the needed data, all the above works perfectly if I use non Dutch webpages. I have narrowed the problem down already to the decimal symbol, i.e. our prices are listed as follows: AEX 540,630 whereas Google Finance for example would have 540.630

This affects my code which I can see already in the Skins Tab while observing the measures. For the ones with the decimal symbol being the dot both the number and the string display the correct values. The measures with the decimal symbol being a comma, the string displays the proper value but the number will be an integer, in this example 540.
-0,72 displays -0 for the number in the measures and +0,02 displays +0 in its measure.
How can I get the number within the measures to read exactly the same as within the string? Can I substitute the comma with the dot while parsing the data from the Url somehow in RegExp?

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

Re: decimal symbol problems in webparser

Post by balala »

Yeah, you can. Just add to each WebParser measure which return those numbers, the following option: Substitute=",":".". This option will make the needed substitution.
But probably if you want to use the value into a Calc (or other kind of) measure, you'll have to enclose the name of the measure into brackets and add the DynamicVariables=1 option to the measure.
If this wasn't clear enough (and probably especially if you're a newbie, it wasn't) please post the code you have so far.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: decimal symbol problems in webparser

Post by FreeRaider »

jacobus60 wrote:Can I substitute the comma with the dot while parsing the data from the Url somehow in RegExp?
Yes, you can.

Have a look at https://docs.rainmeter.net/manual/measures/general-options/substitute/#RegExpSubstitute

For the other question, can you post you code, so I (we) can help?




Edit: balala beat me
User avatar
jacobus60
Posts: 7
Joined: November 24th, 2017, 6:10 pm

Re: decimal symbol problems in webparser

Post by jacobus60 »

Hi there,
Thanks for the swift replies.
I had used the substitute already and that works for the display in the meters. For the colors and symbol I am using a Calc indeed but this is where the problem starts, for those strings with the comma, I am only getting the number upto the comma and therefore in an example like -0,72, the Calc is done with -0, not recognized as BelowValue.

Code: Select all

[Rainmeter]
Update=10
AccurateText=1

[Metadata]
Author=Sjaak Snoeren
Name=FD information
Version=1.0
Description= Shows the price and change in price for five stocks, currency or market indexes. Prices are from https://beurs.fd.nl/aandelen/amsterdam/aex/ | Right-click on the skin -> Edit Stocks/Labels - to change the stocks being shown

;___________________________________________________
;    STYLES

[sTextLeft]
FontFace=Calibri
FontSize=11
FontColor=255,225,181,255
SolidColor=47,47,47,255
StringAlign=LEFT
MouseOverAction=[!SetOption "#CURRENTSECTION#" FontColor 66ccff] [!Update]
MouseLeaveAction=[!SetOption "#CURRENTSECTION#" FontColor ""] [!Update]
Antialias=1
Group=2

[sTextRight]
FontFace=Calibri
FontSize=11
FontColor=255,225,181,255
SolidColor=47,47,47,255
StringAlign=RIGHT
FontSize=#FontHeight#
Antialias=1
Group=2
NumOfDecimals=2

;___________________________________________________
;    MEASURES

[MeasureStock1]
Measure=Plugin
Plugin=WebParser
Url=https://beurs.fd.nl/noteringen/12272/aex/koersen
;RegExp=(?siU)id="12272LastPrice">(.*)</span>.*<span.*>(.*)</span>.*<span.*>(.*)</span>
RegExp=(?siU)AEX</span>.*<span>(.*)</span>.*<span.*>(.*)</span>.*<span.*>(.*)</span>

[MeasureStock1_Price]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock1]
StringIndex=1
;Substitute=",":"."

[MeasureStock1_Change]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock1]
StringIndex=2

[MeasureStock1_UpDown]
Measure=Plugin
Plugin=WebParser
Url=[MeasureStock1]
StringIndex=2

[MeasureStock1_ChangePer]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock1]
StringIndex=3
;____________________________________________
[MeasureStock2]
Measure=Plugin
Plugin=WebParser
Url=https://beurs.fd.nl/noteringen/96535/pharming/koersen
RegExp=(?siU)Pharming Group</span>.*<span>(.*)</span>.*<span.*>(.*)</span>.*<span.*>(.*)</span>

[MeasureStock2_Price]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock2]
StringIndex=1
;Substitute=",":"."

[MeasureStock2_Change]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock2]
StringIndex=2

[MeasureStock2_UpDown]
Measure=Plugin
Plugin=WebParser
Url=[MeasureStock2]
StringIndex=2

[MeasureStock2_ChangePer]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock2]
StringIndex=3
;____________________________________________
[MeasureStock3]
Measure=Plugin
Plugin=WebParser
Url=https://beurs.fd.nl/noteringen/16923/asml/koersen
RegExp=(?siU)ASML Holding</span>.*<span>(.*)</span>.*<span.*>(.*)</span>.*<span.*>(.*)</span>

[MeasureStock3_Price]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock3]
StringIndex=1

[MeasureStock3_Change]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock3]
StringIndex=2

[MeasureStock3_UpDown]
Measure=Plugin
Plugin=WebParser
Url=[MeasureStock3]
StringIndex=2

[MeasureStock3_ChangePer]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock3]
StringIndex=3
;____________________________________________
[MeasureStock4]
Measure=Plugin
Plugin=WebParser
Url=https://finance.google.com/finance?q=EURUSD
RegExp=(?siU)1 EUR = <span class=bld>(.*)USD.*id=ref_10222480_c>(.*)</span>.*id=ref_10222480_cp>(.*)</span>

[MeasureStock4_Price]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock4]
StringIndex=1

[MeasureStock4_Change]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock4]
StringIndex=2

[MeasureStock4_UpDown]
Measure=Plugin
Plugin=WebParser
Url=[MeasureStock4]
StringIndex=2

[MeasureStock4_ChangePer]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock4]
StringIndex=3
;____________________________________________
[MeasureStock5]
Measure=Plugin
Plugin=WebParser
Url=https://finance.google.com/finance?q=EURCAD&ei=hgMXWtD0CIKPUM3ngbAG
RegExp=(?siU)1 EUR = <span class=bld>(.*)CAD.*id=ref_10222480_c>(.*)</span>.*id=ref_10222480_cp>(.*)</span>

[MeasureStock5_Price]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock5]
StringIndex=1

[MeasureStock5_Change]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock5]
StringIndex=2

[MeasureStock5_UpDown]
Measure=Plugin
Plugin=WebParser
Url=[MeasureStock5]
StringIndex=2

[MeasureStock5_ChangePer]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock5]
StringIndex=3

;___________________________________________________
;    METERS

[MeterBackground]
Meter=Image
W=320
H=170
SolidColor=20,20,20,255
UpdateDivider=-1

[MeterTitleBackground]
Meter=String
;MeterStyle=sTextLeft
SolidColor=47,47,47,255
X=5
Y=4
W=300
H=15
UpdateDivider=-1
Padding=5,5,5,5
AntiAlias=1
Text=""

[MeterTitle]
Meter=String
MeterStyle=sTextLeft
X=160
Y=0r
;W=300
H=15
UpdateDivider=-1
Padding=5,5,5,5
FontWeight=700
StringAlign=Center
AntiAlias=1
LeftMouseUpAction=https://beurs.fd.nl/aandelen/amsterdam/aex/
ToolTipText="@Beurs Financieel Dagblad"
Text=Financial Markets
;____________________________________________
[MeterStock1_ChangePer]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock1_ChangePer
X=315
Y=3R
W=300
H=15
Padding=5,5,5,5

[MeterStock1Label]
Meter=String
MeterStyle=sTextLeft
LeftMouseUpAction=https://beurs.fd.nl/noteringen/12272/aex/koersen
X=10
Y=5r
;W=300
H=15
;Padding=5,5,5,5
Text=AEX

[MeterStock1_Price]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock1_Price
X=150
Y=0r
H=15
;Padding=5,5,5,5

[UpDownSteady1]
Measure=Calc
Formula=MeasureStock1_UpDown
IfAboveValue=0
IfAboveAction=[!SetOption "MeterStock1_Change" "FontColor" "00FF00cc"] [!SetOption "MeterStock1_ChangePer" "FontColor" "00FF00cc"] [!SetOption "UpDownImage1" "ImageName" "#@#Up.png"]
IfEqualValue=0
IfEqualAction=[!SetOption "MeterStock1_Change" "FontColor" "255,225,181,255"] [!SetOption "MeterStock1_ChangePer" "FontColor" "255,225,181,255"][!SetOption "UpDownImage1" "ImageName" "#@#Steady.png"]
IfBelowValue=0
IfBelowAction=[!SetOption "MeterStock1_Change" "FontColor" FF0000"] [!SetOption "MeterStock1_ChangePer" "FontColor" "FF0000"] [!SetOption "UpDownImage1" "ImageName" "#@#Down.png"]

[MeterStock1_Change]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock1_Change
X=240
Y=0r
H=15
;Padding=5,5,5,5

[UpDownImage1]
Meter=Image
ImageName=#@#Steady.png
X=160
Y=0r
H=15
;____________________________________________
[MeterStock2_ChangePer]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock2_ChangePer
X=315
Y=7R
W=300
H=15
Padding=5,5,5,5

[MeterStock2Label]
Meter=String
MeterStyle=sTextLeft
LeftMouseUpAction=https://beurs.fd.nl/noteringen/96535/pharming/koersen
X=10
Y=5r
;W=300
H=15
;Padding=5,5,5,5
Text=Pharming

[MeterStock2_Price]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock2_Price
X=150
Y=0r
H=15
;Padding=5,5,5,5

[UpDownSteady2]
Measure=Calc
Formula=MeasureStock2_UpDown
IfAboveValue=0
IfAboveAction=[!SetOption "MeterStock2_Change" "FontColor" "00FF00cc"] [!SetOption "MeterStock2_ChangePer" "FontColor" "00FF00cc"] [!SetOption "UpDownImage2" "ImageName" "#@#Up.png"]
IfEqualValue=0
IfEqualAction=[!SetOption "MeterStock2_Change" "FontColor" "255,225,181,255"] [!SetOption "MeterStock2_ChangePer" "FontColor" "255,225,181,255"][!SetOption "UpDownImage2" "ImageName" "#@#Steady.png"]
IfBelowValue=0
IfBelowAction=[!SetOption "MeterStock2_Change" "FontColor" FF0000"] [!SetOption "MeterStock2_ChangePer" "FontColor" "FF0000"] [!SetOption "UpDownImage2" "ImageName" "#@#Down.png"]

[MeterStock2_Change]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock2_Change
X=240
Y=0r
H=15
;Padding=5,5,5,5

[UpDownImage2]
Meter=Image
ImageName=#@#Steady.png
X=160
Y=0r
H=15
;____________________________________________
[MeterStock3_ChangePer]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock3_ChangePer
X=315
Y=7R
W=300
H=15
Padding=5,5,5,5

[MeterStock3Label]
Meter=String
MeterStyle=sTextLeft
LeftMouseUpAction=https://beurs.fd.nl/noteringen/16923/asml/koersen
X=10
Y=5r
;W=300
H=15
;Padding=5,5,5,5
Text=ASML

[MeterStock3_Price]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock3_Price
X=150
Y=0r
H=15
;Padding=5,5,5,5

[UpDownSteady3]
Measure=Calc
Formula=MeasureStock3_UpDown
IfAboveValue=0
IfAboveAction=[!SetOption "MeterStock3_Change" "FontColor" "00FF00cc"] [!SetOption "MeterStock3_ChangePer" "FontColor" "00FF00cc"] [!SetOption "UpDownImage3" "ImageName" "#@#Up.png"]
IfEqualValue=0
IfEqualAction=[!SetOption "MeterStock3_Change" "FontColor" "255,225,181,255"] [!SetOption "MeterStock3_ChangePer" "FontColor" "255,225,181,255"][!SetOption "UpDownImage3" "ImageName" "#@#Steady.png"]
IfBelowValue=0
IfBelowAction=[!SetOption "MeterStock3_Change" "FontColor" "FF0000"] [!SetOption "MeterStock3_ChangePer" "FontColor" "FF0000"] [!SetOption "UpDownImage3" "ImageName" "#@#Down.png"]

[MeterStock3_Change]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock3_Change
X=240
Y=0r
H=15
;Padding=5,5,5,5

[UpDownImage3]
Meter=Image
ImageName=#@#Steady.png
X=160
Y=0r
H=15
;____________________________________________
[MeterStock4_ChangePer]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock4_ChangePer
X=315
Y=7R
W=300
H=15
Padding=5,5,5,5

[MeterStock4Label]
Meter=String
MeterStyle=sTextLeft
LeftMouseUpAction=https://finance.google.com/finance?q=EURUSD
X=10
Y=5r
;W=300
H=15
;Padding=5,5,5,5
Text=USD

[MeterStock4_Price]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock4_Price
X=150
Y=0r
H=15
;Padding=5,5,5,5

[UpDownSteady4]
Measure=Calc
Formula=MeasureStock4_UpDown
IfAboveValue=0
IfAboveAction=[!SetOption "MeterStock4_Change" "FontColor" "00FF00cc"] [!SetOption "MeterStock4_ChangePer" "FontColor" "00FF00cc"] [!SetOption "UpDownImage4" "ImageName" "#@#Up.png"]
IfEqualValue=0
IfEqualAction=[!SetOption "MeterStock4_Change" "FontColor" "255,225,181,255"] [!SetOption "MeterStock4_ChangePer" "FontColor" "255,225,181,255"][!SetOption "UpDownImage4" "ImageName" "#@#Steady.png"]
IfBelowValue=0
IfBelowAction=[!SetOption "MeterStock4_Change" "FontColor" "FF0000"] [!SetOption "MeterStock4_ChangePer" "FontColor" "FF0000"] [!SetOption "UpDownImage4" "ImageName" "#@#Down.png"]

[MeterStock4_Change]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock4_Change
X=240
Y=0r
H=15
;Padding=5,5,5,5

[UpDownImage4]
Meter=Image
ImageName=#@#Steady.png
X=160
Y=0r
H=15
;____________________________________________
[MeterStock5_ChangePer]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock5_ChangePer
X=315
Y=7R
W=300
H=15
Padding=5,5,5,5

[MeterStock5Label]
Meter=String
MeterStyle=sTextLeft
LeftMouseUpAction=https://finance.google.com/finance?q=EURCAD&ei=hgMXWtD0CIKPUM3ngbAG
X=10
Y=5r
;W=300
H=15
;Padding=5,5,5,5
Text=CAD

[MeterStock5_Price]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock5_Price
X=150
Y=0r
H=15
;Padding=5,5,5,5

[UpDownSteady5]
Measure=Calc
Formula=MeasureStock5_UpDown
IfAboveValue=0
IfAboveAction=[!SetOption "MeterStock5_Change" "FontColor" "00FF00cc"] [!SetOption "MeterStock5_ChangePer" "FontColor" "00FF00cc"] [!SetOption "UpDownImage5" "ImageName" "#@#Up.png"]
IfEqualValue=0
IfEqualAction=[!SetOption "MeterStock5_Change" "FontColor" "255,225,181,255"] [!SetOption "MeterStock5_ChangePer" "FontColor" "255,225,181,255"][!SetOption "UpDownImage5" "ImageName" "#@#Steady.png"]
IfBelowValue=0
IfBelowAction=[!SetOption "MeterStock5_Change" "FontColor" "FF0000"] [!SetOption "MeterStock5_ChangePer" "FontColor" "FF0000"] [!SetOption "UpDownImage5" "ImageName" "#@#Down.png"]

[MeterStock5_Change]
Meter=String
MeterStyle=sTextRight
MeasureName=MeasureStock5_Change
X=240
Y=0r
H=15
;Padding=5,5,5,5

[UpDownImage5]
Meter=Image
ImageName=#@#Steady.png
X=160
Y=0r
H=15
;Padding=5,5,5,5
;Group=2
User avatar
balala
Rainmeter Sage
Posts: 16162
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: decimal symbol problems in webparser

Post by balala »

jacobus60 wrote:For the colors and symbol I am using a Calc indeed but this is where the problem starts, for those strings with the comma, I am only getting the number upto the comma and therefore in an example like -0,72, the Calc is done with -0, not recognized as BelowValue.
As I've said in my previous post, if you want to use the value into a Calc (or any other kind of) measure, you have to use in the Formula, not the name of the substituted measure (which is returning the decimal number), but have to include its name into brackets and add a DynamicVariables=1 option to the Calc measure. You have to do this because the WebParser measures return a string, even if that string is in fact a number. Including the name into brackets converts that string to its numeric value. Eg the [MeasureStock1_Price] measure returns a number (right now 540,630) which when is substituted (the Substitute option is commented out, but we can easily put it back) becomes 540.630. But this value returned by the WebParser measure is a string. If you want to use it simply in a Calc measure, you can't as it is, due to the simple fact I've explained above. The following Calc measure won't work properly:

Code: Select all

[MeasureStock1_PriceCalc]
Measure=Calc
Formula=( MeasureStock1_Price + 1 )
This, as you've said, gives 541.000.
But if you're modifying the Calc measure as it follows, this one will work:

Code: Select all

[MeasureStock1_PriceCalc]
Measure=Calc
Formula=( [MeasureStock1_Price] + 1 )
DynamicVariables=1
This one returns right now 541.630, which is ok.
See in the code of this last Calc measure the brackets around the name of the measure [color=#FF0000][[/color]MeasureStock1_Price[color=#FF0000]][/color] instead of MeasureStock1_Price( and the DynamicVariables=1 option, which have to be used in the measures and meters which are using section variables (what the [MeasureStock1_Price] is).

And just a tip: I recommend to not use IfActions (IfBelowValue / IfBelowAction / IfEqualValue / IfequalAction / IfAboveValue / IfAboveAction), instead use the IfConditions, which are more versatile and should be prefered (at least I prefere them, since they was added).
arty_fish
Posts: 14
Joined: June 7th, 2016, 7:04 am

Re: decimal symbol problems in webparser

Post by arty_fish »

Or alternatively:

Code: Select all

[MeasureStock1_Change]
Measure=Plugin
Plugin=WebParser
URL=[MeasureStock1]
StringIndex=2
IfCondition=MeasureStock1_Change = 0
IfTrueAction=[!SetOption "MeterStock1_Change" "FontColor" "255,225,181,255"] [!SetOption "MeterStock1_ChangePer" "FontColor" "255,225,181,255"][!SetOption "UpDownImage1" "ImageName" "#@#Steady.png"]
IfMatch=\+
IfMatchAction=[!SetOption "MeterStock1_Change" "FontColor" "00FF00cc"] [!SetOption "MeterStock1_ChangePer" "FontColor" "00FF00cc"] [!SetOption "UpDownImage1" "ImageName" "#@#Up.png"]
IfMatch2=-
IfMatchAction2=[!SetOption "MeterStock1_Change" "FontColor" FF0000"] [!SetOption "MeterStock1_ChangePer" "FontColor" "FF0000"] [!SetOption "UpDownImage1" "ImageName" "#@#Down.png"]
Doing this for each [MeasureStockN_Change] (not forgetting to change the MeterStockN references each time) means you can get rid of each [MeasureStockN_UpDown] and [UpDownSteadyN] - which simplifies the code.

One more observation: Minimum effective Update value for a skin is 16. See: https://docs.rainmeter.net/manual/skins/rainmeter-section/

Edited to correct error on IfCondition statement
Last edited by arty_fish on November 26th, 2017, 12:00 pm, edited 1 time in total.
User avatar
jacobus60
Posts: 7
Joined: November 24th, 2017, 6:10 pm

Re: decimal symbol problems in webparser

Post by jacobus60 »

Excellent help guys, I have got my code to work properly now.
I have only used the substitute for the MeasureStock1_UpDown for the Calc later on. We are used to the comma as a decimal symbol so I left the other measures as is.
For now I have modified following balala's suggestion. For sure I will continue simplifying my code as you have suggested arty_fish.
Thanks you so much, this newbee is very happy to have made this giant step forward.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16162
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: decimal symbol problems in webparser

Post by balala »

arty_fish wrote:

Code: Select all

[MeasureStock1_Change]
...
IfCondition=0
arty_fish, have you tried your code? Because IfCondition=0 doesn't work. I didn't enter too deeply in your code, but this option in this form definitely doesn't work. It probably should be IfCondition=(#CURRENTSECTION#=0). The form you've used is valid for the IfActions (IfBelowValue / IfEqualValue / IfAboveValue), but not for the IfCondition.
arty_fish wrote:One more observation: Minimum effective Update value for a skin is 16. See: https://docs.rainmeter.net/manual/skins/rainmeter-section/
Good point, I've omitted this.
User avatar
jacobus60
Posts: 7
Joined: November 24th, 2017, 6:10 pm

Re: decimal symbol problems in webparser

Post by jacobus60 »

Started using the IfConditions, text makes more sense at least. Works perfectly.
Thanks balala :D
User avatar
balala
Rainmeter Sage
Posts: 16162
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: decimal symbol problems in webparser

Post by balala »

The IfCondition is a newer option and it's much better then the previously used IfActions. Usually should be prefered.
BTW, glad to help.