Vorheriges Thema: "Parameters" in Business-Logik-FormelnNächstes Thema: Testen von Business-Logik-Formeln


Vollständiges Formelbeispiel

Die folgende Business-Logik-Formel aggregiert die Werte von Uptime-Events während des Zeitfensters des Kontrollzeitraums für die Metrik zu einem Durchschnittswert.

Option Explicit

' Global variables declaration
Dim SumOfValues 'accumulates values of events
Dim NumOfValues 'counts number of events

Sub OnRegistration (dispatcher)
'Registration of "UpTime" event to be sent to "OnUpTimeEvent" procedure
dispatcher.RegisterByContractPartyAndService "OnUpTimeEvent" , "UpTime"
End Sub

Sub OnLoad (time)
'Initialization of global variables at the beginning of calculation
SumOfValues = 0
NumOfValues = 0
End Sub

Sub OnPeriodStart (time)
'We reinitialize SumOfValues & NumOfValues at the beginning of each tracking period
SumOfValues = 0
NumOfValues = 0
End Sub

Sub OnUpTimeEvent (upTimeEvent)
'We perform aggregation of event values, but only when inside a timeslot
If Context.IsWithinTimeSlot Then
SumOfValues = SumOfValues + upTimeEvent ("Value")
NumOfValues= NumOfValues + 1
End If
End Sub

Function Result
If NumOfValues = 0 Then
Result = NULL
Else
Result = SumOfValues / NumOfValues
End If

End Function