上一主题: 业务逻辑公式中的参数

下一主题: 测试业务逻辑公式

完整示例公式

以下业务逻辑公式将聚合度量标准跟踪期时间段内的 Uptime 事件的值并计算其平均值。

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