moshi wrote:just for fun, please ignore:
.................
(formula stolen from smurfier)
Just for fun, please ignore this as well
:
- I think in your "stolen" formula, something is wrong, moshi ...
Log(x)<=0 not only when x=0, but also when x is between 0 and 1. Therefore, for sub-unit values, the method yields wrong results: due to the negative powers of 1024, things are actually getting multiplied, instead of being divided. The condition should be changed from
=0 to
<=1.
- I don't know why smurfier thought of writing
10*log(2) there, as it doesn't ring a bell anywhere in our heads, lol. The value is simply
log(1024) and this fits the general idea of the formula pretty well. It also becomes easier to change things when applying an "autoscale" of
2 (by 1000) instead of an "autoscale" of
1 (by 1024): you simply have to replace 1024 with 1000 in both places (including the former
10*log(2) which was previously "transformed" into
log(1024)).
-
AutoScale,
Prefix and
Postfix aren't really necessary in the meter, as things can be done in just one step, in the [MeasureMem2] (aka my [MeasureMemToolTip]) measure. I adapted the method a little bit, and it deviates from the original intended purpose of SilverAzide, but gets its job very well for my need :
autoscale + right align in tooltips (where formatting isn't possible, only by the somewhat "restricted" section variables). And to potentially answer to jsmorley, the tooltip font doesn't change much in tooltips, so no need to bother with "different" monospaced or proportional fonts - you just have to find the right settings for the default one (which is proportional, but with some added spaces to fix the difference between wider and narrower characters you get the job done).
Here's what I've come up with:
Code: Select all
[Variables]
Decimals=2
[MeasureMem]
Measure=PhysicalMemory
[MeasureMemToolTip]
Measure=Calc
Formula=Round(MeasureMem/1024**((MeasureMem<=1?1:Ceil(Log(MeasureMem)/Log(1024)))-1),#Decimals#)+(MeasureMem<=1?1:Ceil(Log(MeasureMem)/Log(1024)))*(1/(10**(#Decimals#+1)))
RegExpSubstitute=1
Substitute="^([\s\S]*)$":" \1","^.*(.{8})$":"\1"," ":" ","1$":" ","2$":" k","3$":" M","4$":" G","5$":" T","6$":" P","7$":" E","8$":" Z","9$":" Y"
[MeterTime]
Meter=String
MeasureName=MeasureMem
ToolTipText=[MeasureMemToolTip]
Text="%1"
-
Decimals2 variable is the 'precision'.
- To make this a "one step job" and avoid using the
AutoScale option (which can't be manipulated in tooltips anyway), I had to somehow "memorize" the metric prefix inside the formula. I've done this by adding the
+(MeasureMem<=1?1:Ceil(Log(MeasureMem)/Log(1024)))*(1/(10**(#Decimals#+1))) part to it. What it does is adding an additional decimal at the end of the number (after those from 'precision') which holds the "index" of the metric prefix (1 for none, 2 for kilo-, etc.). Given the fact that the index starts at 1, this trick is also "forcing" the resulting string to have decimals, even if 'precision' is 0, thus avoiding the need to add multiple
. and to merge them afterwards in the string, like in moshi's code.
- Then, in the
Substitute, besides adding some spaces for the "right align" (sometimes more, to compensate for the difference between the width of
k and
M, for example), I convert the above index to the corresponding metric prefix string. The excess spaces also helps in "right aligning" the metric prefixes as well.
There you go. No Lua/bua or anything for a simple thing that can be done in a simple measure. Before this, I tried doing all of it in the original measure (aka [MeasureMem]), but due to some glitches with
DynamicVariables=1 which changed my "computed" measure on the fly and some section variable divisor issues discussed
here, I had to take this route. The only inconvenient is that I have to have additional measures (aka [MeasureMemToolTip]) besides the original ones (aka [MeasureMem]). But then,
Calc measures are not that resource hungry, after all...
P.S. I think the above could work for negative values too, if one replaces the
MeasureMem occurences in the formula with
Abs(MeasureMem) and storing the sign via the metric index storing trick. And yes, I know the above is not
exactly what SilveAzide worked on, but thought these issues are related, so I posted here.