Referenz › Funktionsreferenz › Functions

Functions.forecast.calculate

öffentlich

Aufruf als

Functions.forecast.calculate(platform, history, window, noheals, nodmg, now)

Erfassen Sie sie als Abhängigkeit mit dem Namen Functions.forecast.calculate (das Übernehmen der Vervollständigung erledigt das) und rufen Sie sie dann unter diesem Namen auf.

Was sie bewirkt

Eine geprüfte Rate aus dem Gesundheitsverlauf mit explizitem endlichem Fenster und expliziter Uhr berechnen. Geordnete Gewichtung, kanonische Live-Rundung pro Zeile, übersprungene Datenströme, Array-Lücken, gebrochene Schlüssel und das zuletzt besuchte Alter bleiben erhalten. Ein festes Budget von 4096 Einheiten deckt besuchte Zeilen und Akkumulationsklassen beider Datenströme ab; überschüssige oder ungültige Arithmetik ergibt „nicht verfügbar“, nie eine Teilschätzung oder Begrenzung. Diese neue API hat eine eigene Quellidentität; historische Trendfunktionen bleiben unverändert.

Argumente

NameTypWas sie bewirkt
platformRMPlatformMaßgebliche Lesbarkeitsprüfung für verwendete Werte.
historytableSchadens-/Heilungs-Arrays aus Zeit-/Wert-Zeilen; nur ausgewählte Datenströme werden verarbeitet.
windownumberExplizites endliches Gewichtungsfenster; kein Rückgriff auf das Profil, keine Begrenzung.
nohealsbooleanTrue überspringt jeden Zugriff auf den Heilungsdatenstrom.
nodmgbooleanTrue überspringt jeden Zugriff auf den Schadensdatenstrom.
nownumberExplizite endliche Uhr-Momentaufnahme; vorzeichenbehaftete und gebrochene Werte bleiben gültig.

Rückgabewerte

1number | nilEndliche vorzeichenbehaftete kombinierte Rate oder nil, wenn die Berechnung nicht verfügbar ist.
2number | nilEndliches letztes Alter des Datenstroms oder nil, wenn nicht verfügbar.
3string | nilVerfügbarkeitsgrund aus Arbeitslimit, Daten oder Arithmetik für nil-Rate/-Alter.

Editionen

Integrierte Hilfsfunktionen werden auf jeder Edition registriert. Unterschiedlich ist die Spiel-API, die sie lesen; fehlt eine, weicht die Hilfsfunktion aus oder gibt nil mit einem Grund zurück.

Sie liest keine Spiel-API direkt.

Geheime Werte (Retail und Forever)

Auf Retail und Forever übergibt das Spiel Addons geheime Werte. Diese Hilfsfunktion prüft, was sie liest (addon.Platform:CanReadValue), und gibt statt eines geheimen Werts, den sie nicht vergleichen kann, nil mit einem Grund wie restricted-value zurück. Behandeln Sie nil als nicht verfügbar, nicht als false.

Beispiel

local guid = UnitGUID("player")
local history = guid and addon.damageHistory[guid]
if not history then return nil, "no-history" end
local rate, age, reason = Functions.forecast.calculate(addon.Platform, history, 5, false, false, GetTime())
if rate == nil then return nil, reason end
return age >= 2 and rate < 0

Abhängigkeiten

Quelle

Functions/forecast.lua, Zeile 61. Im Spiel schreibgeschützt; Duplizieren erstellt eine bearbeitbare Kopie.

Functions.forecast.calculate(platform, history, window, noheals, nodmg, now)
    if type(platform)~='table' or type(platform.CanReadValue)~='function' then return nil,nil,'invalid-forecast-platform' end
    if not platform:CanReadValue(history) or not platform:CanReadValue(noheals) or not platform:CanReadValue(nodmg) then return nil,nil,'restricted-value' end
    if type(history)~='table' then return nil,nil,'invalid-forecast-history' end
    if type(noheals)~='boolean' or type(nodmg)~='boolean' then return nil,nil,'invalid-forecast-mode' end
    local valid,reason=finite(platform,window)
    if not valid then return nil,nil,reason end
    valid,reason=finite(platform,now)
    if not valid then return nil,nil,reason end
    local work=0
    local function scan(name,skip)
        if skip then return 0,0,0 end
        local rows,why=readField(platform,history,name)
        if why then return nil,nil,nil,why end
        if type(rows)~='table' then return nil,nil,nil,'invalid-forecast-stream' end
        local maxoffs,data=0,{}
        for _,row in ipairs(rows) do
            work=work+1
            if work>4096 then return nil,nil,nil,'forecast-work-budget' end
            local time,problem=readField(platform,row,'time')
            if problem then return nil,nil,nil,problem end
            local good,numberReason=finite(platform,time)
            if not good then return nil,nil,nil,numberReason end
            local diff=now-time
            good,numberReason=finite(platform,diff)
            if not good then return nil,nil,nil,numberReason end
            local scale=window-diff
            local functions,namespaceReason=readField(platform,addon,'Functions')
            if namespaceReason then return nil,nil,nil,namespaceReason end
            if type(functions)~='table' then return nil,nil,nil,'forecast-round-unavailable' end
            local values
            values,namespaceReason=readField(platform,functions,'values')
            if namespaceReason then return nil,nil,nil,namespaceReason end
            if type(values)~='table' then return nil,nil,nil,'forecast-round-unavailable' end
            local round
            round,namespaceReason=readField(platform,values,'round')
            if namespaceReason then return nil,nil,nil,namespaceReason end
            if type(round)~='function' then return nil,nil,nil,'forecast-round-unavailable' end
            local ok,rounded=pcall(round,diff)
            if not ok then return nil,nil,nil,'forecast-round-error' end
            good,numberReason=finite(platform,rounded)
            if not good then return nil,nil,nil,numberReason end
            maxoffs=rounded
            if maxoffs>window then break end
            local amount,amountReason=readField(platform,row,'value')
            if amountReason then return nil,nil,nil,amountReason end
            if amount~=nil and amount~=false then
                good,numberReason=finite(platform,amount)
                if not good then return nil,nil,nil,numberReason end
                good,numberReason=finite(platform,scale)
                if not good then return nil,nil,nil,numberReason end
                local product=amount*scale
                good,numberReason=finite(platform,product)
                if not good then return nil,nil,nil,numberReason end
                local value=(data[maxoffs] or 0)+product
                good,numberReason=finite(platform,value)
                if not good then return nil,nil,nil,numberReason end
                data[maxoffs]=value
            end
        end
        local bins=maxoffs<0 and 0 or math.floor(maxoffs)+1
        if bins>4096-work then return nil,nil,nil,'forecast-work-budget' end
        work=work+bins
        local total,count=0,0
        for i=0,maxoffs do
            total=total+(data[i] or 0)
            local good,numberReason=finite(platform,total)
            if not good then return nil,nil,nil,numberReason end
            local scale=window-i
            good,numberReason=finite(platform,scale)
            if not good then return nil,nil,nil,numberReason end
            count=count+scale
            good,numberReason=finite(platform,count)
            if not good then return nil,nil,nil,numberReason end
        end
        return total,count,maxoffs
    end
    local damageTotal,damageCount,damageSeconds,damageReason=scan('damage',nodmg)
    if damageReason then return nil,nil,damageReason end
    local healTotal,healCount,healSeconds,healReason=scan('heals',noheals)
    if healReason then return nil,nil,healReason end
    local damageRate=damageCount>0 and -damageTotal/damageCount or 0
    valid,reason=finite(platform,damageRate)
    if not valid then return nil,nil,reason end
    local healRate=healCount>0 and healTotal/healCount or 0
    valid,reason=finite(platform,healRate)
    if not valid then return nil,nil,reason end
    local rate=damageRate+healRate
    valid,reason=finite(platform,rate)
    if not valid then return nil,nil,reason end
    return rate,damageSeconds>healSeconds and damageSeconds or healSeconds

Zurück zu Funktionsreferenz