Previous Topic: Parameters in Business Logic FormulasNext Topic: Test Business Logic Formulas


Full Sample Formula

The following Business Logic formula aggregates the values of Uptime events, to an average value, during the timeslot of the tracking period for the metric.

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