using rate engine

Comment on Asterisk addon rate-engine
Anonymous

Re: using rate engine

Posted:Tue 15 of Feb, 2005 (13:50 UTC)
Hm i just noticed that if you want to use the agi.. you have to watch out as everything in square brakets are displayed as linik
so if you want to use ti you have to reverse this.. so in function write_rates
change the set_var('DESTINATION'.$i,$rate["destination"]);
and so on .. to $rate and then the square braket and then "destination" squarebraket
...
this should help i think
Anonymous

using rate engine

Posted:Sun 16 of Jan, 2005 (17:47 UTC)
so after some closer tlook at this addon i got it finally to work. Note that this won't sort (:exclaim:)
the rates for you , you have to write an script which would do that.
here is my php agi (it took me a full day fo figure out that this actually don't sort


require "phpagi.php";
//include('/etc/asterisk/config.php');
ob_implicit_flush(true);
global $agi;
$agi = new AGI();
set_time_limit(5);

error_reporting(0);
//L:wq$in = fopen("php://stdin","r");

$debug=false;

$avglen=300;

function load_rates() {
global $agi;
$j=0;
for ($i=1 ; $iget_var('DESTINATION'.$i);

$firstlen=$agi->get_var('FIRSTLEN'.$i);

$restlen=$agi->get_var('RESTLEN'.$i);
$startcost=$agi->get_var('STARTCOST'.$i);
$periodcost=$agi->get_var('PERIODCOST'.$i);
$trialcost=$agi->get_var('TRIALCOST'.$i);

if (isset($destination) ) {
$j ++;
$ecost = calcaveragecall($firstlen, $restlen,$startcost,$periodcost);

$tmp = array("destination"=>$destination,"firstlen"=>$firstlen,"restlen"=>$restlen,"startcost"=>$startcost,"periodcost"=>$periodcost,"trialcost"=>$trialcost,"ecost"=>$ecost);
$rates[$j] = $tmp;

$agi->con_print_r($tmp);
}
}

return $rates;
}



function calcaveragecall($firstlen, $restlen,$startcost,$periodcost){
global $avglen,$agi;

if ($firstlen >= $avglen ){

$estimatecost = $firstlen/$restlen * $periodecost;}
else{
$estimatecost = ($avglen/$restlen) * $periodcost;


}
$estimatecost += $startcost;
$agi->con_print_r($estimatecost);
return $estimatecost;
}

function write($line) {
global $debug, $stdlog,$agi;
if ($debug) fputs($stdlog, "write: $line\n");
echo $line."\n";
}

function write_rates($rates){
global $agi;
$agi->con_print_r($rates);
$i=0;

  foreach ($rates as $rate){
  $i++;
  $agi->set_var('DESTINATION'.$i,$rate["destination"]);
$agi->set_var('FIRSTLEN'.$i,$rate["firstlen"]);
$agi->set_var('RESTLEN'.$i,$rate["restlen"]);
$agi->set_var('STARTCOST'.$i,$rate["startcost"]);
$agi->set_var('PERIODCOST'.$i,$rate["periodcost"]);
$agi->set_var('TRIALCOST'.$i,$rate["trialcost"]);
$agi->set_var('ECOST'.$i,$rate["ecost"]);


}


}
function read() {
global $in, $debug, $stdlog;
$input = str_replace("\n", "", fgets($in, 4096));
if ($debug) fputs($stdlog, "read: $input\n");
return $input;
}



function array_sort($array, $key)
{
for ($i = 1; $i con_print_r($sortedrates);
write_rates($sortedrates);

exit;

it is not really a nice script but it will work. any updates welcome
next you have to fill the database
so for using for instance voipjet



| route_id | provider_id | technology | peer | pattern | substitute | description |

| 1 | 3 | IAX2 | XXX@voipjet | 00 | 011$1 | try |

which would subtitute 00 with 011 and adds IAX2/XXX@voipjet/011
not tha you would have to add adifferent line to egress if you wanna
dial to the us .

next an exampel for the rate feed

| rate_id | route_id | iso | type | country | extra | prefix | active_date | expires_date | firstperiod | periods | startcost | periodcost | trialcost |

| 9 | 9 | 1 | | usa alaska | | 001907 | 0000-00-00 | 0000-00-00 | 0 | 1 | 2980 | 0 | 0 |
| 10 | 9 | 1 | | usa hawaii | | 001808 | 0000-00-00 | 0000-00-00 | 0 | 1 | 2980 | 0 | 0 |
| 95 | 9 | 1 | | usa proper | | 001 | 0000-00-00 | 0000-00-00 | 0 | 1 | 2980 | 28 | 0 |
| 2594 | 3 | 1 | | usa alaska | | 001907 | 0000-00-00 | 0000-00-00 | 6 | 6 | 0 | 197 | 0 |
| 2595 | 3 | 1 | | usa hawaii | | 001808 | 0000-00-00 | 0000-00-00 | 6 | 6 | 0 | 161 | 0 |
| 2596 | 3 | 1 | | usa proper | | 001 | 0000-00-00 | 0000-00-00 | 6 | 6 | 0 | 130 | 0 |

so for the route_id you would have to use the key from the egress table.
that will make it work
the extra column is actually for the identifier mobile or proper but i still have not done the work . to make that happen
so maybe this will help you save some time .. (:biggrin:)
i would have appreciate it..
kyra