It is currently April 3rd, 2020, 11:04 am

Help with CALC

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

Help with CALC

Post by ms310 »

Hi - I am trying to do some match with values I am fetching from WebParser. The WebParser values come through to my skin fine but the CALC measures are only returning ZERO.

Code: Select all

[MeasureOverall]
Measure=WebParser
URL=https://www.worldometers.info/coronavirus/
RegExp=(?siU)<tbody>.*<td>.*</td>.*<td>(.*)</td>.*<td>(.*)</td>.*<td>(.*)</td>.*
StringIndex=1
UpdateDivider=7200
Format=Dec

[MeasureDeaths]
Measure=WebParser
URL=[MeasureOverall]
StringIndex=2
Format=Dec

[MeasureRecovered]
Measure=WebParser
URL=[MeasureOverall]
StringIndex=3
Format=Dec

[percentDeaths]
Measure=Calc
Formula=MeasureDeaths/MeasureOverall
DynamicVariables=1

[percentRecovered]
Measure=Calc
Formula=MeasureRecovered/MeasureOverall
DynamicVariables=1
Thanks for any help and guidance!
User avatar
balala
Rainmeter Sage
Posts: 10034
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with CALC

Post by balala »

ms310 wrote:
March 23rd, 2020, 7:53 am
Hi - I am trying to do some match with values I am fetching from WebParser. The WebParser values come through to my skin fine but the CALC measures are only returning ZERO.
You have to do two things:
  • Use the WebParser measure name into the Formula options of the Calc measures as section variables:

    Code: Select all

    [percentDeaths]
    ...
    Formula=[MeasureDeaths]/[MeasureOverall]
    ...
    
    [percentRecovered]
    ...
    Formula=[MeasureRecovered]/[MeasureOverall]
    ...
  • The decimals numbers provided on the site are using decimal comma, not dot. But Rainmeter uses dot as decimal separator. So add the Substitute=",":"." option to all WebParser measures ([MeasureOverall], [MeasureDeaths] and [MeasureRecovered]).
ms310
Posts: 183
Joined: April 1st, 2015, 7:16 am

Re: Help with CALC

Post by ms310 »

balala wrote:
March 23rd, 2020, 8:21 am
You have to do two things:
  • Use the WebParser measure name into the Formula options of the Calc measures as section variables:

    Code: Select all

    [percentDeaths]
    ...
    Formula=[MeasureDeaths]/[MeasureOverall]
    ...
    
    [percentRecovered]
    ...
    Formula=[MeasureRecovered]/[MeasureOverall]
    ...
  • The decimals numbers provided on the site are using decimal comma, not dot. But Rainmeter uses dot as decimal separator. So add the Substitute=",":"." option to all WebParser measures ([MeasureOverall], [MeasureDeaths] and [MeasureRecovered]).
Thank you as usual Balala.

The values from the website I am gathering are as such - they are 341,000 - its not a decimal, its three hundred forty one thousand.

Code: Select all

<tbody>
                        <tr class="total_row">
                            <td><strong>Total:</strong></td>
                            <td>341,526</td>
                            <td style="background-color:#FFEEAA; color:#000;">4,096</td>
                            <td>14,747</td>
                            <td style="background-color:red; color:#fff">109</td>
                            <td>99,040</td>
                            <td>227,739</td>
                            <td>10,560</td>
                            <td>43.8</td>
                        </tr>
                    </tbody>
Using this to display the values after your changes I am still getting Total (0-0):

Code: Select all

[mTotalLabel]
Meter=String
MeasureName=percentDeaths
MeasureName2=percentRecovered
X=0
Y=30
FontSize=#FontS#
FontWeight=700
FontColor=#LabelColor#
Text=Total (%1-%2)
DynamicVariables=1
I've uploaded my work in progress here - with some tweaking its still not working but values of 14,751 and 14751 (with and without substitute) the CALC measure is chopping off the values to the first two digits.
CoronaCounter_.rmskin
You do not have the required permissions to view the files attached to this post.
mak_kawa
Posts: 554
Joined: December 30th, 2015, 9:47 am

Re: Help with CALC

Post by mak_kawa »

The reasons are:
1. Substitute option has to be Substitute=",":"".
2. You have missed NumOfDecimals=x option in the [mTotalLabel] meter.Default value of the NumOfDecimals is 0, so 0.04318 and 0.28999 are both displayd as 0.

Following code works well for me.

Code: Select all

[MeasureOverall]
Measure=WebParser
URL=https://www.worldometers.info/coronavirus/
RegExp=(?siU)<tbody>.*<td>.*</td>.*<td>(.*)</td>.*<td>(.*)</td>.*<td>(.*)</td>.*
StringIndex=1
UpdateDivider=7200
Substitute=",":""
;Format=Dec

[MeasureDeaths]
Measure=WebParser
URL=[MeasureOverall]
StringIndex=2
;Format=Dec
Substitute=",":""

[MeasureRecovered]
Measure=WebParser
URL=[MeasureOverall]
StringIndex=3
;Format=Dec
Substitute=",":""

[percentDeaths]
Measure=Calc
Formula=[MeasureDeaths]/[MeasureOverall]
DynamicVariables=1

[percentRecovered]
Measure=Calc
Formula=[MeasureRecovered]/[MeasureOverall]
DynamicVariables=1

[mTotalLabel]
Meter=String
MeasureName=percentDeaths
MeasureName2=percentRecovered
X=0
Y=30
FontWeight=700
NumOfDecimals=5
Text=Total (%1-%2)
DynamicVariables=1
Ps. The WebParser measure has no such option as Format=Dec, I think.

EDIT: you have already set Substitute=",":"" and removed Format=Dec from your code, sorry for my overlook.
ms310
Posts: 183
Joined: April 1st, 2015, 7:16 am

Re: Help with CALC

Post by ms310 »

Thank you both.

For formatting I would like to keep the original values with a comma - so I guess I can just have two MEASURES - one from the WebParser and then another one that removes the comma.

Thanks to you both. Now to work on creating a BAR GRAPH with this percentage!
User avatar
balala
Rainmeter Sage
Posts: 10034
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with CALC

Post by balala »

ms310 wrote:
March 23rd, 2020, 11:09 am
For formatting I would like to keep the original values with a comma - so I guess I can just have two MEASURES - one from the WebParser and then another one that removes the comma.
Yes, this is the best approach in such a case.
Glad if you got it working well.
ms310
Posts: 183
Joined: April 1st, 2015, 7:16 am

Re: Help with CALC

Post by ms310 »

Hi guys - sorry - one more issue - shouldn't this return the appropriate value?

Code: Select all

[MeasureOverall]
Measure=WebParser
URL=https://www.worldometers.info/coronavirus/
RegExp=(?siU)<tbody>.*<td>.*</td>.*<td>(.*)</td>.*<td>(.*)</td>.*<td>(.*)</td>.*
StringIndex=1
UpdateDivider=7200

[MeasureDeaths]
Measure=WebParser
URL=[MeasureOverall]
StringIndex=2

[decOverall]
Measure=Calc
Formula=[MeasureOverall]
Substitute=",":""
DynamicVariables=1

[decDeaths]
Measure=Calc
Formula=[MeasureDeaths]
Substitute=",":""
DynamicVariables=1

[percentDeaths]
Measure=Calc
Formula=[decDeaths]/[decOverall]
DynamicVariables=1
For some reason this is still returning 0 - can you see my simple mistakes here?
mak_kawa
Posts: 554
Joined: December 30th, 2015, 9:47 am

Re: Help with CALC

Post by mak_kawa »

You are missing Substitute=",":"" in the measures [MeasureOverall] and [MeasureDeaths], so syntax errors have occurred in [decOverall] and [decDeaths]. Substitute=",":"" is not necessary in these two Calc measures.
ms310
Posts: 183
Joined: April 1st, 2015, 7:16 am

Re: Help with CALC

Post by ms310 »

Thanks - I have sorted it out. I am keeping display measures with the comma and then creating a String measure to hold the value without commas for calculations.
2020-03-23_20h59_43.png
This simple skin uses Chameleon to make "most" of the colors adapt to the image below the skin.
CoronaCounter_.rmskin
You do not have the required permissions to view the files attached to this post.
mak_kawa
Posts: 554
Joined: December 30th, 2015, 9:47 am

Re: Help with CALC

Post by mak_kawa »

Really terrifying values, especially Deaths %...