phpDocumentor VFront
Function-Libraries
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file func.stat.php

Documentation is available at func.stat.php

  1. <?php
  2. /**
  3. * Libreria di funzioni a supporto delle statistiche.
  4. * Vengono utilizzate dai file della cartella /stats
  5. @package VFront
  6. @subpackage Function-Libraries
  7. @author Mario Marcello Verona <marcelloverona@gmail.com>
  8. @copyright 2007 Mario Marcello Verona
  9. @version 0.90
  10. @license http://www.gnu.org/licenses/gpl.html GNU Public License
  11. */
  12.  
  13.  
  14.  
  15.  
  16. /**
  17.  * Generatore delle tabelle riassuntive per le statistiche
  18.  *
  19.  * @param array $eti Array etichette
  20.  * @param array $dati Array dati
  21.  * @param array $th Intetazioni di colonna
  22.  * @return string HTML
  23.  */
  24. function stat_tabella($eti,$dati,$th=array('tabella','record')){
  25.     
  26.     $TAB="<table summary=\"tabella statistiche\" class=\"tab-stat\">\n";
  27.     
  28.     
  29.     $TOT=array_sum($dati);
  30.  
  31.     $TAB.="
  32.         <tr>
  33.               <th>".$th[0]."</th>
  34.               <th>".$th[1]."</th>
  35.         </tr>";
  36.     
  37.     for($i=0;$i<count($eti);$i++){
  38.         
  39.         $TAB.= "
  40.         <tr>\n<td>".$eti[$i]."</td>
  41.               <td>".$dati[$i]."</td>
  42.         </tr>
  43.               ";
  44.     
  45.     }
  46.     
  47.     $TAB.="</table>";
  48.     
  49.     
  50.     return $TAB;
  51. }
  52.  
  53.  
  54.  
  55. /**
  56.  * Formula per il calcolo delle percentuali
  57.  *
  58.  * @param int $n Numero dato
  59.  * @param int $tot Totale
  60.  * @param int $round Decimali per l'arrotondamento
  61.  * @return float 
  62.  */
  63. function percento($n,$tot,$round=2){
  64.     
  65.     return round($n/$tot*100,$round);
  66.     
  67. }
  68.  
  69.  
  70.  
  71. /**
  72.  * Funzione per il calcolo della deviazione standard
  73.  * Dato un array $x ed un arrotondamento restituisce un numero con virgola
  74.  *
  75.  * @param array $x Array con i valori per cui calcolare la deviazione standard
  76.  * @param int $arrotondamento Decimali per l'arrotondamento
  77.  * @return float 
  78.  */
  79. function deviazione_standard($x,$arrotondamento){
  80.  
  81.      $n=count($x);
  82.      $somma_x=array_sum($x);
  83.      foreach($x as $valore){
  84.       $somma_x_pow +=pow($valore,2);
  85.       }
  86.      $pow_somma_x=pow($somma_x,2);
  87.     
  88.      $dev=sqrt((($n $somma_x_pow$pow_somma_x /   ($n*($n-1)));
  89.      $dev=round($dev,$arrotondamento);
  90.      return $dev;
  91.  
  92.  
  93. ?>

Documentation generated on Sat, 22 Sep 2007 11:50:22 +0200 by phpDocumentor 1.4.0a2