It is currently April 19th, 2024, 6:26 pm

Compare old variable with new

Get help with creating, editing & fixing problems with skins
User avatar
DeceptiveGmR
Posts: 5
Joined: July 21st, 2021, 3:56 am

Compare old variable with new

Post by DeceptiveGmR »

Hey all, so I have been going mad with trial and error trying to figure out how to compare and old value with new.

ie. Pulls prices with webparse then checks the new pulled price with the old to check if it's higher or lower.
I cannot get it to check before writing the new value. it keeps checking new vs. new.

I would post code, but I have tried so many ways I just don't know what to post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Compare old variable with new

Post by SilverAzide »

DeceptiveGmR wrote: September 3rd, 2021, 10:58 pm Hey all, so I have been going mad with trial and error trying to figure out how to compare and old value with new.

ie. Pulls prices with webparse then checks the new pulled price with the old to check if it's higher or lower.
I cannot get it to check before writing the new value. it keeps checking new vs. new.

I would post code, but I have tried so many ways I just don't know what to post.
It would help if you posted the skin, even a basic simplified one that shows what you are trying to do, so we can at least see how you are doing the comparison. Without it I have to ask a dumb question... after you retrieved the value, did you save it to a variable, so that you can compare old vs. new on the next update?
Gadgets Wiki GitHub More Gadgets...
User avatar
DeceptiveGmR
Posts: 5
Joined: July 21st, 2021, 3:56 am

Re: Compare old variable with new

Post by DeceptiveGmR »

SilverAzide wrote: September 3rd, 2021, 11:42 pm It would help if you posted the skin, even a basic simplified one that shows what you are trying to do, so we can at least see how you are doing the comparison. Without it I have to ask a dumb question... after you retrieved the value, did you save it to a variable, so that you can compare old vs. new on the next update?
First off, That is not a stupid question, completely reasonable.

Second; As I mentioned I have tried so many variations that I did not know where to start with an example AND I am new to rainmeter so I am a bit embarrassed to post my messy unorganized programming skills.

So basically I am using WebParse to pull crypto prices, % change, highs and lows from coinmarketcap and yes it is saving the prices as variables as well as putting them in a meter string.
The issue is, I cant seem to get it to tell me if the new pulled price is higher or lower then the previously set price variable. It sets the new price then just comes back equal to.

something like this:

Code: Select all

[CheckChangeBTC]
UpdateRate=3600
Measure=WebParser
URL=[get_btc]
StringIndex=2
Substitute="$":""
IfEqualValue=#BTC_CHANGE_PRICE#
IfEqualAction=[!SetVariable BTC_PRICE_CHANGE "Same"][!Log "Equal: #BTC_CHANGE_PRICE#"]
IfAboveValue=#BTC_CHANGE_PRICE#
IfAboveAction=[!SetVariable BTC_PRICE_CHANGE "Higher"][!Log "Higher: #BTC_CHANGE_PRICE#"]
IfBelowValue=#BTC_CHANGE_PRICE#
IfBelowAction=[!SetVariable BTC_PRICE_CHANGE "Lower"][!Log "Lower: #BTC_CHANGE_PRICE#"]
DynamicVariables=1
Last edited by balala on September 4th, 2021, 9:33 am, edited 1 time in total.
Reason: Please use <code> tags whenever are posting code snippets. It's the </> button.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Compare old variable with new

Post by SilverAzide »

DeceptiveGmR wrote: September 4th, 2021, 4:01 am First off, That is not a stupid question, completely reasonable.

Second; As I mentioned I have tried so many variations that I did not know where to start with an example AND I am new to rainmeter so I am a bit embarrassed to post my messy unorganized programming skills.

So basically I am using WebParse to pull crypto prices, % change, highs and lows from coinmarketcap and yes it is saving the prices as variables as well as putting them in a meter string.
The issue is, I cant seem to get it to tell me if the new pulled price is higher or lower then the previously set price variable. It sets the new price then just comes back equal to.
Aha, now I see... The problem is you are comparing the price to a variable BTC_CHANGE_PRICE, but using a !SetVariable bang to set a variable BTC_PRICE_CHANGE. Is BTC_CHANGE_PRICE being set someplace else?

Also, one thing you have to be careful of is that Rainmeter can't do string comparisons, except with IfMatch actions only. Sometimes WebParser measures return strings instead of numbers (even though it might look like a number), so you have to make adjustments to your comparisons. For example, try IfCondition=(CheckChangeBTC = #BTC_CHANGE_PRICE#) or even IfCondition=([CheckChangeBTC:] = #BTC_CHANGE_PRICE#) to see if it makes a difference.
Gadgets Wiki GitHub More Gadgets...
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Compare old variable with new

Post by death.crafter »

SilverAzide wrote: September 4th, 2021, 5:28 am Also, one thing you have to be careful of is that Rainmeter can't do string comparisons, except with IfMatch actions only. Sometimes WebParser measures return strings instead of numbers (even though it might look like a number), so you have to make adjustments to your comparisons. For example, try IfCondition=(CheckChangeBTC = #BTC_CHANGE_PRICE#) or even IfCondition=([CheckChangeBTC:] = #BTC_CHANGE_PRICE#) to see if it makes a difference.
IfConditions use number value of a measure. So, both methods will wield the same result.
I think
from the Realm of Death
User avatar
DeceptiveGmR
Posts: 5
Joined: July 21st, 2021, 3:56 am

Re: Compare old variable with new

Post by DeceptiveGmR »

So There was a typo with the variable it is BTC_PRICE_CHANGE. either way this helps tremendously!
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Compare old variable with new

Post by balala »

DeceptiveGmR wrote: September 3rd, 2021, 10:58 pm Hey all, so I have been going mad with trial and error trying to figure out how to compare and old value with new.
Asking the same as SilverAzide: post a working code please, because the code of the [CheckChangeBTC] measure is completely useless. Not having the parent measure (and maybe even other needed measures), we can't get it working, however at least in some cases, there are some possibilities to get what you want.
User avatar
DeceptiveGmR
Posts: 5
Joined: July 21st, 2021, 3:56 am

Re: Compare old variable with new

Post by DeceptiveGmR »

Ok so this is basically what I have. the last measure seems to work partially.
It only works if I completely refresh the skin. It updates all the prices correctly, but doesn't check the if condition except on a refresh.

Code: Select all

; Recently had to add another measure to make it download the page. it was working without it,
; but after about a week it seems they blocked webparse requests so downloading the page is the only thing I could get to work.

[Download_page_BTC]
UpdateRate=3600
Group=get_prices
Measure=Plugin
Plugin=WebParser
Download=1
URL=https://coinmarketcap.com/currencies/bitcoin/
DownloadFile=btc.txt

[get_btc]
UpdateRate=3600
Group=get_prices
Measure=WebParser
URL=#parse_file#btc.txt
RegExp=(?siU)</span>ETH Gas<!-- -->.*<a>(.*)<span .*>.*<div class="priceValue ">(.*)</div>.*<span class="(.*)">.*</span>(.*)</span>.*<span .*>.*Low.*</span><span .*>(.*)</span>.*<span .*>High.*</span><span .*>(.*)</span>.*<span>Price: .*</span><div>(.*)</div>.*<img src="(.*)".*>

; I removed the other StringIndex measures since they are all fine.
; Only included the one in question

[MeasureBTC]
UpdateRate=3600
Measure=WebParser
URL=[get_btc]
StringIndex=2
Substitute="$":"",",":""
IfCondition=([MeasureBTC] => #BTC_OLD_PRICE#)
IfTrueAction=[!Log "Higher: #BTC_OLD_PRICE#"][ ## the rest of my if true/higher bangs ## ]
IfFalseAction=[!Log "Lower: #BTC_OLD_PRICE#"][ ## the rest of my if false/lower bangs ## ]
OnChangeAction=[!SetVariable BTC_OLD_PRICE [MeasureBTC]]
DynamicVariables=1
It seems to check the condition twice. here is my log window. also it always says lower, even when the value is higher.

Code: Select all

Log Window:

Lower: 49846.35 (CryptoPrices_Large\CryptoPrices_Large.ini)
Syntax error: IfCondition=(0.0000000000 > #BTC_CHANGE_PRICE#) (CryptoPrices_Large\CryptoPrices_Large.ini - [CheckChangeBTC])
Sorry I did not post this before.

I am very novice with rainmeter, still scouring the documentation and learning. Everything I have built so far works, except this. (you should see the whole skin, it's not very efficient, need to clean it up to speed things up. I have calls to measures that call other measures way to much. but trial and error has been working so far. Once I can get this working I will clean it all up neat.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Compare old variable with new

Post by balala »

DeceptiveGmR wrote: September 5th, 2021, 5:53 am Ok so this is basically what I have. the last measure seems to work partially.
It only works if I completely refresh the skin. It updates all the prices correctly, but doesn't check the if condition except on a refresh.
First note a mistake in your code: the inequality sign (=>) in the IfCondition option of the [MeasureBTC] measure is incorrect. Rainmeter doesn't work if it is used this way. Correctly it is >= and accordingly the option should be IfCondition=([MeasureBTC] >= #BTC_OLD_PRICE#). But fixing this is not enough.
Try the followings: first remove (or at least comment out) the IfCondition, IfTrueAction, IfFalseAction options of the [MeasureBTC] measure. Replace the OnChangeAction option of the same measure with the following one: OnChangeAction=[!UpdateMeasure "MeasureCompare"][!SetVariable BTC_OLD_PRICE "[MeasureBTC]"].
So far there is no [MeasureCompare] measure, which is used in the above option. So add it to the code:

Code: Select all

[MeasureCompare]
Measure=Calc
Formula=( [MeasureBTC] - #BTC_OLD_PRICE# )
DynamicVariables=1
IfCondition=(#CURRENTSECTION#>0)
IfTrueAction=[!Log "Higher: #BTC_OLD_PRICE#"][ ## the rest of my if true/higher bangs ## ]
IfCondition2=(#CURRENTSECTION#<0)
IfTrueAction2=[!Log "Lower: #BTC_OLD_PRICE#"][ ## the rest of my if false/lower bangs ## ]
IfCondition3=(#CURRENTSECTION#=0)
IfTrueAction3=[!Log "Not changing: #BTC_OLD_PRICE#"][ ## the rest of my if false/lower bangs ## ]
UpdateDivider=-1
Note that the change is not properly shown when you refresh / activate the skin, only on the first update of the WebParser measure.

And there is one more thing I'd definitely do. I'd modify the UpdateRate option of the [get_btc] measure to something like UpdateRate=86400 (yep, this is not a mistake, it really is a day!). Would also add a FinishAction=[!CommandMeasure "get_btc" "Update"] option to the [Download_page_BTC] measure, because this way you can ensure that the [get_btc] measure is updated right when the [Download_page_BTC] measure downloads the file.
Even if I didn't try yet, I doubt there would be needed to download the file and parse it. Instead I probably would try to parse the information directly from the first site, without involving the downloaded btc.txt. but this is another story. Please try the above solution and let me know if does its job.
User avatar
DeceptiveGmR
Posts: 5
Joined: July 21st, 2021, 3:56 am

Re: Compare old variable with new

Post by DeceptiveGmR »

balala wrote: September 5th, 2021, 12:52 pm And there is one more thing I'd definitely do. I'd modify the UpdateRate option of the [get_btc] measure to something like UpdateRate=86400 (yep, this is not a mistake, it really is a day!). Would also add a FinishAction=[!CommandMeasure "get_btc" "Update"] option to the [Download_page_BTC] measure, because this way you can ensure that the [get_btc] measure is updated right when the [Download_page_BTC] measure downloads the file.
Even if I didn't try yet, I doubt there would be needed to download the file and parse it. Instead I probably would try to parse the information directly from the first site, without involving the downloaded btc.txt. but this is another story. Please try the above solution and let me know if does its job.
Thanks a lot, this did not work perfectly, having an issue with [MeasureCompare] not always working, or only working half the time it updates. even when there is a change in value. but for the most part this helped tremendously.

I was parsing directly from the site, but it stopped working and downloading first was the only thing that worked again afterwards.

My apologies for the delay in the response, been out of town. I appreciate it all the help, wonderful community!