[Asterisk-Users] ASTCC Rate Calculation

Darren Wiebe darren at aleph-com.net
Sat Jun 18 14:34:28 MST 2005


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
eval { $cost = int($adjcost * $adjtime / 60) };
#    cost = 253
$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.
$cost = ($billseconds / 60) * $adjcost + $adjconn;
Therefore the cost = 300

3.  Proposed Correction to original Code
The difference I see is that the first one is double billing for the 
included seconds.  That would be easier fixed as follows: 
eval { my $adjtime = int((($answeredtime - $numdata->{includedseconds}) 
+ $increment - 1) / $increment) * $increment };

Doing the math this way the cost on the call would come out @ 303

Which example is correct?  Which code is easier to follow? :-)

Darren Wiebe
darren at aleph-com.net





Rusty Shackleford wrote:

>On Fri, June 17, 2005 5:19 pm, Darren Wiebe said:
>  
>
>>Good Day
>>
>>Has anybody here looked closely at the call cost calculation in ASTCC?
>>Can you duplicate the way the cost of a call is calculated?  I believe
>>that there is an error in the code.  I have fixed it, I think and
>>submitted a patch but we need user comments.  I would appreciate if
>>anybody involved would slip over to chech out this link on the
>>bugtracker and provide feedback. http://bugs.digium.com/view.php?id=4480
>> I may well be wrong but I believe the issue needs visiting.  Somebody
>>was asking me how it calculates costs as they thought they knew what a
>>call should cost.  I said "I'll show you".  Mistake, I could not come up
>>with an answer that made sense.
>>
>>    
>>
>
>Darren,
>
>I took a quick look at the patch. I'm not certain, but it appears that
>you've taken out the formula that factors in the billing increment. This
>forumla, inything other than a 1 second incement, will always "add" time
>to the call for any number of seconds not equally divisible by the billing
>increment integer, resulting in a slightly higher cost than might be
>expected at first glance. This is the way it is supposed to work.
>
>As I said, I only glanced at it briefly. Could you describe your changes
>and the error you were seeing?
>
>_______________________________________________
>Asterisk-Users mailing list
>Asterisk-Users at lists.digium.com
>http://lists.digium.com/mailman/listinfo/asterisk-users
>To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-users
>
>  
>




More information about the asterisk-users mailing list