Script Example-Using the MeterSummary Helper Function
TASK: Create a Virtual Bill using Interval Data to calculate the Use and Demand (from Channel Data).
The ReadingDelta Helper function works well for monthly readings, but does not work well for more frequent intervals of data (15 Minute or Hourly), since it subtracts the current reading from the next most previous reading. For more frequent intervals, the MeterSummary Helper function should be used.
The MeterSummary Helper function is a programming Object available to Virtual Account Scripts. It is used to obtain summary information regarding interval data for a defined period of time, from a defined Meter Channel. MeterSummary Helper returns the:
- Maximum – The maximum data point value.
- Minimum – The minimum data point value.
- Average – The average of all data point (values).
- Total – The sum of all data point (values).
- Count – The number of data points included in the summary.
Here is an example Virtual Account Script for a meter with a 15-minute Demand Channel, using the MeterSummary Helper function to generate a Virtual Bill containing Use, Demand, and Cost.
' Sample Virtual Account Script using MeterSummary Helper Function
' set a Debug variable
Dim Debug
' Debug = 1 for True, Debug = 0 for False
Debug = 1
'
' declare variables
Dim UnitCost, MeterCode, ChannelCode
' initialize variables
UnitCost = 0.15
MeterCode = "Meter123"
ChannelCode = "DEMAND:KW"
'
' =======
' MeterSummary helper function should return Maximum, Minimum, Average, Total, and Count
'
' declare variables
Dim MSMax, MSMin, MSAvg, MSTotal, MSCount
' initialize variables
MSMax = 0.0
MSMin = 0.0
MSAvg = 0.0
MSTotal = 0.0
MSCount = 0.0
'
If Debug = 1 Then
MsgBox ("MSMax = " & MSMax & ", MSMin = " & MSMin & ", MSAvg = " & MSAvg)
MsgBox ("MSTotal = " & MSTotal & ", MSCount = " & MSCount)
End If
'
' Now use MeterSummary helper function to retrieve the data
Dim MSHF
Set MSHF = MeterSummary(MeterCode, ChannelCode, 0)
'
MSMax = MSHF.Maximum
MSMin = MSHF.Minimum
MSAvg = MSHF.Average
MSTotal = MSHF.Total
MSCount = MSHF.Count
'
If Debug = 1 Then
MsgBox ("MSMax = " & MSMax & ", MSMin = " & MSMin & ", MSAvg = " & MSAvg)
MsgBox ("MSTotal = " & MSTotal & ", MSCount = " & MSCount)
End If
'
' generate the destination bill
'=======
' The kWh consumption is equal to the sum of the 15-minute KW values, divided by 4
Dest.Lines("Usage").value = (MSTotal/4.0)
Dest.Lines("Demand").value = MSMax
Dest.Lines("Total Cost").cost = ((MSTotal/4.0) * UnitCost)
Dest.Cost = (MSTotal * UnitCost)
'
' =======
' end of script

