global-functions: $HumanReadableNum: indicate binary base...

... and update scripts to match the change.
This commit is contained in:
Christian Hesse 2024-04-07 21:11:03 +02:00
parent 36cf4d028b
commit 3015743b19
4 changed files with 11 additions and 7 deletions

View file

@ -71,7 +71,7 @@
message=("Uploaded backup for " . $Identity . " to cloud.\n\n" . \
[ $DeviceInfo ] . "\n\n" . \
[ $FormatLine "Name" ($Cloud->"name") ] . "\n" . \
[ $FormatLine "Size" ([ $HumanReadableNum ($Cloud->"size") 1024 ] . "iB") ] . "\n" . \
[ $FormatLine "Size" ([ $HumanReadableNum ($Cloud->"size") 1024 ] . "B") ] . "\n" . \
[ $FormatLine "Download key" ($Cloud->"secret-download-key") ]); silent=true });
} else={
$SendNotification2 ({ origin=$ScriptName; \

View file

@ -140,7 +140,7 @@
:return \
[ $IfThenElse ([ :typeof $File ] = "array") \
($Name . ":\n" . [ $FormatLine " name" ($File->"name") ] . "\n" . \
[ $FormatLine " size" ([ $HumanReadableNum ($File->"size") 1024 ] . "iB") ]) \
[ $FormatLine " size" ([ $HumanReadableNum ($File->"size") 1024 ] . "B") ]) \
[ $FormatLine $Name $File ] ];
}

View file

@ -64,9 +64,9 @@
$SendNotification2 ({ origin=$ScriptName; \
subject=([ $SymbolForNotification "card-file-box,chart-increasing" ] . "Health warning: RAM utilization"); \
message=("The RAM utilization on " . $Identity . " is at " . $CheckHealthRAMUtilization . "%!\n\n" . \
[ $FormatLine "total" ([ $HumanReadableNum ($Resource->"total-memory") 1024 ] . "iB") 8 ] . "\n" . \
[ $FormatLine "used" ([ $HumanReadableNum ($Resource->"total-memory" - $Resource->"free-memory") 1024 ] . "iB") 8 ] . "\n" . \
[ $FormatLine "free" ([ $HumanReadableNum ($Resource->"free-memory") 1024 ] . "iB") 8 ]) });
[ $FormatLine "total" ([ $HumanReadableNum ($Resource->"total-memory") 1024 ] . "B") 8 ] . "\n" . \
[ $FormatLine "used" ([ $HumanReadableNum ($Resource->"total-memory" - $Resource->"free-memory") 1024 ] . "B") 8 ] . "\n" . \
[ $FormatLine "free" ([ $HumanReadableNum ($Resource->"free-memory") 1024 ] . "B") 8 ]) });
:set CheckHealthRAMUtilizationNotified true;
}
:if ($CheckHealthRAMUtilization < 70 && $CheckHealthRAMUtilizationNotified = true) do={

View file

@ -578,11 +578,13 @@
:local Base [ :tonum $2 ];
:global EitherOr;
:global IfThenElse;
:local Prefix "kMGTPE";
:local Pow 1;
:set Base [ $EitherOr $Base 1024 ];
:local Bin [ $IfThenElse ($Base = 1024) "i" "" ];
:if ($Input < $Base) do={
:return $Input;
@ -595,9 +597,11 @@
:local Tmp1 ($Input * 100 / $Pow);
:local Tmp2 ($Tmp1 / 100);
:if ($Tmp2 >= 100) do={
:return ($Tmp2 . $Prefix);
:return ($Tmp2 . $Prefix . $Bin);
}
:return ($Tmp2 . "." . [ :pick $Tmp1 [ :len $Tmp2 ] ([ :len $Tmp1 ] - [ :len $Tmp2 ] + 1) ] . $Prefix);
:return ($Tmp2 . "." . \
[ :pick $Tmp1 [ :len $Tmp2 ] ([ :len $Tmp1 ] - [ :len $Tmp2 ] + 1) ] . \
$Prefix . $Bin);
}
}
}