Zend - The PHP Company




Calculators

Add Code


Average Time Calculator  

Type: code fragment
Added by: Plove
Entered: 01/09/2001
Last modified: 09/12/2000
Rating: **** (3 votes)
Views: 31366
I had to come up with a way to generate an average call time. Simple enough I suppose. Hope it's usefull to someone.


<?
//===============================\
//  Author:Patrick Loven         \
//  Name: Avg Time Calculator    \
//  Date: 8/31/01                \
//  Site: www.lovenresources.com \
//===============================\
function sub_time($time,$intv){
    
//$time = the total amount of time to handle.
    //$intv = the number of which you want to divide by
    
if($time >= $intv){
        
$time_div = ($time $intv);
        
$time_exp explode("."$time_div);
            for(
$n=0;$n<count($time_exp);$n++){
                
$time_exp_pre = ("$time_exp[0]");
            }
        
$time_exp_pre_rem = ($time - ($time_exp_pre $intv));
            if(
$time_exp_pre_rem == 0){
                
$time_exp_pre_rem = ("cleaned");
            }else{
                
$time_exp_pre_rem = ("$time_exp_pre_rem");
            }
        
$time = ("$time_exp_pre.$time_exp_pre_rem");
        
//echo("$time<br>n");
    
}else{
        
//echo ("$time<br>n");
    
}
return array(
$time_exp_pre,$time_exp_pre_rem);
}
function 
calc_avg_time($array$end){
    
//$array = the time you want to divide up "." period deliminated
    //$end = the number of which you want to divide by i.e. the number of time in your array
    
for($i=0;$i<count($array);$i++){
        
$indv_array explode("."$array[$i]);
        for(
$g=0;$g<count($indv_array);$g++){
            
$min = ("$indv_array[0]");
            
$sec = ("$indv_array[1]");
        }
    
$new_min[] = $min++;
    
$new_sec[] = $sec++;
        for(
$q=0;$q<count($new_min);$q++){
            
$new_min_ms = ($new_min[$q] * 60);
        }
    
$new_min_sec[] = $new_min_ms++;
    }

    
$all_sec_min array_sum($new_min_sec);
    
$all_sec_sec array_sum($new_sec);
    
$all_time = ($all_sec_min $all_sec_sec);
    
$avg round($all_time $end0);
    
//echo("$all_sec_min : all minuts<br>n");
    //echo("$all_sec_sec : all seconds<br>n");
    //print_r($new_min_sec);
    //print_r($new_sec);
    
return array($avg,$all_time);
}
?>


Usage Example


$length = array("1.15","1.45");             
list($avg,$all) = calc_avg_time($length,2);

list($avg_min,$avg_sec) = sub_time($avg,60);      
echo("Avg Handle Time : $avg_min.$avg_sec<br>n");


Rate This Script





Search



This Category All Categories