It is currently November 26th, 2022, 8:08 pm

Maxima LUA script

Skins that control functions in Windows or Rainmeter
cchargin
Posts: 1
Joined: October 8th, 2013, 5:07 am

Maxima LUA script

Post by cchargin »

Hello all,

I have written a LUA script that will track the maximum value of a measure over a specified time interval. The script is mainly designed to be used in conjunction with measures plotted on line or histogram meters.

You can pick up the example skin at DeviantART.

Both the skin and the script have comments describing how maxima.lua should be used. It is released under a creative commons license, so feel free to add it to your own skins.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Maxima LUA script

Post by smurfier »

I had done the same thing a while back.

Code: Select all

function Initialize()
	Values = {}
	Measure = SKIN:GetMeasure(SELF:GetOption('MeasureName'))
	Width = SELF:GetNumberOption('Width')
end

function Update()
	table.insert(Values, Measure:GetValue())
	if #Values > Width then table.remove(Values, 1) end
	local max, min = math.max(unpack(Values)), math.min(unpack(Values))
	for i = 1, 4 do
		local scaled, post = AutoScale(max * (i / 4), 1)
		SKIN:Bang('!SetVariable', 'Scaled' .. i, scaled .. ' ' .. post)
	end
	return max
end

function Round(num, idp)
	return tonumber(string.format('%.'..(idp or 0)..'f', num))
end

function AutoScale(num, idp)
	local suffix = { 'B', 'kB', 'mB', 'gB', 'tB', 'pB', 'eB', 'zB', 'yB' }
	local scale = num == 0 and 1 or math.ceil(math.log(num)/(10 * math.log(2)))
	return Round(num / 1024 ^ (scale-1), idp or 0), suffix[scale] or scale
end
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .