Advertisement
cdsatrian

prototype r1

Jul 15th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.02 KB | None | 0 0
  1. <?php
  2. $tes=array("-14,-12","-8,-6","-6,-4","-4,-3","-3,-2","-2,-1.5","-1.5,-1","-1,-0.5","-0.5,0","0,0.67","0.67,1.33","1.33,2","2,2.67","2.67,3.33","3.33,4","4,6","6,8");
  3. $actual_value=array(173.81,179.65,182.83,186.28,182.65,184.95,184.5,183.42,187.17,191.08,191.29,177.79,180.09,182.65,181.95,179.64,179.7,177.54,178.9,183.89,179.89,179.48,179,178.68,182.65,184.17,186.79,184.13,183.92,183.65,182.02,183.28,183.45,184.88,192.5,190.54,192.01,196.48,203.59,206.14,201.28,205.02,198.02,198.24,196.95,193.55,192.02,192.75,189.63,188.06,189.9);
  4.  
  5. for($i=0;$i<count($actual_value)-1;$i++){
  6.   $var[$i]=$actual_value[$i+1]-$actual_value[$i];
  7. }
  8.  
  9. $mean=array();$c=0;
  10. foreach($tes as $t){
  11.   $mean[] = explode(",", $t);
  12.   $mean[$c][2]=($mean[$c][1]+$mean[$c][0])/2;
  13.   echo "mean A".($c+1)."=".$mean[$c][2]."<br>";
  14.   $c++;
  15. }
  16. //echo "<pre>";print_r($mean);echo "</pre>";
  17. $urut=array();
  18. echo "<br>======mappin====<br>";
  19. foreach($var as $v){
  20.     $misal = round($v, 2);
  21.     $no2 = 1;
  22.     foreach($tes as $t){
  23.         $pisah = explode(",", $t);
  24.         if($misal >=$pisah[0] && $misal<=$pisah[1]){
  25.             echo $misal.' => A'.$no2.'<br/> ';
  26.             $urut[]=$no2;
  27.             break;
  28.         }
  29.         $no2++;
  30.     }
  31. }
  32. unset($test);
  33. unset($var);
  34. $grup=array();
  35. echo "<br>======routin====<br>";
  36. for($i=0;$i<(count($urut)-1);$i++){
  37.     echo 'A'.$urut[$i].' => A'.$urut[$i+1].'<br/>';
  38.     $grup[]=array($urut[$i],$urut[$i+1]);
  39. }
  40. //unset($urut);
  41. echo "<br>======groupin====<br>";
  42. $first=array();
  43. $second=array();
  44. foreach ($grup as $key => $row) {
  45.     $first[$key] = $row[0];
  46.     $second[$key] = $row[1];
  47. }
  48. array_multisort($first, SORT_ASC, $second, SORT_ASC, $grup);
  49. //echo "<pre>";print_r($grup);echo "</pre>";
  50. $hasil=array();
  51. $c=0;
  52. for($i=0;$i<count($grup);$i++){
  53.     if($i==0){
  54.         $hasil[]=array($grup[0][0],array($grup[0][1]));
  55.         $c++;
  56.     }else{
  57.         if($hasil[$c-1][0]==$grup[$i][0]){
  58.           $n=count($hasil[$c-1][1]);
  59.           if($hasil[$c-1][1][$n-1]!=$grup[$i][1]){
  60.               $hasil[$c-1][1][]=$grup[$i][1];
  61.             }
  62.         }else{
  63.             $hasil[]=array($grup[$i][0],array($grup[$i][1]));
  64.             $c++;
  65.         }
  66.     }
  67. }
  68. //echo "<pre>";print_r($hasil);echo "</pre>";
  69. for($i=0;$i<count($hasil);$i++){
  70.     echo 'A'.$hasil[$i][0].'=>';
  71.     $n=count($hasil[$i][1]);
  72.     $d=0;
  73.     for($j=0;$j<$n;$j++){
  74.         echo ($j==0?'':',').'A'.$hasil[$i][1][$j];
  75.         $d+=$mean[$hasil[$i][1][$j]-1][2];
  76.     }
  77.     $d=$d/$n;
  78.     $mean[$i][3]=$d;
  79.     echo '<br/>';
  80. }
  81. echo "<br>---new mean interval---<br>";
  82. $c=1;
  83. foreach($mean as $m){
  84.   echo "new mean interval A".($c)."=".$m[3]."<br>";
  85.   $c++;
  86. }
  87. //echo "<pre>";print_r($mean);echo "</pre>";
  88. echo "<br>---forecasting1---<br>";
  89. for($i=0;$i<count($actual_value);$i++){
  90.   echo "[".($i+1)."] ".$actual_value[$i]." ->".(isset($actual_value[$i-1])?$actual_value[$i-1]." + A".($urut[$i-1])."=".($actual_value[$i-1]+$mean[$urut[$i-1]-1][3]):"0")."<br>";
  91. }
  92. echo "<br>---forecasting2---<br>";
  93. for($i=0;$i<count($actual_value);$i++){
  94.   echo "[".($i+1)."] ".$actual_value[$i]." ->".(isset($actual_value[$i-1])?(isset($urut[$i-2])?$actual_value[$i-1]." + A".($urut[$i-2])."=".($actual_value[$i-1]+$mean[$urut[$i-2]-1][3]):"0"):"0")."<br>";
  95. }
  96. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement