It is currently March 29th, 2024, 11:07 am

Check a measure value respect the last update

Get help with creating, editing & fixing problems with skins
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Check a measure value respect the last update

Post by mak_kawa »

Hi brax64

I don't actually understand the precious metals market...:-) But having tested your code, I noticed several points.

1. IfCondition expressions other than you have edited must be corrected. Probably;

Code: Select all

[CompareGoldChange]
IfCondition=([CompareGoldChange] > 0)
IfCondition2=([CompareGoldChange] = 0)
IfCondition3=([CompareGoldChange] < 0)
2. After the IfCondition evaluation, [CompareGoldChange] is continuously updated, so text color is back to grey as new value of #GoldChangePrevious# is evaluated. So, UpdateDivider=-1 has to be added. The measure should be updated after the [Site] measure is finished.
3. The comparison in [CompareGoldChange] doesn't work. Because... when this evaluation, value of [GoldChangeOld] is still zero (null). So some delay seems to be necessary.
So;

Code: Select all

[Site]
FinishAction=[!EnableMeasureGroup Child][!Delay 1000][!UpdateMeasure CompareGoldChange]
Probably, there is more smart way, but after these modification, your code does seem to work at least for me.
If I am misunderstanding/missing something, sorry.
Last edited by mak_kawa on August 31st, 2020, 2:40 am, edited 1 time in total.
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Check a measure value respect the last update

Post by brax64 »

mak_kawa wrote: August 31st, 2020, 12:13 am Hi brax64

I didn't actually understand the precious metals market...:-) But having tested your code, I noticed several points.
...
Hi mak_kawa

Did try your suggestions but is not working for me...
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5384
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Check a measure value respect the last update

Post by eclectic-tech »

brax64 wrote: August 31st, 2020, 1:56 am Hi mak_kawa

Did try your suggestions but is not working for me...
Besides mak_kawa's last suggestion, I believe you misunderstood, or overlooked mak_kawa's previous statement that said "you need to 'convert' the substituted STRING value (the substituted string without any comma) to a NUMBER by using it in a Calc measure"; you must do that because you can only use NUMBER values in IfCondition tests, not STRING values.

Something like this approach should work for any Web-parser STRING values containing commas.

Code: Select all

[GoldChange]
Measure=WebParser
URL=[SpotGold]
StringIndex=2
Substitute=",":""

[GoldChangeNUMBER]
Measure=Calc
Formula=[GoldChange]
DynamicVariables=1
IfCondition=([GoldChangeNUMBER]>#PreviousGoldPrice#)
IfTrueAction=[!SetVariable "GoldChange" "1"]
IfCondition2=([GoldChangeNUMBER]<#PreviousGoldPrice#)
IfTrueAction2=[!SetVariable "GoldChange" "-1"]
IfCondition3=([GoldChangeNUMBER]=#PreviousGoldPrice#)
IfTrueAction3=[!SetVariable "GoldChange" "0"]
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Check a measure value respect the last update

Post by brax64 »

eclectic-tech wrote: August 31st, 2020, 2:29 am Besides mak_kawa's last suggestion, I believe you misunderstood, or overlooked mak_kawa's previous statement that said "you need to 'convert' the substituted STRING value (the substituted string without any comma) to a NUMBER by using it in a Calc measure"; you must do that because you can only use NUMBER values in IfCondition tests, not STRING values.
...
Hi eclectic-tech,
Thank you very much for chime in!
Yes I'm totally aware about your statement, in fact I did drastically change approach and actually made the thing works this way:

Code: Select all

[GoldChangeNUMBER]
Measure=Calc
Formula=[GoldChange]
DynamicVariables=1
IfCondition=([GoldChangeNUMBER] > 0)
IfTrueAction=[!SetVariable GoldColor 0,255,0][!UpdateMeter Gold2][!Redraw]
IfCondition2=([GoldChangeNUMBER] = 0)
IfTrueAction2=[!SetVariable GoldColor #Color2#][!UpdateMeter Gold2][!Redraw]
IfCondition3=([GoldChangeNUMBER] < 0)
IfTrueAction3=[!SetVariable GoldColor 255,0,0][!UpdateMeter Gold2][!Redraw]
The [GoldChange] measure it's always less then 1000, so I don't need to get rid of the commas...
Don't know why I thrown myself in a rabbit's hole when I had in front of my eyes the whole time a way more simple solution...
Again, thank you very much to you and mak_kawa
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Check a measure value respect the last update

Post by mak_kawa »

Hi brax64

I have tested by an integrated (= not using @include for measures/meters) ini file with only "gold" part for simplification. And... it seems to work well to me. But, as I said, because I am not familiar to the presious metal market, I am not sure whether it is working well or not. :-)
BTW, I can't do evaluation on the actual site data, so I arbitrarily changed the value directly in Variables.inc.
Untitled-1.png

Code: Select all

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

@include=#@#Variables.inc

[Site]
Measure=WebParser
URL=#URL#
UpdateRate=#UpdateRate#
Flags=Resync | NoCookies
UserAgent=#UserAgent#
LogSubstringErrors=0
RegExp=(?siU)^(.*)$
StringIndex=1
FinishAction=[!EnableMeasureGroup Child][!Delay 1000][!UpdateMeasure CompareGoldChange]

[SpotGold]
Measure=WebParser
URL=[Site]
StringIndex=1
RegExp=(?siU)^.*>Spot Gold </a>.*nowrap>(.*)</td>.*nowrap>(.*)</td>.*nowrap>(.*)%</td>.*right'>(.*)</td>.*right'>(.*)</td>.*right'>(.*)</td>.*nowrap>(.*)</td>
Disabled=1
Group=Child

;============================================
;           Gold
;============================================

[GoldPrice]
Measure=WebParser
URL=[SpotGold]
StringIndex=1

[GoldChange]
Measure=WebParser
URL=[SpotGold]
StringIndex=2

[Gold%Change]
Measure=WebParser
URL=[SpotGold]
StringIndex=3

[GoldOpen]
Measure=WebParser
URL=[SpotGold]
StringIndex=4

[GoldHigh]
Measure=WebParser
URL=[SpotGold]
StringIndex=5

[GoldLow]
Measure=WebParser
URL=[SpotGold]
StringIndex=6

[GoldVolume]
Measure=WebParser
URL=[SpotGold]
StringIndex=7

[GoldChangeOld]
Measure=Calc
Formula=[GoldChange]
DynamicVariables=1
Group=Child
Disabled=1

[CompareGoldChange]
Measure=Calc
Formula=([GoldChangeOld]-#GoldChangePrevious#)
IfCondition=([CompareGoldChange] > 0)
IfTrueAction=[!SetVariable GoldColor 0,255,0][!SetVariable GoldChangePrevious [GoldChange]][!WriteKeyValue Variables GoldChangePrevious [GoldChange] #@#Variables.inc][!UpdateMeter *[!Redraw][!Log ">"]
IfCondition2=([CompareGoldChange] = 0)
IfTrueAction2=[!SetVariable GoldColor 155,155,155][!SetVariable GoldChangePrevious [GoldChange]][!WriteKeyValue Variables GoldChangePrevious [GoldChange] #@#Variables.inc][!UpdateMeter *][!Redraw][!Log "="]
IfCondition3=([CompareGoldChange] < 0)
IfTrueAction3=[!SetVariable GoldColor 255,0,0][!SetVariable GoldChangePrevious [GoldChange]][!WriteKeyValue Variables GoldChangePrevious [GoldChange] #@#Variables.inc][!UpdateMeter *][!Redraw][!Log "<"]
DynamicVariables=1
UpdateDivider=-1
Group=Child
Disabled=1

; ------------------ Meters

[BKGD]
Meter=Shape
Shape=Rectangle 1,2,546,84,10 | StrokeWidth 1 | Stroke Color 100,100,100,150 | Fill Color 20,20,20,150

[HeaderStyle]
FontFace=#ff#
FontSize=9
FontColor=#Color1#
StringAlign=Left
AntiAlias=1

[ValuesStyle]
FontFace=#ff#
FontSize=8
FontColor=155,155,155
StringAlign=Right
StringStyle=Italic
AntiAlias=1

;============================================
;           Header
;============================================

[MetalHeader]
Meter=String
MeterStyle=HeaderStyle
X=10
Y=10
Text=METAL

[PriceHeader]
Meter=String
MeterStyle=HeaderStyle
X=25R
Y=r
Text=PRICE oz t

[ChangeHeader]
Meter=String
MeterStyle=HeaderStyle
X=20R
Y=r
Text=CHANGE $

[Change%Header]
Meter=String
MeterStyle=HeaderStyle
X=15R
Y=r
Text=CHANGE %

[OpenHeader]
Meter=String
MeterStyle=HeaderStyle
X=25R
Y=r
Text=OPEN

[HighHeader]
Meter=String
MeterStyle=HeaderStyle
X=35R
Y=r
Text=HIGH

[LowHeader]
Meter=String
MeterStyle=HeaderStyle
X=35R
Y=r
Text=LOW

[VolHeader]
Meter=String
MeterStyle=HeaderStyle
X=25R
Y=r
Text=VOLUME

;============================================
;           Gold
;============================================

[Gold0]
Meter=String
MeterStyle=ValuesStyle
StringAlign=Left
FontColor=#MetallicGold#
X=10
Y=20r
Text=Gold

[Gold1]
Meter=String
MeasureName=GoldPrice
MeterStyle=ValuesStyle
FontColor=#MetallicGold#
X=95R
Y=r
Text=%1

[Gold2]
Meter=String
MeasureName=GoldChange
MeterStyle=ValuesStyle
FontColor=#GoldColor#
X=25R
Y=r
Text=%1
DynamicVariables=1

[Gold3]
Meter=String
MeasureName=Gold%Change
MeterStyle=ValuesStyle
FontColor=#GoldColor#
X=35R
Y=r
Text=%1
DynamicVariables=1

[Gold4]
Meter=String
MeasureName=GoldOpen
MeterStyle=ValuesStyle
X=60R
Y=r
Text=%1

[Gold5]
Meter=String
MeasureName=GoldHigh
MeterStyle=ValuesStyle
X=10R
Y=r
Text=%1

[Gold6]
Meter=String
MeasureName=GoldLow
MeterStyle=ValuesStyle
X=10R
Y=r
Text=%1

[Gold7]
Meter=String
MeasureName=GoldVolume
MeterStyle=ValuesStyle
X=-5R
Y=r
Text=%1
You do not have the required permissions to view the files attached to this post.
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Check a measure value respect the last update

Post by brax64 »

mak_kawa wrote: August 31st, 2020, 3:35 am Hi brax64

I have tested by an integrated (= not using @include for measures/meters) ini file with only "gold" part for simplification. And... it seems to work well to me. But, as I said, because I am not familiar to the presious metal market, I am not sure whether it is working well or not. :-)
BTW, I can't do evaluation on the actual site data, so I arbitrarily changed the value directly in Variables.inc.
...
Hi mak_kawa,

I'm really grateful for your effort; changing manually the variable will always work; I'm using it right now live and your code do not update the variable inside Variable.inc; also if you notice in your image, you got a negative and a no change values (green and gray), that's not correct, negative=red, no change=gray, positive=green
Changed completely my approach in a much simpler way and I got what I was looking for, see my replay to eclectic_tech below for the details.

Again, thank you very much for your help, really appreciated :rosegift: !!!
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Check a measure value respect the last update

Post by mak_kawa »

Hi brax64
you got a negative and a no change values (green and gray), that's not correct, negative=red, no change=gray, positive=green
Sorry, it's my bad presentation/explanation. For the results posted above, I modified the value of #GoldChangePrevious# in Variable.inc arbitrarily.

For example in the second image, assumed [GoldChange] is -3.40, so I set #GoldChangePrevious# in Variabls.inc to -5.40, so [CompareGoldChange] is positive and text color is green.
And in the third image I set #GoldChangePrevious# to -3.40, [CompareGoldChange] is zero, so text is grey.

That is, conditional function in the posted code seems to work well, at least as far as I see... But now I gave up. There is nothing further I can do...:-)
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Check a measure value respect the last update

Post by brax64 »

Hi all,

this thing is driving me nut... :?
I'm trying to compare the previous value of some measures [GoldPrice], [SilverPrice], [PlatinumPrice] and [PalladiumPrice] respect to the last updated one; comparing if the last value is higher, equal or lower then the previous one, then I'm setting options and variables...
Did applied the suggestions kindly made by eclectic_tech and mak_kawa, but still I'm getting bizarre results...
As you can see from the picture below, did log previous and last values but they are not correct and also i get the error
[GoldTick] - Calc: Syntax error only when i load/refresh the skin; during its normal cycle update no errors are generated.
Interesting enough the copied measures [SilverTick, [PlatinumTick] and [PalladiumTick] are not generating any error...
Anybody wanna try to help me with this mess? :oops:

Here my last version of the skin
SpotPrices_1.0.rmskin
Untitled.png
You do not have the required permissions to view the files attached to this post.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Check a measure value respect the last update

Post by mak_kawa »

Hi brax64

Your problems are really complicated for me, so I can't fully follow them.

But, one weird thing is...GoldPricePrevious=1969.12C:\Users\ecarp\Documents\Rainmeter\Skins\SpotPrices\@Resources\Variables.inc in the [Variables] section at the end of SpotPrices.ini. This overrides #GoldPricePrevious# in the Variables.inc, so syntax error in the formula Formula=([&GoldPriceNumber]-#GoldPricePrevious#) of the [GoldTick] section naturally occurs.

Again, if I am misunderstanding something, sorry.
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Check a measure value respect the last update

Post by brax64 »

mak_kawa wrote: September 1st, 2020, 2:45 am Hi brax64

Your problems are really complicated for me, so I can't fully follow them.

But, one weird thing is...GoldPricePrevious=1969.12C:\Users\ecarp\Documents\Rainmeter\Skins\SpotPrices\@Resources\Variables.inc in the [Variables] section at the end of SpotPrices.ini. This overrides #GoldPricePrevious# in the Variables.inc, so syntax error in the formula Formula=([&GoldPriceNumber]-#GoldPricePrevious#) of the [GoldTick] section naturally occurs.

Again, if I am misunderstanding something, sorry.
Man, you made my day! :thumbup:
Honestly, I don't even know how those 2 lines ended up at the end of the SpotPrices.ini
I was so focus messing around the Measure.inc that I never looked there...
Well as happy ending, having removed those 2 stupid lines everything's working as supposed to
I owe you a beer!!! :D