[Asterisk-Users] ASTCC Rate Calculation
Rusty Shackleford
john97 at flatline.com
Sat Jun 18 16:08:15 MST 2005
On Sat, June 18, 2005 2:34 pm, Darren Wiebe said:
> Okay, I'll post both pieces of code. What I was seeing is that calls
> where being billed more than I thought they should be. Lets use an
> example with the following info:
>
> Call Length: 147 Seconds
> Increments: 6 Seconds
> Connect Charge: 100
> Included Seconds: 30
> Cost per minute: 100
>
>
> 1. Present Code:
> eval { my $adjtime = int(($answeredtime + $increment - 1) / $increment)
> * $increment };
> # adjtime = 152
This might be where your error is creeping in. $adjtime SHOULD equal 150.
Remember, the int() function removes the value to the right of the decimal
point - so int(($answerdtime + $increment -1) / $increment) = 25 and not
25.333333333~, as your example appears to show. This makes $adjtime
actually 150, not 152.
> eval { $cost = int($adjcost * $adjtime / 60) };
> # cost = 253
Corrected, this would be 250.
Viewed another way, using a 6 second increment, 147 seconds represents 25
such increments (actually 24.5, but we get all of the last increment, so
it's 25).
25 * 10 (the cost of one 6-second increment) = 250.
> $cost += $adjconn;
> # Total Cost = 353
>
> 2. My Proposed Code:
> $total_seconds = ($answeredtime - $numdata->{includedseconds})/$increment;
> # Total_Seconds(This variable is not very well named) = 19.5
> $bill_increments = ceil($total_seconds);
> # We need to bill for 20 6 second increments.
> $billseconds = $bill_increments * $increment;
> # This translates to 120 seconds.
Which cheats us out of 27 seconds worth of revenue (actually 30 seconds,
since that 27 seconds represents five 6-second increments).
More information about the asterisk-users
mailing list