# Weighted Rate

## Program ID

MetraPipeline.WeightedRate.1

## Description

The Weighted Rate plug-in figures out the rate for an event which that event spans one or more time periods. Examples of two time periods are peak and off-peak. The time periods and corresponding calendar codes are configured in the calendar file associated to this plug-in in the <calendar> tag. Any number of calendar codes can be configured, down to each second of the day if necessary.

When a session is processed by the weighted rate plug-in, it is first divided into segments, where each segment si fits into a single time period. A rate ri is then assigned to each segment.

The rate is calculated by calling a configurable external plug-in. This plug-in is passed a copy of the session with the property specified by calendar_code_prop_name holding the correct calendar code, and start_time_prop_name and end_time_prop_name adjusted appropriately. This external plug-in is typically a rule plug-in but can be any pipeline plug-in. The plug-in returns the rate by setting the property specified in rate_prop_name.

Each segment si makes up a certain percentage ni of the total time of the event. The sum of the percentages of each segment is 100% (the entire event); therefore, the weighted rate of the event is

rate = S (ni · ri)

The calculated rate is stored in the property named in rate_prop_name.

The time segments are rated in reverse order. The earliest segment is rated last. This way, any side effects of the external rate plug-in (such as setup charges, minimum cost calculations, etc.) will be based on the calendar code of the start of the event.

## Required Input Properties

Tag name | Value type | Description
start_time_prop_name | Datetime | Time event started.
end_time_prop_name | Datetime | Time event ended.
offset_prop_name | Long | No longer used, but required in configuration.
timezoneid_prop_name | Long | Users timezone ID (see Remarks section for values)

## Required Output Properties

Tag name | Value type | Description
rate_prop_name | decimal | Weighted rate (across all applicable time periods) for this event
calendar_code_prop_name | String | Calendar code in which this event took place. If multiple calendar codes apply, the value of multi_period_calendar_code is used instead.

## Additional Configuration Tags

Tag name | Value type | Description
multi_period_calendar_code | String | Value of calendar_code_prop_name property if this transaction spans multiple calendar codes.
stage_name | String | External plug-ins stage name (typically the name of the current stage)
execute_plug_in | String | External plug-in executed to perform rating.
calendar | String | Filename of the calendar information file holding all calendar code data.

## Configuration Example

<configdata>
<rate_prop_name>Rate</rate_prop_name>
<calendar_code_prop_name>CalendarCode</calendar_code_prop_name>
<start_time_prop_name>ConnectTime</start_time_prop_name>
<end_time_prop_name>DisconnectTime</end_time_prop_name>
<offset_prop_name>timezoneoffset</offset_prop_name>
<timezoneid_prop_name>timezoneID</timezoneid_prop_name>
<multi_period_calendar_code>*</multi_period_calendar_code>
<stage_name>AudioConfConn</stage_name>
<execute_plug_in>RateConnections</execute_plug_in>
<calendar>calendar.xml</calendar>
</configdata>

## Remarks

The Unix zoneinfo database is used to do all time of day calculations. The following timezone IDs are supported.

ID | Microsoft Time Zone Name | Unix Zoneinfo Name
1 | Afghanistan Standard Time | Asia/Kabul
2 | Alaskan Standard Time | America/Anchorage
3 | Arabian Standard Time | Asia/Muscat
4 | Atlantic Standard Time | America/Halifax
5 | AUS Central Standard Time | Australia/Darwin
6 | Azores Standard Time | Atlantic/Azores
7 | Bangkok Standard Time | Asia/Bangkok
8 | Canada Central Standard Time | America/Regina
9 | Cen. Australia Standard Time | Australia/Adelaide
10 | Central Asia Standard Time | Asia/Almaty
11 | Central Europe Standard Time | Europe/Prague
12 | Central Pacific Standard Time | Asia/Magadan
13 | Central Standard Time | America/Chicago
14 | China Standard Time | Asia/Urumqi
15 | Dateline Standard Time | Pacific/Kwajalein
16 | E. Europe Standard Time | NOT SUPPORTED
17 | E. South America Standard Time | NOT SUPPORTED
18 | Eastern Standard Time | America/New_York
19 | Egypt Standard Time | Africa/Cairo
20 | Fiji Standard Time | Pacific/Fiji
21 | GFT Standard Time | Europe/Athens
22 | GMT | Europe/Dublin
23 | GMT Standard Time | Africa/Monrovia
24 | Hawaiian Standard Time | Pacific/Honolulu
25 | India Standard Time | Asia/Calcutta
26 | Iran Standard Time | Asia/Tehran
27 | Israel Standard Time | Asia/Jerusalem
28 | Mexico Standard Time | America/Mexico_City
29 | Mid-Atlantic Standard Time | NOT SUPPORTED
30 | Mountain Standard Time | America/Phoenix
31 | New Zealand Standard Time | Pacific/Auckland
32 | Newfoundland Standard Time | America/St_Johns
33 | Pacific Standard Time | America/Los_Angeles
34 | Romance Standard Time | Europe/Paris
35 | Russian Standard Time | Europe/Moscow
36 | SA Eastern Standard Time | America/Buenos_Aires
37 | SA Pacific Standard Time | America/Bogota
38 | SA Western Standard Time | America/Caracas
39 | Samoa Standard Time | Pacific/Midway
40 | Saudi Arabia Standard Time | Asia/Baghdad
41 | South Africa Standard Time | Africa/Harare
42 | Sydney Standard Time | Australia/Brisbane
43 | Taipei Standard Time | Asia/Hong_Kong
44 | Tasmania Standard Time | Australia/Hobart
45 | Tokyo Standard Time | Asia/Tokyo
46 | US Eastern Standard Time | America/Indianapolis
47 | US Mountain Standard Time | America/Phoenix
48 | W. Europe Standard Time | Europe/Berlin
49 | West Asia Standard Time | Asia/Karachi
50 | West Pacific Standard Time | Pacific/Guam