It is currently October 29th, 2020, 5:49 am

Trailing Zeros

General topics related to Rainmeter.
Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Re: Trailing Zeros

Post by Resike »

NumOfDecimals doesn't seems to work on strings from WebParser:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[ParsePrice]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=http://finance.yahoo.com/echarts?s=eurusd=x
RegExp="(?siU).*<span class="time_rtq_ticker.*">.*>(.*)</span>
StringIndex=1
UpdateRate=300
UpdateDivider=300

[MeasureCalc]
Measure=Calc
Formula=1 + 0.12

[MeterResult]
Meter=String
MeasureName=ParsePrice
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=1
User avatar
balala
Rainmeter Sage
Posts: 11640
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Trailing Zeros

Post by balala »

Yes, the WebParser measure seems to return a string, so you have to convert it to number. To do that, add this measure to your code:

Code: Select all

[MeasureCalc]
Measure=Calc
Formula=[ParsePrice]
DynamicVariables=1
The result of the [MeasureCalc] measure will be a number. Now you can set the number of decimals:

Code: Select all

[MeterResult]
Meter=String
MeasureName=ParsePrice
MeasureName2=MeasureCalc
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=%1#CRLF#%2
NumOfDecimals=1
User avatar
jsmorley
Developer
Posts: 21435
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trailing Zeros

Post by jsmorley »

Resike wrote:NumOfDecimals doesn't seems to work on strings from WebParser:
That's right.

This gets a little complicated and I admit not terribly intuitive.

The issue is that numeric operations can only be done on "number" values returned by a measure.

Most measures that return numbers as a value return both "string" and "number" values, so Rainmeter can use them either way. If for instance the measure returns 1.12, it can be used as a string in the Text option of a String meter, or as a number in a formula.

Some measures, certainly WebParser and the String measure, ONLY return a "string" value. They have no ability to generate or evaluate what they return as a real number, only as a string. It may happen to "look like" a number, but that doesn't mean anything in the anal-retentive, user-hostile programming in C++ under the covers. A string is a string, and a number is a number, it's about "type", not "value".

What does this mean in a practical sense?

For measures that only return strings you have to "convert" the string to a number to use it in any numeric way, including NumOfDecimals on a String meter.

The only real way to do that is to "pass the string through a Calc measure". The Calc measure is one of the only places in Rainmeter skin code that will evaluate a "numeric string" measure value and convert it to an actual "number".

So this will work:

Code: Select all

[ParsePrice]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=http://finance.yahoo.com/echarts?s=eurusd=x
RegExp="(?siU).*<span class="time_rtq_ticker.*">.*>(.*)</span>
StringIndex=1
UpdateRate=300
UpdateDivider=300

[PriceAsNumber]
Measure=Calc
Formula=[ParsePrice]
DynamicVariables=1

[MeterResult]
Meter=String
MeasureName=PriceAsNumber
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=1
Edit: Sorry, didn't notice that balala had really answered this perfectly well before me...
Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Re: Trailing Zeros

Post by Resike »

I see, it's working now.
User avatar
balala
Rainmeter Sage
Posts: 11640
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Trailing Zeros

Post by balala »

And one more thing about your code: don't use both UpdateRate and UpdateDivider options onto a single WebParser measure. For clarification, read this.
Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Re: Trailing Zeros

Post by Resike »

I have another issue now, i have a little graph which i would like to update each time the parser runs, however at the first parser tick it doesn't seems update (when i refresh the skin) only at the second tick:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[ParsePrice]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=http://finance.yahoo.com/echarts?s=eurusd=x
RegExp="(?siU).*<span class="time_rtq_ticker.*">.*>(.*)</span>
StringIndex=1
UpdateRate=10
UpdateDivider=10

[PriceAsNumber]
Measure=Calc
Formula=[ParsePrice]
DynamicVariables=1

[MeterResult]
Meter=String
MeasureName=PriceAsNumber
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,20
AntiAlias=1
NumOfDecimals=1

[Graph1]
Meter=Line
AutoScale=1
X=1
Y=20
W=28
H=14
MeasureName=PriceAsNumber
LineColor=faba00
UpdateDivider=10
Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Re: Trailing Zeros

Post by Resike »

balala wrote:And one more thing about your code: don't use both UpdateRate and UpdateDivider options onto a single WebParser measure. For clarification, read this.
I have an OnUpdateAction assigned to my parser, and if i don't use UpdateDivider on it then it's gonna run it's OnUpdateAction code every second.
User avatar
jsmorley
Developer
Posts: 21435
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trailing Zeros

Post by jsmorley »

Resike wrote:I have another issue now, i have a little graph which i would like to update each time the parser runs, however at the first parser tick it doesn't seems update (when i refresh the skin) only at the second tick:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[ParsePrice]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=http://finance.yahoo.com/echarts?s=eurusd=x
RegExp="(?siU).*<span class="time_rtq_ticker.*">.*>(.*)</span>
StringIndex=1
UpdateRate=10
UpdateDivider=10

[PriceAsNumber]
Measure=Calc
Formula=[ParsePrice]
DynamicVariables=1

[MeterResult]
Meter=String
MeasureName=PriceAsNumber
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,20
AntiAlias=1
NumOfDecimals=1

[Graph1]
Meter=Line
AutoScale=1
X=1
Y=20
W=28
H=14
MeasureName=PriceAsNumber
LineColor=faba00
UpdateDivider=10
You need to set Hidden=1 on the meter, and use !ShowMeter in a FinishAction on the WebParser measure. WebParser is a "threaded" plugin, due to the fact that connecting, downloading and parsing a big web site can take a little time. WebParser is designed not to "block" Rainmeter while it is waiting to finish, so unlike most measures, where the Rainmeter in a sense waits for the answer on each update, WebParser just says "I'm on it, go ahead with whatever else you are doing and keep checking back on each update. I'll have the answer when I have it."

The long and short of that is that the initial value of any WebParser measure is going to be "" (an empty string) for at least one skin update. FinishAction will allow you to to take some action when the measure is actually done getting the information and it is ready to use. In this case "unhiding" the meter.
User avatar
jsmorley
Developer
Posts: 21435
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trailing Zeros

Post by jsmorley »

Resike wrote: I have an OnUpdateAction assigned to my parser, and if i don't use UpdateDivider on it then it's gonna run it's OnUpdateAction code every second.
I'm not sure you want to use OnUpdateAction on a WebParser measure. Use FinishAction. What is the point of having the measure cause actions on every update, when the value of the measure can only at the very best, change every UpdateRate?

The trouble with mixing UpdateRate and UpdateDivider on a WebParser measure goes back to what I posted a second ago about "threaded". You don't want to have WebParser finish getting the answer for you, and then wait Update X UpdateDivider milliseconds before you check back and use the information. In some (but not all) cases, using UpdateDivider with WebParser can cause some real "lag" between "getting" and "displaying" the information. With no UpdateDivider, which would be the default UpdateDivider=1, you are sure of getting the result at the most one skin update after WebParser is finished.

Just be sure if you change it, that you adjust the UpdateRate accordingly. You have

UpdateRate=10
UpdateDivider=10

Now, and while that is ok, hitting the site every 100 seconds, you don't want to just remove UpdateDivider and be hitting the site every 10 seconds. You would want to change UpdateRate to 100.
Resike
Posts: 33
Joined: May 1st, 2015, 1:25 am

Re: Trailing Zeros

Post by Resike »

jsmorley wrote: I'm not sure you want to use OnUpdateAction on a WebParser measure. Use FinishAction. What is the point of having the measure cause actions on every update, when the value of the measure can only at the very best, change every UpdateRate?

The trouble with mixing UpdateRate and UpdateDivider on a WebParser measure goes back to what I posted a second ago about "threaded". You don't want to have WebParser finish getting the answer for you, and then wait Update X UpdateDivider milliseconds before you check back and use the information. In some (but not all) cases, using UpdateDivider with WebParser can cause some real "lag" between "getting" and "displaying" the information. With no UpdateDivider, which would be the default UpdateDivider=1, you are sure of getting the result at the most one skin update after WebParser is finished.

Just be sure if you change it, that you adjust the UpdateRate accordingly. You have

UpdateRate=10
UpdateDivider=10

Now, and while that is ok, hitting the site every 100 seconds, you don't want to just remove UpdateDivider and be hitting the site every 10 seconds. You would want to change UpdateRate to 100.
I have tried this, however it still skips the first initial parse tick:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[ParsePrice]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=http://finance.yahoo.com/echarts?s=eurusd=x
RegExp="(?siU).*<span class="time_rtq_ticker.*">.*>(.*)</span>"
StringIndex=1
UpdateRate=10
FinishAction=[!ShowMeter Graph1] [!UpdateMeter Graph1] [!Redraw]

[PriceAsNumber]
Measure=Calc
Formula=[ParsePrice]
DynamicVariables=1

[MeterResult]
Meter=String
MeasureName=PriceAsNumber
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,20
AntiAlias=1
NumOfDecimals=1

[Graph1]
Meter=Line
AutoScale=1
X=1
Y=20
W=28
H=14
MeasureName=PriceAsNumber
LineColor=faba00
UpdateDivider=3600
Hidden=1
I tought WebParser is handled dynamically and after it downloads a value from the site, each meter gets updated which using that parser.
Maybe it would be better just to save it's value to a variable and handle it dynamically?
Last edited by Resike on May 2nd, 2015, 10:11 pm, edited 1 time in total.