Tópico anterior: Parâmetros nas fórmulas de lógica de negócios

Próximo tópico: Testar fórmulas de lógica de negócios

Exemplo de fórmula inteira

A seguinte fórmula de lógica de negócios agrega os valores de eventos de tempo de atividade, para um valor médio, durante o período de atividade do período de monitoramento da métrica.

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