It is currently March 29th, 2024, 12:42 am

Calc measure 0 (zero), avoid

Get help with installing and using Rainmeter.
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Calc measure 0 (zero), avoid

Post by pul53dr1v3r »

by default, a Calc measure will return 0 if measure used by the Calc measure doesn't give a number value. But it makes me a problem and i want that, if the parent measure doesn't return a number value (is empty), that the calc doesn't return the 0 but to be empty or to use sth like "--" and when the parent measure have "0" as a number value, then the calc should have return it.
So, a simple Substitution like "0":"--" won't help.
In many cases 0 means "nothing", while as for temperature, it's a real value.
Last edited by pul53dr1v3r on December 4th, 2019, 2:52 pm, edited 1 time in total.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Calc measure 0 (zero), avoid

Post by mak_kawa »

This may be an unsmart solution....But anyway, how about show result simply via variable? Like this;

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=192,192,192,192

[Variables]
ShowString=""

[ParentMeasure]
Measure=String
;String=""
;String="n/a"
String="0"
;String="18"
IfMatchMode=1
IfMatch=[0-9]
IfMatchAction=[!SetVariable ShowString [ChildCalc:0]]
IfNotMatchAction=[!SetVariable ShowString [ParentMeasure]]
DynamicVariables=1

[ChildCalc]
Measure=Calc
Formula=([ParentMeasure]-32)*5/9
DynamicVariables=1

[meterParentMeasure]
Meter=String
MeasureName=ParentMeasure
X=5
Y=5
Text=Original: %1

[meterChildCalc]
Meter=String
MeasureName=ChildCalc
X=5
Y=20
Text=Child: %1

[meterShowString]
Meter=String
X=5
Y=35
Text=String: #ShowString#
DynamicVariables=1
Untitled-2.png
Probably somone here will provide more smart solution.:-)
Also, If I am misunderstanding your aim, sorry.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Calc measure 0 (zero), avoid

Post by jsmorley »

Pul53dr1v3r wrote: November 29th, 2019, 11:05 pm by default, a Calc measure will return 0 if measure used by the Calc measure doesn't give a number value. But it makes me a problem and i want that, if the parent measure doesn't return a number value (is empty), that the calc doesn't return the 0 but to be empty or to use sth like "--" and when the parent measure have "0" as a number value, then the calc should have return it.
So, a simple Substitution like "0":"--" won't help.
In many cases 0 means "nothing", while as for temperature, it's a real value.

Code: Select all

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

[Variables]

[MeasureString]
Measure=String
;String=""
;String=0
String=47
IfMatch=^$
IfMatchAction=[!SetOption MeasureCalc Substitute """0":"--"""]
IfNotMatchAction=[!SetOption MeasureCalc Substitute ""]

[MeasureCalc]
Measure=Calc
Formula=MeasureString

[MeterCalc]
Meter=String
MeasureName=MeasureCalc
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
So if the measure being referenced in the Calc measure (I'm not thrilled about using "parent" here) has an empty ^$ string value (nothing can have an empty number value) then it will set the Substitute on the Calc measure to replace the derived number value of "0" with "--". If the measure is not an empty string, the Calc measure will return whatever numeric value the measure has, even if that value is actually properly zero.

Unlike IfCondition, IfMatch must be on the measure in question, as it uses the value of the measure it resides on to match "with".

You need to use """magic quotes""" on the parameter to set the Substitute, as it begins and ends with a "quote".

Again, NOTHING (no measure) can have an empty number value. That is just not possible.

I don't think I would test FOR a number, as any IfMatch you use will need to be quite complicated to handle possible negative numbers and fractions. It's doable, but I think it is better to test for FOR the empty string, which is simple and unambiguous.


If you really need to test for "N/A" or "ERROR" or some other string that for your purposes has a meaning of "none", then use more conditions on the IfMatch to explicitly test for those. Just saying "is there a number anywhere in the string?" is not particularly useful in my view. It might work in this particular case, but it's lazy logic...

Code: Select all

[MeasureString]
Measure=String
;String=""
;String=0
;String=n/a
;String=Error
String=47
IfMatch=(?i)^$|N/A|ERROR
IfMatchAction=[!SetOption MeasureCalc Substitute """0":"--"""]
IfNotMatchAction=[!SetOption MeasureCalc Substitute ""]
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Calc measure 0 (zero), avoid

Post by mak_kawa »

As always, jsmorley is smart and powerful (far more than me :-) ).
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Calc measure 0 (zero), avoid

Post by jsmorley »

mak_kawa wrote: November 30th, 2019, 3:30 am As always, jsmorley is smart and powerful (far more than me :-) ).
Meh, you were on the right track. I just tweaked it a bit.
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Calc measure 0 (zero), avoid

Post by pul53dr1v3r »

[/quote]
mak_kawa wrote: November 30th, 2019, 12:27 am
Hi mak.
i don't agree. Any solution that works is smart. Isn't even a workable Nokia 3310 better than a Galay S10 that's went off. ;) But your solution is much more of it.
Thank you! And you'll probably agree that it have a bit more meters than it should, but it doesn't hurt anyway. :thumbup:
This would be my approach (after i turned my brain on and saw your method):

Code: Select all

[Variables]
Unit=0

[ParentMeasure]
...
IfMatch=^$
IfMatchAction=[!SetOption "meterShowString" "Text" "--"]
IfNotMatchAction=[!SetOption "meterShowString" "Text" "%1"]

[ChildCalc]
Measure=Calc
Formula=((#Unit#=0)?([ParentMeasure]-32)*5/9 : [ParentMeasure])
DynamicVariables=1

[meterShowString]
Meter=String
MeasureName=ChildCalc
X=5
Y=35
DynamicVariables=1
jsmorley wrote: November 30th, 2019, 12:51 am
oh, thank you for all that explanations. :thumbup:

Your approach will work if there is no any additional calculation in the formula of the Calc measure. But if there is, it will show the calculated value, no matter if the parent measure have any number value or not.
You didn't think of it.

Code: Select all

[MeasureCalc]
Measure=Calc
Formula=(MeasureString+5)
so in the situation above there will be a number valul (5 in this case) even if the parent measure doesn't have any numebr.
It would be a great approach if the calculations could be "ignored" when the parent measure is "empty" (of number values).
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Calc measure 0 (zero), avoid

Post by mak_kawa »

Hi Pul53dr1v3r

All approaches in this forum are always useful/helpful for me. And I know there would be many approaches for one single aim.:-)

Anyway, my IfMatch= expression in above post was really "loose". If input string includes both digits and non-digit characters like "Tokyo2020", this skin did not work as intended.
This, possibly, should be IfMatch=^\d+\.?\d*$ instead of too simple IfMatch=[0-9]. This RegExp works for digits having decimals, I expect.
Honestly, the world of regular expression is too deep for me. I can't see into its depth, at least so far. :-)

Further, although this doesn't affect the result, when the input string is not only digits, "Calc *** is unknown" error occurs in [ChildCalc] measure.
To avoid this error, [ChildCalc] measure should be disabled at startup and [!EnableMeasure ChildCalc] only when above IfMatch is true.
Last edited by mak_kawa on December 1st, 2019, 10:48 am, edited 1 time in total.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Calc measure 0 (zero), avoid

Post by FreeRaider »

I usually use a FinishAction in the parent measure if it is a webparser measure.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Calc measure 0 (zero), avoid

Post by mak_kawa »

Hi FreeRaider

Yes, FinishAction= option is very useful in some situation. I am often using it with FileView Plugin also.
As I have looked into Rainmeter documents, RunCommand Plugin also has this option...I didn't explicitly realize.
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Calc measure 0 (zero), avoid

Post by pul53dr1v3r »

mak_kawa wrote: December 1st, 2019, 9:06 am
i agree. Even not working examples can help sometimes to find a solution.
That way your and Morley's helped me to start my, sometimes kind of rusty brain since from time to time i'm slow on the draw.
FreeRaider wrote: December 1st, 2019, 9:44 am I usually use a FinishAction in the parent measure if it is a webparser measure. :rosegift:
hi Raider. Yes, i'm also using them in any of the parent webparser measures, to enable and update the childs and meters on any update cycle. :great: