Location: PHPKode > projects > WebETB > stats/get_stats.php4
<?
/******************************************************************************/
/*	MODUL:	stats/get_stats.php4       													*/
/*																										*/
/* DATUM:	27.03.2006, Version 0.1															*/
/* BESCHR.:	Funktionssammlung fuer Einsatzstatistiken                         */
/*																										*/
/*	AUTOR:   Marcus Groh																			*/
/*	LIZENZ:  GPL v2 vom Juni 1991 															*/
/*																										*/
/*	AENDERUNGEN:	13.01.2006        -initiale Version								   */
/*                27.03.2006 v 0.1, -Versionskennzeichnung eingefuehrt        */
/*                                  -Code unter GPL v2 gestellt               */
/*                                  -Tabellenname dynamisiert                 */
/*																										*/
/******************************************************************************/
$allowed_groups=array("elw");
      if ( $access != "TRUE" )
      {
         echo "<meta http-equiv=\"refresh\" content=\"0; URL=../login.php4\">\n";
         exit;
      }
      

function sec_to_time ($time_to_conv_s)
{
   // Anzahl sekunden in das format hh:mm:ss umsetzen
   $time_to_conv_m=0;
   $time_to_conv_h=0;
 
       while ( $time_to_conv_s >= 59 )
       {
          $time_to_conv_m++;
          $time_to_conv_s = $time_to_conv_s - 60;
 
          if ( $time_to_conv_m == 60 )
          {
             $time_to_conv_h++;
             $time_to_conv_m = $time_to_conv_m - 60;
          }

       }
       if ($time_to_conv_s <= 9) { $time_to_conv_s="0".$time_to_conv_s; }
       if ($time_to_conv_m <= 9) { $time_to_conv_m="0".$time_to_conv_m; }
      
      $converted_time=$time_to_conv_h . ":" . $time_to_conv_m . ":" . $time_to_conv_s;
      return  "$converted_time";
}

function time_to_sec ($time_to_conv)
{
   // Format hh:mm:ss in anzahl sekunden umsetzen
   list ($HH, $MM, $SS) = split ('[/.-/:]', $time_to_conv);
   $converted_time_s=$SS;
   
       while ( $HH != 0 )
       {
          $converted_time_s=$converted_time_s + 3600;
          $HH--;
       } 

       while ( $MM != 0 )
       {
          $converted_time_s=$converted_time_s + 60;
          $MM--;
       }

      return  "$converted_time_s";
}

function min_out_of_array ($array, $length)
{
   $min_val = 0;
   for ( $i=0; $i <= $length; $i++ )
   {
      $act_val=$array[$i];
      for ( $j=0; $j <= $length; $j++ )
      {
         if ( $array[$j] <= $act_val ) { $min_val=$array[$j]; break; }            
      }
   
   }
   return $min_val;
}

function max_out_of_array ($array, $length)
{
   $max_val = 0;
   for ( $i=0; $i <= $length; $i++ )
   {
      $act_val=$array[$i];
      for ( $j=0; $j <= $length; $j++ )
      {
         if ( $array[$j] >= $act_val ) { $max_val=$array[$j]; break; }            
      }
   
   }
   return $max_val;
}

// Get user name
$user_name="select u_name from $T_user where uid=$uid";
$result=@mysql_db_query($database["database"],$user_name,$db);
   $row=mysql_fetch_array($result);
   $user_name=$row['u_name'];

//Get users group
$group_name="select einheit from $T_user where uid=$uid";
$result=@mysql_db_query($database["database"],$group_name,$db);
   $row=mysql_fetch_array($result);
   switch ( $row[einheit] )
                  {
                     case 'reg':    $einheit_name="Registratur";
                                    break;
                     case 'elw':    $einheit_name="SEG-ELW";
                                    break;
                     case 'trans':  $einheit_name="Transport";
                                    break;                                                                        
                     case 'san':    $einheit_name="Verbandsplatz";
                                    break;                     
                     case 'sons':   $einheit_name="Sonstige";
                                    break;                                    
                  } 
   
// Get desc. of EINSATZ
$einsatz_name="select ort from $T_einsaetze where eid=$eid";
$result=@mysql_db_query($database["database"],$einsatz_name,$db);
   $row=mysql_fetch_array($result);
   $einsatz_name=$row['ort'];

// Get max. entrys from etb
$max_etb_eintr="select * from $T_etb where eid=$eid";
$result=@mysql_db_query($database["database"],$max_etb_eintr,$db);
$max_etb_eintr=mysql_num_rows($result);

// Get max. entrys from auftrag
$max_auftr_eintr="select * from $T_auftrag where eid=$eid";
$result=@mysql_db_query($database["database"],$max_auftr_eintr,$db);
$max_auftr_eintr=mysql_num_rows($result);

// Beginn des Einsatzes auslesen
$select_etb_first="select date_beg , time_beg from $T_einsaetze where eid=$eid";
$result_etb_first=@mysql_db_query($database["database"],$select_etb_first,$db);
   while ( $row=mysql_fetch_array($result_etb_first))
   {
         list ($Y, $M, $D) = split ('[/.-]', $row['date_beg']);        
         $result_etb_first_date="$D.$M.$Y";
         $result_etb_first_time=$row['time_beg'];         
   }

// Ende des Einsatzes auslesen
$select_etb_closed="select * from $T_einsaetze where eid=$eid";
$result_etb_closed=@mysql_db_query($database["database"],$select_etb_closed,$db);
while ( $row=mysql_fetch_array($result_etb_closed))
{
   $einsatz_is_closed=$row['closed'];
}
if ( $einsatz_is_closed == "Y" )
{

$select_etb_last="select date_end , time_end from $T_einsaetze where eid=$eid";
$result_etb_last=@mysql_db_query($database["database"],$select_etb_last,$db);
   while ( $row=mysql_fetch_array($result_etb_last))
   {
         list ($Y, $M, $D) = split ('[/.-]', $row['date_end']);        
         $result_etb_last_date = "$D.$M.$Y";
         $result_etb_last_time = $row['time_end'];        
   }
   
    // Einsatzdauer berechnen
       list ($d, $m, $y) = split ('[/.-/:]', $result_etb_first_date);
       list ($H, $M, $S) = split ('[/.-/:]', $result_etb_first_time);
       $result_etb_first_unix=mktime($H, $M, $S, $m, $d, $y);

       list ($d, $m, $y) = split ('[/.-/:]', $result_etb_last_date);
       list ($H, $M, $S) = split ('[/.-/:]', $result_etb_last_time);
       $result_etb_last_unix=mktime($H, $M, $S, $m, $d, $y);
 
       $result_etb_diff_s=$result_etb_last_unix - $result_etb_first_unix;
       $result_einsatz_gesamt_s=$result_etb_last_unix - $result_etb_first_unix;      
       $result_etb_diff_h = 0 ;
       $result_etb_diff_m = 0 ;
 
       while ( $result_etb_diff_s >= 59 )
       {
          $result_etb_diff_m++;
          $result_etb_diff_s = $result_etb_diff_s - 60;
 
          if ( $result_etb_diff_m == 60 )
          {
             $result_etb_diff_h++;
             $result_etb_diff_m = $result_etb_diff_m - 60;
          }

       }
       if ($result_etb_diff_s <= 9) { $result_etb_diff_s="0".$result_etb_diff_s; }
       if ($result_etb_diff_m <= 9) { $result_etb_diff_m="0".$result_etb_diff_m; }
}
else
{
   $result_etb_last_date = "- Einsatz noch nicht abgeschlossen";
   $result_etb_last_time = "";
   $result_etb_diff_h = "00";
   $result_etb_diff_m = "00";
   $result_etb_diff_s = "00";
   
}

// Erfasse Anzahl vom Typ "Abschnitt"
$select_max_abs_eintr="select * from $T_kraefte where eid=$eid and typ like 'Abschnitt'";
$result_max_abs_eintr=@mysql_db_query($database["database"],$select_max_abs_eintr,$db);
$result_max_abs_eintr=mysql_num_rows($result_max_abs_eintr);

// Erfasse Anzahl vom Typ "Fahrzeug"
$select_max_fzg_eintr="select * from $T_kraefte where eid=$eid and typ like 'Fahrzeug'";
$result_max_fzg_eintr=@mysql_db_query($database["database"],$select_max_fzg_eintr,$db);
$result_max_fzg_eintr=mysql_num_rows($result_max_fzg_eintr);

// Erfasse Anzahl vom Typ "Team"
$select_max_team_eintr="select * from $T_kraefte where eid=$eid and typ like 'Team'";
$result_max_team_eintr=@mysql_db_query($database["database"],$select_max_team_eintr,$db);
$result_max_team_eintr=mysql_num_rows($result_max_team_eintr);

// Erfasse Anzahl der erfassten Patienten
$select_max_pat_eintr="select * from $T_patient where eid=$eid and used='Y'";
$result_max_pat_eintr=@mysql_db_query($database["database"],$select_max_pat_eintr,$db);
$result_max_pat_eintr=mysql_num_rows($result_max_pat_eintr);

// Erfasse Anzahl der erfassten Transporte
$select_max_pat_trans="select * from $T_patient where eid=$eid and used='Y' and fzg_typ >= '1'";
$result_max_pat_trans=@mysql_db_query($database["database"],$select_max_pat_trans,$db);
$result_max_pat_trans=mysql_num_rows($result_max_pat_trans);


// Berechne Anzahl Aktionen / Minute minimalwert u. maximalwert
// Alle 15 minuten wird ein Messpunkt gesetzt und die Anzahl Eintraege in diesem
// Zeitraum ermittelt. Ueber ein Array wird der max bzw. min Wert ausgelesen.
$step_time_value=900;                                         // Schritweite 15 Minuten = 900 sek.
$step_nums_max=$result_einsatz_gesamt_s / $step_time_value;    // Anzahl der Schritte
$step_nums_act=0;
$act_time_value=$result_etb_first_time;                        // Aktuelle Schrittposition
while ( $step_nums_act <= $step_nums_max )
{

   $limit_time_value_s = time_to_sec($act_time_value) + $step_time_value;
   $limit_time_value = sec_to_time($limit_time_value_s);
      
   $select_step_entrys="select lfdnr from $T_etb where eid=$eid and zeit>='$act_time_value' and zeit<='$limit_time_value'";
   $result_step_entrys=@mysql_db_query($database["database"],$select_step_entrys,$db);   
   $step_pos_anzahl[$step_nums_act]=mysql_num_rows($result_step_entrys);      
   $act_time_value = $limit_time_value;
   $step_nums_act++;
}
$actions_per_minute_min=min_out_of_array ($step_pos_anzahl, $step_nums_max) / 15;
$actions_per_minute_max=max_out_of_array ($step_pos_anzahl, $step_nums_max) / 15;

// Berechne Anzahl Aktionen / Minute Mittelwert uber gesamte Dauer
$actions_per_minute_mean=$max_etb_eintr / ( $result_einsatz_gesamt_s  / 60 );

?>
Return current item: WebETB