Skip to content

Instantly share code, notes, and snippets.

@GabeStah
Created September 20, 2013 11:10
Show Gist options
  • Save GabeStah/6636034 to your computer and use it in GitHub Desktop.
Save GabeStah/6636034 to your computer and use it in GitHub Desktop.
WeakAuras: Amount per Interval Tracker - Custom Text Function
function() -- CUSTOM TEXT
-- BEGIN VARIABLES
local ID = 'AmountPerIntervalTracker'
-- END VARIABLES
-- BEGIN BASE FUNCTIONS
local GetValue = function(...)
if not WeakAuras.CustomValues then WeakAuras.CustomValues = {} end
if not ... then return end
local count, data = #{...}
if count and (count > 1) then
for i,v in pairs({...}) do
if i==1 then WeakAuras.CustomValues[v] = WeakAuras.CustomValues[v] or {} data = WeakAuras.CustomValues[v]
else if i ~= count then if not data[v] then data[v] = {} else data = data[v] end else data = data[v] end end
end
else data = WeakAuras.CustomValues[select(1, ...)] end
return data
end
local ShortenNumber = function(value, decimal, format)
if not value then return end
format = format or '%s%s'
function round(val, decimal)
if (decimal) then
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
else
return math.floor(val+0.5)
end
end
if(value > 999999999) then return (format):format(round(value/1000000000, decimal), 'b') end
if(value > 999999) then return (format):format(round(value/1000000, decimal), 'm') end
if(value > 999) then return (format):format(round(value/1000, decimal), 'k') end
return (format):format(round(value, decimal), '')
end
-- END BASE FUNCTIONS
-- BEGIN CUSTOM FUNCTIONS
local GetDestinationCount = function(data)
if not data or not data.destinations then return end
local count
for i,v in pairs(data.destinations) do
count = (count and count or 0) + 1
end
return count
end
local GetValuePerSecond = function(data)
if not data or not data.totalValue then return end
-- Find time diff between now and first entry
if data.events and data.events[1] then
local diff = time() - data.events[1].time
if diff and diff > 0 then
return data.totalValue / diff
end
end
end
local GetTotalValue = function(data)
if not data or not data.totalValue then return end
return data.totalValue
end
-- END CUSTOM FUNCTIONS
-- Total Effective Healing
--return GetTotalValue(GetValue(ID)) or 0
-- Number of affected players
--return GetDestinationCount(GetValue(ID)) or 0
-- Healing per Second for interval
return ShortenNumber(GetValuePerSecond(GetValue(ID))) or 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment