It is currently February 25th, 2020, 12:11 am

Number measure extension "0"

Help with creating, editing & fixing problems with skins
Mekurukito
Posts: 21
Joined: July 8th, 2018, 6:09 am

Re: Number measure extension "0"

Post by Mekurukito »

balala wrote:
November 14th, 2019, 2:33 pm
Instead of an overcomplicated approach, I'd use a following kind of substitution: Substitute="^(.{5})$":"0\1","^(.{4})$":"00\1","^(.{3})$":"000\1","^(.{2})$":"0000\1","^(.{1})$":"00000\1".
What this substitution does?
First it checks if the value returned by the measure where it is added has five characters (in the .{5} expression, . means any character, {5} means there are five characters). If the value has indeed five characters, this substitution is made and in front of the string (wrote as \1 in the second part of the substitution) is added a zero. If the string has four characters, the first substitution is ignored, but the second one is executed. In this case two zeros are added before the string (due to the 00\1 value). Same way, if there are three characters, three zeros are added (being executed the "^(.{3})$":"000\1" substitution), for two characters four zeros ("^(.{2})$":"0000\1") and finally for one single character, five zeros are added ("^(.{1})$":"00000\1").
Obviously you have to rewrite the zeros if different number of them are required. And further substitutions are also required if more zeros have to be added. But this is the basic of a such procedure to get zeros in front of the string returned by a measure.
thank you very much now this solve my problem. :thumbup:
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Number measure extension "0"

Post by jsmorley »

balala wrote:
November 14th, 2019, 2:33 pm
Instead of an overcomplicated approach, I'd use a following kind of substitution: Substitute="^(.{5})$":"0\1","^(.{4})$":"00\1","^(.{3})$":"000\1","^(.{2})$":"0000\1","^(.{1})$":"00000\1".
What this substitution does?
First it checks if the value returned by the measure where it is added has five characters (in the .{5} expression, . means any character, {5} means there are five characters). If the value has indeed five characters, this substitution is made and in front of the string (wrote as \1 in the second part of the substitution) is added a zero. If the string has four characters, the first substitution is ignored, but the second one is executed. In this case two zeros are added before the string (due to the 00\1 value). Same way, if there are three characters, three zeros are added (being executed the "^(.{3})$":"000\1" substitution), for two characters four zeros ("^(.{2})$":"0000\1") and finally for one single character, five zeros are added ("^(.{1})$":"00000\1").
Obviously you have to rewrite the zeros if different number of them are required. And further substitutions are also required if more zeros have to be added. But this is the basic of a such procedure to get zeros in front of the string returned by a measure.

Yes. Do be aware that this is measuring the "total" length of the string representing the number, so the idea is that the total length of the result will be six characters, including any decimal point . for fractional values.

Note as well that you will likely want to explicitly use the string value of the measure in any String meter. If you use MeasureName=MeasureSomething in the meter, fractional numeric values will be rounded to match NumOfDecimals, (default 0) before the substitution is applied. If you explicitly (and dynamically) use [MeasureSomething] as a section variable, then no rounding or forced decimal places are applied. Any number value is ignored, and you are just using the raw string value, with the substitute applied.

Code: Select all

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

[Variables]

[MeasureSomething]
Measure=Calc
Formula=27.6
RegExpSubstitute=1
Substitute="^(.{5})$":"0\1","^(.{4})$":"00\1","^(.{3})$":"000\1","^(.{2})$":"0000\1","^(.{1})$":"00000\1"

[MeterSomeThing]
Meter=String
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=[MeasureSomething]

1.png


Formula=27, Formula=27.0
2.png

In and of themselves, the numbers 27.0, 27.00, 27.000 do not exist or have any meaning in the world of math. They are all just 27, and that is how Rainmeter will treat the value. No formula in Rainmeter can result in a numeric value of 27.0. Having a zero-value fraction show up is a function of how you "display" it with MeasureName / NumOfDecimals or [SectionVariable:decimals] in a String meter, and has nothing to do with the measured value or any math.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Number measure extension "0"

Post by jsmorley »

I think if you wanted to force the "integer" portion of a number to be some fixed (let's say 6) length, with leading zeros, and display a fixed (let's say 2) number of decimal places as well, with trailing zeros, you might want something like this:

Code: Select all

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

[Variables]

[MeasureValue]
Measure=Calc
Formula=227.505

[MeasureTrunc]
Measure=Calc
Formula=Trunc(MeasureValue)
RegExpSubstitute=1
Substitute="^(.{5})$":"0\1","^(.{4})$":"00\1","^(.{3})$":"000\1","^(.{2})$":"0000\1","^(.{1})$":"00000\1"

[MeasureFrac]
Measure=Calc
Formula=Frac(Round(MeasureValue,2))
RegExpSubstitute=1
Substitute="0.(.*)":"\1","^([\d]{1})$":"\10"

[MeterAll]
Meter=String
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=[MeasureTrunc].[MeasureFrac]

3.png


The point being that you want to treat the integer and fractional portions of the value separately in order to not have the total length including the decimal . play a role.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 9758
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Number measure extension "0"

Post by balala »

jsmorley wrote:
November 14th, 2019, 3:59 pm
I think if you wanted to force the "integer" portion of a number to be some fixed (let's say 6) length, with leading zeros, and display a fixed (let's say 2) number of decimal places as well, with trailing zeros, you might want something like this:
Or the same thing can be achieved even with no need of suplimentar measures. For instance you can add the RegExpSubstitute=1 option directly to the [MeasureValue] measure and add the following Substitute option as well: Substitute="^(\d*)$":"\1.","^(.{6,})\.(.{2,})$":"\1.\2","^(.{5})\.(.{2,})$":"0\1.\2","^(.{4})\.(.{2,})$":"00\1.\2","^(.{3})\.(.{2,})$":"000\1.\2","^(.{2})\.(.{2,})$":"0000\1.\2","^(.{1})\.(.{2,})$":"00000\1.\2","^(.{6,})\.(.{1})$":"\1.\20","^(.{5})\.(.{1})$":"0\1.\20","^(.{4})\.(.{1})$":"00\1.\20","^(.{3})\.(.{1})$":"000\1.\20","^(.{2})\.(.{1})$":"0000\1.\20","^(.{1})\.(.{1})$":"00000\1.\20","^(.{6,})\.$":"\1.00","^(.{5})\.$":"0\1.00","^(.{4})\.$":"00\1.00","^(.{3})\.$":"000\1.00","^(.{2})\.$":"0000\1.00","^(.{1})\.$":"00000\1.00".
In this case the Text option of the [MeterAll] meter should look like: Text=[MeasureVal].
Yes, for sure this looks much more complicated then your solution. And additionally it has an advantage and a disadvantage as well.
The advantage is that no suplimentar measures are required.
The disadvantage is that if the number of needed decimal places is increasing, the Substitution becomes much more complicated. Probably for up to two decimals this might worth, but for more, it definitely doesn't.
User avatar
Yamajac
Posts: 134
Joined: June 30th, 2014, 8:44 am

Re: Number measure extension "0"

Post by Yamajac »

Mekurukito wrote:
November 14th, 2019, 2:39 pm
thank you very much now this solve my problem. :thumbup:
I feel like you might've missed my comment.


It works similarly - a regex to add zeroes, but it works for any length of string with any number of zeroes and preserves any trailing letters like gb, etc.



Here's a video of it in action. It works better than any other regex here, and it's significantly easier to modify the max-length of the number section of the string.

If you've already got something that works well for you then that's great, just wanted to make sure you saw mine in case you were having this problem in the future and needed it to work with a different length/stuff.


If you need a fixed number of decimal places as well, then that can also be done in the same measure, I just didn't include it in this substitution. Lemme know if you do and I'll write up a simple regex for that too. Isn't a terribly complicated thing.
User avatar
balala
Rainmeter Sage
Posts: 9758
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Number measure extension "0"

Post by balala »

Yamajac wrote:
November 14th, 2019, 7:03 pm
I feel like you might've missed my comment.


It works similarly - a regex to add zeroes, but it works for any length of string with any number of zeroes and preserves any trailing letters like gb, etc.



Here's a video of it in action. It works better than any other regex here, and it's significantly easier to modify the max-length of the number section of the string.
Unfortunately it seems this code doesn't have set a MinValue option onto the [DoIt] measure. The code as it is posted, cuts the beginning of the numeric value, if it's longer.
Please check and fix your code.
User avatar
Yamajac
Posts: 134
Joined: June 30th, 2014, 8:44 am

Re: Number measure extension "0"

Post by Yamajac »

balala wrote:
November 14th, 2019, 7:24 pm
Unfortunately it seems this code doesn't have set a MinValue option onto the [DoIt] measure. The code as it is posted, cuts the beginning of the numeric value, if it's longer.
Please check and fix your code.
My understanding is this is supposed to have a fixed max length on the numbers, so I intentionally made the regex to do it that way. It isn't a bug, it's a feature.

But if you really want a one-size fits all, here's a skin that will force a minimum length on numbers both before and after the decimal place without culling any numbers on either side, with separately assigned minimum lengths. Works whether you have decimal places or not. Works with arbitrary numbers of zeroes, decimal places and trailing non-numerical characters.

If you WANT a forced maximum length then in the third and sixth substitutes change the 0* to .* that's all it is. I literally intentionally made it cull the beginning because that's what it was supposed to do. That was literally the "fix".

This one has TWO references to the parent measure in the substitutes. One in the third substitute, one in the sixth. Make sure you change both of them to match the parent measure name.

MinValue assigns a minimum length to the pre-decimal places. MaxValue assigns a minimum length to the post-decimal places.


Here's your one size fits all measure. Here's a video of it. I didn't showcase it but removing the decimal places entirely doesn't break anything.


UPDATE: FIXED A BUG, IF YOU USED THIS BEFORE SEEING THIS MESSAGE USE THE NEW REGEX INSTEAD.

UPDATE2: I REALIZED IM STUPID AND PUT THE DECIMAL ZEROES AT THE FRONT INSTEAD OF BACK HOLD UP I FIX.

UPDATE3: FIX: https://forum.rainmeter.net/viewtopic.php?f=5&t=33948&p=167868#p167868

Code: Select all

[Rainmeter]
Update = -1

[DoIt]
Measure = String
String = 2342.31534534gb
RegExpSubstitute = 1
MinValue = 1
MaxValue = 2

; The first substitute grabs the entire string and adds zeroes to the front
; The second substitute grabs the leading zeroes and duplicates them several times
; to ensure we have enough leading zeroes for all use cases
; Then finally the third substitute removes all but the last X digits
; Where X is the MinValue on this measure
; Then we do the exact same process over again for the numbers after the decimal place
Substitute = "(^[0-9]*)" : "0000000\1", "^(0*)(0.*)" : "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\2", "0*([0-9]{[DoIt:MinValue]}.*)" : "\1", "\.([0-9]*)" : ".0000000\1", "(.*\.)([0]*)(0.*)" : "\1\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\3", "(^.*\.)0*([0-9]{[DoIt:MaxValue]}.*)" : "\1\2"

[ShowIt]
Meter = String
Text = [DoIt]
FontSize = 15
SolidColor = 0,0,0,1

Last edited by Yamajac on November 14th, 2019, 8:38 pm, edited 2 times in total.
User avatar
balala
Rainmeter Sage
Posts: 9758
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Number measure extension "0"

Post by balala »

Yamajac wrote:
November 14th, 2019, 7:45 pm
My understanding is this is supposed to have a fixed max length on the numbers, so I intentionally made the regex to do it that way. It isn't a bug, it's a feature.
The code posted on the provided link (https://forum.rainmeter.net/viewtopic.php?f=5&t=33948#p167839), has no MinValue set, but in the video posted on the same reply (https://streamable.com/kzrs5) a such option is posted and used. Something doesn't match, that's why I said you to check your reply. Just to make sure the two links are related to each other.

On the other hand, there is a small mistake into this code as well, in my opinion, because setting a large value to the MaxValue option of the [DoIt] measure, adds leading zeros to the DECIMAL PART of the number, modifying its value. For instance this measure:

Code: Select all

[DoIt]
Measure = String
String = 2342.31534534gb
RegExpSubstitute = 1
MinValue = 6
MaxValue = 10
returns 002342.0031534534gb. As you can see there are two zeros added before the decimal part. But this is visible in your video (https://streamable.com/wfws0) as well.

Don't misunderstand me, I don't want to tease you, but these are my observations and had to say.
User avatar
Yamajac
Posts: 134
Joined: June 30th, 2014, 8:44 am

Re: Number measure extension "0"

Post by Yamajac »

balala wrote:
November 14th, 2019, 8:19 pm
The code posted on the provided link (https://forum.rainmeter.net/viewtopic.php?f=5&t=33948#p167839), has no MinValue set, but in the video posted on the same reply (https://streamable.com/kzrs5) a such option is posted and used. Something doesn't match, that's why I said you to check your reply. Just to make sure the two links are related to each other.

On the other hand, there is a small mistake into this code as well, in my opinion, because setting a large value to the MaxValue option of the [DoIt] measure, adds leading zeros to the DECIMAL PART of the number, modifying its value. For instance this measure:

Code: Select all

[DoIt]
Measure = String
String = 2342.31534534gb
RegExpSubstitute = 1
MinValue = 6
MaxValue = 10
returns 002342.0031534534gb. As you can see there are two zeros added before the decimal part. But this is visible in your video (https://streamable.com/wfws0) as well.

Don't misunderstand me, I don't want to tease you, but these are my observation and had to say.
O I didn't notice the MinValue got deleted somehow, that's my bad. And yea I noticed it's putting leading zeroes after the decimal place when I set it to a random calc and saw it was backwards lol, even edited my previous comment to reflect that.


Anyway, here's a working skin. Should work for just about all use cases. And a video of it

It's currently showing the RandomNumber value but you could send it any ol' measure instead and it'd work just fine.

Code: Select all

[Rainmeter]
Update = 1000
DynamicWindowSize = 1

[RandomNumber]
Measure = Calc
UpdateRandom = 1
HighBound = 2147483647
Formula = Random / 1000

[DoIt]
Measure = String
DynamicVariables=1
String = [RandomNumber:4]gb
RegExpSubstitute = 1
MinValue = 8
MaxValue = 7

; The first substitute grabs the entire string and adds zeroes to the front
; The second substitute grabs the leading zeroes and duplicates them several times
; to ensure we have enough leading zeroes for all use cases
; Then finally the third substitute removes all but the last X digits
; Where X is the MinValue on this measure
Substitute = "(^[0-9]*)" : "0000000\1", "^(0*)(0.*)" : "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\2", "0*([0-9]{[DoIt:MinValue]}.*)" : "\1", "(\.[0-9]*)" : "\1000000000", "(.*\.)(.+)(00*)(0[^0-9]*)" : "\1\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\4", "(^.*\.)([0-9]{[DoIt:MaxValue]}[^0]*)0*" : "\1\2"

[ShowIt]
Meter = String
Text = [DoIt]
DynamicVariables=1
FontSize = 15
SolidColor = 0,0,0,1
User avatar
balala
Rainmeter Sage
Posts: 9758
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Number measure extension "0"

Post by balala »

Yamajac wrote:
November 14th, 2019, 8:36 pm
O I didn't notice the MinValue got deleted somehow, that's my bad. And yea I noticed it's putting leading zeroes after the decimal place when I set it to a random calc and saw it was backwards lol, even edited my previous comment to reflect that.
Don't worry, it happens to all of us sometimes to miss such details.
Yamajac wrote:
November 14th, 2019, 8:36 pm
Anyway, here's a working skin. Should work for just about all use cases. And a video of it
Well, unfortunately there still is a problem: if the number generated by the Rand function of the [RandomNumber] measure is so large that the number returned by the measure has more digits than MinValue, the result is wrong again. Check it increasing the HighBound value of the
[RandomNumber] measure.
Unfortunately the code should handle such cases as well.