参考 › 函数参考 › Functions

Functions.trends.calculate

公共

调用方式

Functions.trends.calculate(history, window, noheals, nodmg)

将其记录为名为 Functions.trends.calculate 的依赖项(接受自动补全即可完成),然后按该名称调用。

作用

根据加权的伤害和治疗历史估算带符号的生命值变化。伤害贡献负速率,治疗贡献正速率。未提供窗口时读取实时配置文件中的窗口,使用实时时钟和旧版舍入服务,并保留现有的加权和舍入后时长计算。此辅助函数不会验证或清理历史,不会截断时间戳,也不保证结果有限。

参数

名称类型作用
historytable | false | nil历史记录,包含以最新者在前的伤害和治疗数组,元素为时间/数值条目。为假值的历史只返回零,不会读取时钟。
windownumber | false | nil加权窗口,单位为秒;为 nil 或 false 时使用当前配置文件的 damage_history 设置。
nohealsboolean | nil为真值时跳过治疗数据流,不读取其数组。
nodmgboolean | nil为真值时跳过伤害数据流,不读取其数组。

返回值

1number来自原始公式的带符号加权合并速率;格式错误或非有限的输入保留旧版的错误/数值行为。
2number | nil较大的舍入后数据流时长(秒),并非样本数量,也不能证明是连续观测。历史为假值时省略。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
GetTime经典旧世TBC 周年版经典进阶服永久服正式服

示例

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 < -1000

源码

Functions/trends.lua,第 75 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

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)

返回函数参考