Call as
Functions.trends.calculate(history, window, noheals, nodmg)
Record it as a dependency named Functions.trends.calculate (accepting the completion does this), then call it by that name.
What it does
Estimate signed health change from weighted damage and healing history. Damage contributes a negative rate and healing a positive rate. Read the live profile window when no window is supplied, use the live clock and legacy rounding service, and preserve the existing weighting and rounded-age calculation. This helper does not validate or sanitize history, clamp timestamps, or guarantee finite results.
Arguments
| Name | Type | What it does |
|---|---|---|
history | table | false | nil | History record with newest-first damage and heals arrays of time/value entries. Falsy history returns only zero without reading the clock. |
window | number | false | nil | Weighting window in seconds; nil or false uses the current profile damage_history setting. |
noheals | boolean | nil | Truthy skips the heals stream without reading its array. |
nodmg | boolean | nil | Truthy skips the damage stream without reading its array. |
Returns
| 1 | number | Combined signed weighted rate from the original formula; malformed or nonfinite inputs retain the legacy error/numeric behavior. |
|---|---|---|
| 2 | number | nil | Larger rounded stream age in seconds, not a sample count or proof of continuous observation. Omitted when history is falsy. |
Editions
Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.
- Not available on that edition (the reason is in the tooltip)
- Only while Blizzard's deprecation fallbacks are on
| Game API | |||||
|---|---|---|---|---|---|
GetTime |
Example
local guid = UnitGUID("target")
local history = guid and addon.damageHistory[guid]
if not history then return false end
local rate = Functions.trends.calculate(history, 5, true)
return rate < -1000Source
Functions/trends.lua, line 75. Read only in game; Duplicate makes an editable copy.
Functions.trends.calculate(history, window, noheals, nodmg)
if not history then
return 0
end
if not window then
window = addon.db.profile.damage_history
end
local now = GetTime()
local damage_total, damage_count, damage_seconds = 0, 0, 0
local heal_total, heal_count, heal_seconds = 0, 0, 0
local maxoffs, data = 0, {}
if not nodmg then
for _,v in ipairs(history.damage) do
local diff = now - v.time
local scale = window - diff
maxoffs = addon.round(diff)
if maxoffs > window then
break
end
if v.value then
data[maxoffs] = (data[maxoffs] or 0) + (v.value * scale)
end
end
damage_seconds = maxoffs
for i=0,maxoffs do
damage_total = damage_total + (data[i] or 0)
damage_count = damage_count + (window - i)
end
end
if not noheals then
maxoffs, data = 0, {}
for _,v in ipairs(history.heals) do
local diff = now - v.time
local scale = window - diff
maxoffs = addon.round(diff)
if maxoffs > window then
break
end
if v.value then
data[maxoffs] = (data[maxoffs] or 0) + (v.value * scale)
end
end
heal_seconds = maxoffs
for i=0,maxoffs do
heal_total = heal_total + (data[i] or 0)
heal_count = heal_count + (window - i)
end
end
return (((damage_count > 0) and (-damage_total / damage_count) or 0) +
((heal_count > 0) and (heal_total / heal_count) or 0)),
(damage_seconds > heal_seconds and damage_seconds or heal_seconds)




