zygo_test_average - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of zygo_test_average.php

  1. <?php
  2.  
  3. $XTELE_DATA=array(
  4.     '2021-03-01 13:00:00',
  5. '2021-03-01 13:00:27',
  6. '2021-03-01 13:00:45',
  7. '2021-03-01 13:01:03',
  8. '2021-03-01 13:01:21',
  9. '2021-03-01 13:01:39',
  10. '2021-03-01 13:01:57',
  11. '2021-03-01 13:02:15',
  12. '2021-03-01 13:02:29',
  13. '2021-03-01 13:02:45',
  14. '2021-03-01 13:03:03','2021-03-01 13:03:21','2021-03-01 13:03:42','2021-03-01 13:04:12','2021-03-01 13:04:45','2021-03-01 13:05:17','2021-03-01 13:05:49','2021-03-01 13:06:20','2021-03-01 13:06:54','2021-03-01 13:07:27','2021-03-01 13:08:04','2021-03-01 13:08:38','2021-03-01 13:09:10','2021-03-01 13:09:34','2021-03-01 13:09:51','2021-03-01 13:10:15','2021-03-01 13:10:48','2021-03-01 13:11:09','2021-03-01 13:11:52','2021-03-01 13:12:38','2021-03-01 13:13:21','2021-03-01 13:14:05','2021-03-01 13:14:50','2021-03-01 13:15:32','2021-03-01 13:16:12','2021-03-01 13:16:56','2021-03-01 13:17:39','2021-03-01 13:18:24','2021-03-01 13:19:11','2021-03-01 13:19:56','2021-03-01 13:20:53','2021-03-01 13:21:34','2021-03-01 13:22:18','2021-03-01 13:24:34','2021-03-01 13:25:19','2021-03-01 13:26:03','2021-03-01 13:26:56','2021-03-01 13:27:43','2021-03-01 13:28:31','2021-03-01 13:29:20','2021-03-01 13:30:55','2021-03-01 13:31:40','2021-03-01 13:32:28','2021-03-01 13:33:17');
  15. $XTELE_OFFSET=array('0','6','0','1','1','1','1','8','5','1','2','-1','0','2','5','-1','2','1','4','7','1','3','5','-1','5','3','0','2','9','3','9','6','13','14','8','4','9','1','9','11','8','7','9','5','2','8','3','6','1','0','11','1','4','1');  
  16. $count=sizeof($XTELE_DATA);
  17.  
  18.  
  19. if($count){
  20.  
  21.     $sec = 10;
  22.  
  23.     $xdata=array();
  24.     $xoff=array();
  25.  
  26.     $mvals=array();
  27.  
  28.     $dtInit = NULL;
  29.  
  30.     foreach($XTELE_DATA as $k=>$rdata){  //while ($row = $resultChart->fetch_object()){
  31.         
  32.         
  33.         $roffset= $XTELE_OFFSET[$k]; //$row->offset;
  34.         //$rdata= $row->data;
  35.         
  36.         if($roffset!==NULL){
  37.             $xdata[]=$rdata;
  38.             $xoff[]=$roffset;
  39.  
  40.             if($dtInit==NULL){
  41.                 $dtInit = new DateTime($rdata);
  42.             }else{
  43.                 $curdt = new DateTime($rdata);
  44.                 $diff = date_diff($dtInit, $curdt);
  45.                 $total = ((($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i)*60 + $diff->s;
  46.                 $mm = floor($total/$sec);
  47.                 if(!isset($mvals[$mm]))
  48.                     $mvals[$mm]=0;
  49.                 $mvals[$mm]+=$roffset;
  50.                 echo $mm." - ".$roffset." - ".$total."\n";
  51.                 
  52.             }    
  53.             
  54.         }
  55.     }
  56.  
  57.     /*
  58.     
  59.      $dt2 = $dt1->add(new DateInterval('PT'.$sec.'S'));
  60.     
  61.     $dt1 = new DateTime('2021-02-26 06:02:23');
  62.     $xz = $dt1->add(new DateInterval('PT'.$sec.'S'));
  63.     echo "ZZ". $xz->format('H:i:s');
  64.     $dt2 = new DateTime('2021-02-26 06:05:51');
  65.     
  66.     $diff = date_diff($dt1, $dt2);
  67.        
  68.     $total = ((($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i)*60 + $diff->s;
  69.     
  70.     echo $total;*/
  71.  
  72.     echo "\nvar XTELE_DATA=['".implode("','", $xdata)."'];";
  73.     echo "\nvar XTELE_OFFSET=['".implode("','", $xoff)."'];";
  74.     
  75.     echo "\nvar MVALS={";
  76.         foreach($mvals as $m=>$v){
  77.             echo "'".$m."' : '".$v."', ";
  78.         }
  79.     echo "};";
  80. }
File Description
  • zygo_test_average
  • PHP Code
  • 01 Mar-2021
  • 3.21 Kb
You can Share it: