It is currently December 6th, 2022, 1:16 pm

Text meter: Limit number of digits displayed with IfCondition >10

Get help with creating, editing & fixing problems with skins
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by emp00 »

Wait, I just saw something: With the above code this error is logged:

Extra operation: IfCondition=(>=10) (NS2Win (Nightscout BG Monitor)\NS2Win.ini - [MeasureIOB])

What does this mean? Does this help to fix the issue?

I just tried to change
"IfCondition=([MeasureIOB]>=10)"
to
"IfCondition=(MeasureIOB>=10)"

--> this eliminates the error message, but the effect is the same as above. The NumOfDecimals bang simply does not work here.

One more tweak I tried:
IfTrueAction=[!SetOption MeterIOB NumOfDecimals "0"][!UpdateMeter MeterIOB][!Redraw]
IfFalseAction=[!SetOption MeterIOB NumOfDecimals "1"][!UpdateMeter MeterIOB][!Redraw]

--> no change... meter always the two digits currently stored in [MeterIOB]. No decimals are cut at all.
User avatar
balala
Rainmeter Sage
Posts: 14765
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by balala »

emp00 wrote: November 7th, 2022, 9:16 pm Extra operation: IfCondition=(>=10) (NS2Win (Nightscout BG Monitor)\NS2Win.ini - [MeasureIOB])

What does this mean? Does this help to fix the issue?
No, this is not a problem. You get this message because when you refresh the skin, the parent WebParser measure needs a little bit of time to get the value. But since its child measure has an IfCondition set, the measure tries to evaluate the IfCondition immediately. But since there is no value yet, the IfCondition is not numeric, which leads to the error message. There is a simple solution, but this is not a problem which prevents the setting to be executed.
emp00 wrote: November 7th, 2022, 9:03 pm Are you sure the IfCondition is really executed in a WebParser measure like that? I have a feeling this is the reason...
I was, however, am not anymore :o . This needs a little bit of study, but unfortunately setting the NumOfDecimals with IfCondition on a WebParser measure seems not to be working. Didn't know about this detail, it surprised me extremely, but definitely will try to figure out what1s going on here (assuming someone won't have a solution in meantime).
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by emp00 »

Strange! I just checked my skin and found another WebParser measure for which IfConditions work perfectly:

Code: Select all

[MeasureGlucose]
; Last received nightscout glucose value in mg/dl
Measure=WebParser
URL=[MeasureSite]
StringIndex=2
; ***Change BG Color to Red
IfCondition=MeasureGlucose < #LowGlucoseAlert#
IfTrueAction=[!SetOption meterGlucose FontColor 255,0,0]
; ***Change BG Color to Orange
IfCondition2=MeasureGlucose > #HighGlucoseAlert#
IfTrueAction2=[!SetOption meterGlucose FontColor 255,155,0]
; ***Change BG Color to Colorful-Gradient @100
IfCondition3=MeasureGlucose = 100
IfTrueAction3=[!SetOption meterGlucose InlineSetting "GradientColor | 180 | 255,0,0,255 ; 0.0 | 0,255,0,255 ; 0.5 | 0,0,255,255 ; 1.0"]
; ***Change BG Color to White if "in-range" AND not @100
IfCondition4=((MeasureGlucose >= #LowGlucoseAlert#) && (MeasureGlucose <= #HighGlucoseAlert#) && (MeasureGlucose <> 100))
IfTrueAction4=[!SetOption meterGlucose FontColor 250,250,250][!SetOption meterGlucose InlineSetting ""]
OnUpdateAction=[!UpdateMeter meterGlucose][!Redraw]
So the principle works, I'm 100% sure for [MeasureGlucose], see code below, since I tested/optimized this heavily :-)

So, I guess, the NumOfDecimals setting seems to be the problem..?? Are we sure, that my code in the meter

Code: Select all

Text="%1"
is not the issue? I also tried

Code: Select all

Text=%1
but all the same effect...

One more variant I tried, including the OnUpdateAction --> also no effect:

Code: Select all

[MeasureIOB]
; IOB = Insulin on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=7
IfCondition=(MeasureIOB<10)
IfTrueAction=[!SetOption MeterIOB NumOfDecimals "1"]
IfFalseAction=[!SetOption MeterIOB NumOfDecimals "0"]
OnUpdateAction=[!UpdateMeter MeterIOB][!Redraw]
User avatar
balala
Rainmeter Sage
Posts: 14765
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by balala »

The only solution I found so far is to add a Calc measure, which takes the value of the [MeasureIOB] measure and sets the number of decimals accordingly:

Code: Select all

[MeasureNum]
Measure=Calc
Formula=[MeasureIOB]
IfCondition=(MeasureNum>=10)
IfTrueAction=[!SetOption MeterIOB NumOfDecimals "0"][!UpdateMeter "MeterIOB"][!Redraw]
IfFalseAction=[!SetOption MeterIOB NumOfDecimals "1"][!UpdateMeter "MeterIOB"][!Redraw]
DynamicVariables=1
Further study required, however only tomorrow from my part...
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by emp00 »

I can confirm, that NumOfDecimals is the problem here! Even when "hardcoding" this command directly into the meter, it still shows e.g. "11.89" instead of "12" (MeasureIOB = 11.89, number and string). I triend NumOfDecimals=1, =3 ... all having no effect. So now it's clear where the problem is coming from... But what to do?

Code: Select all

[MeterIOB]
; Meter "Insulin on Board"
Meter=String
MeterStyle=StyleRightText
FontSize=8
MeasureName=MeasureIOB
X=138
Y=26
W=40
H=21
; Adding ":1" ensures display of 1 decimal, also for X.0 otherwise giving X !
;Text=[&MeasureIOB:1]
NumOfDecimals=0
Text=%1
DynamicVariables=1
User avatar
SilverAzide
Rainmeter Sage
Posts: 2178
Joined: March 23rd, 2015, 5:26 pm

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by SilverAzide »

emp00 wrote: November 7th, 2022, 10:04 pm I can confirm, that NumOfDecimals is the problem here! Even when "hardcoding" this command directly into the meter, it still shows e.g. "11.89" instead of "12" (MeasureIOB = 11.89, number and string). I triend NumOfDecimals=1, =3 ... all having no effect. So now it's clear where the problem is coming from... But what to do?
The reason for this oddness is a quirk in Rainmeter. The value coming from WebParser is actually a string ("11.89", not 11.89). And when you use MeasureName=MeasureIOB in your meter, it is fetching the string value of the measure, not the number value. I'm not sure why xenium's suggestion didn't work (seems like it should have), but balala's suggestion should definitely work (be sure to change MeasureName to MeasureName=MeasureNum), as the value will be a real number that NumOfDecimals can deal with.
Gadgets Wiki GitHub More Gadgets...
User avatar
balala
Rainmeter Sage
Posts: 14765
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by balala »

SilverAzide wrote: November 7th, 2022, 10:28 pm (be sure to change MeasureName to MeasureName=MeasureNum), as the value will be a real number that NumOfDecimals can deal with.
Good point! Sorry, I forgot to specify this. My bad...
emp00 wrote: November 7th, 2022, 10:04 pm But what to do?
Do this:

Code: Select all

...

[MeasureIOB]
; IOB = Insulin on Board
Measure=WebParser
URL=[MeasureSite]
StringIndex=7

[MeasureNum]
Measure=Calc
Formula=[MeasureIOB]
IfCondition=(MeasureNum>=10)
IfTrueAction=[!SetOption MeterIOB NumOfDecimals "0"][!UpdateMeter "MeterIOB"][!Redraw]
IfFalseAction=[!SetOption MeterIOB NumOfDecimals "1"][!UpdateMeter "MeterIOB"][!Redraw]
DynamicVariables=1

[MeterIOB]
; Meter "Insulin on Board"
Meter=String
MeterStyle=StyleRightText
FontSize=8
MeasureName=MeasureNum
X=138
Y=26
W=40
H=21
; Adding ":1" ensures display of 1 decimal, also for X.0 otherwise giving X !
Text=%1
NumOfDecimals=0
Text=%1
emp00
Posts: 32
Joined: October 7th, 2022, 8:08 pm

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by emp00 »

@balala / @SilverAzide: THANKS, now it finally works. :thumbup: :great: :thumbup:

Constructively meant critics and proposal (to whom should this be adressed?):
  • Creating an extra Calc measure only for converting a string (which is even shown as a regular number in the measure list tab and there was no error message using the IfCondition ==> how should I possibly have known?!) is - well - not very elegant. With this workaround we have additional code, an additional redundant measure, lots of room for mistakes and many partially frustrated users, at least one = me (yesterday)
  • Honestly - there should be a Rainmeter function such as MeasureName=StringToNumber([Measure]) to do this rather "simple conversion job" in one line, directly in the existing e.g. Webparser measure
For me it's a learning and I feel happy now - but all those discussions and our time could have been saved with a "small" (?) code addition in Rainmeter. Maybe there are very good historical reasons for this - but it's really, really "special" to say it in nice words.

THANKS so much for helping me through this - I could never, ever have done this without you (YOU did it!) :oops:
User avatar
balala
Rainmeter Sage
Posts: 14765
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Text meter: Limit number of digits displayed with IfCondition >10

Post by balala »

emp00 wrote: November 8th, 2022, 8:13 pm
  • Creating an extra Calc measure only for converting a string (which is even shown as a regular number in the measure list tab and there was no error message using the IfCondition ==> how should I possibly have known?!) is - well - not very elegant. With this workaround we have additional code, an additional redundant measure, lots of room for mistakes and many partially frustrated users, at least one = me (yesterday)
  • Honestly - there should be a Rainmeter function such as MeasureName=StringToNumber([Measure]) to do this rather "simple conversion job" in one line, directly in the existing e.g. Webparser measure
Sorry, I have no other / better solution.
emp00 wrote: November 8th, 2022, 8:13 pm For me it's a learning and I feel happy now - but all those discussions and our time could have been saved with a "small" (?) code addition in Rainmeter. Maybe there are very good historical reasons for this - but it's really, really "special" to say it in nice words.
Maybe post a request in the Bugs & Feature Suggestions section, if you think it'd be needed.
emp00 wrote: November 8th, 2022, 8:13 pm I could never, ever have done this without you (YOU did it!) :oops:
No, we (or at least me for sure) didn't do it. You did it, with a little bit of help from our / my side.