test single read.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. function show_status($done, $total, $size=30) {
  3. static $start_time;
  4. // if we go over our bound, just ignore it
  5. if($done > $total) return;
  6. if(empty($start_time)) $start_time=time();
  7. $now = time();
  8. $perc=(double)($done/$total);
  9. $bar=floor($perc*$size);
  10. $status_bar="\r[";
  11. $status_bar.=str_repeat("=", $bar);
  12. if($bar<$size){
  13. $status_bar.=">";
  14. $status_bar.=str_repeat(" ", $size-$bar);
  15. } else {
  16. $status_bar.="=";
  17. }
  18. $disp=number_format($perc*100, 0);
  19. $status_bar.="] $disp% $done/$total";
  20. $rate = ($now-$start_time)/$done;
  21. $left = $total - $done;
  22. $eta = round($rate * $left, 2);
  23. $elapsed = $now - $start_time;
  24. $status_bar.= " remaining: ".number_format($eta)." sec. elapsed: ".number_format($elapsed)." sec.";
  25. echo "$status_bar ";
  26. flush();
  27. // when done, send a newline
  28. if($done == $total) {
  29. echo "\n";
  30. }
  31. }
  32. // include channel list
  33. include "SDS_status_channels.php";
  34. $username = 'katrin';
  35. $password = 'neutrino';
  36. $context = stream_context_create(array(
  37. 'http' => array(
  38. 'header' => "Authorization: Basic " . base64_encode("$username:$password"), "Connection: close\r\n"
  39. )
  40. ));
  41. $counter = 0;
  42. $calltime = time();
  43. $errorcount = 0;
  44. $errormessage = '<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>';
  45. $starttime = time();
  46. echo "Polling ADEI data.".PHP_EOL;
  47. for ($id = 0; $id < 1; $id++)
  48. {
  49. $adeiChannels = "";
  50. for ($id2 = 0; $id2 < sizeof($adeiChannel[$id]); $id2++)
  51. {
  52. $adeiChannels = $adeiChannels . $adeiChannel[$id][$id2] . ",";
  53. }
  54. $adeiChannels = substr($adeiChannels, 0, strlen($adeiChannels) - 1);
  55. // new adei-katrin.kaas.kit.edu added
  56. $fileip = file_get_contents("http://adei-katrin.kaas.kit.edu/adei/services/getdata.php?db_server=virtual&db_name=srctree&db_group=-3&control_group=-3&virtual=srctree&srctree=" . $adeiChannels . "&rt=full&window=3600,-1&format=csv", false, $context);
  57. echo $fileip.PHP_EOL;
  58. //show_status($id+1,sizeof($adeiChannel));
  59. if (substr($fileip,0,5) == "ERROR")
  60. {$errorcount++; $errormessage = $errormessage . "Error loading ADEI channel " . $id . "<br>";}
  61. for ($id2 = sizeof($adeiChannel[$id]) - 1 ; $id2 > -1; $id2--)
  62. {
  63. $pos = strrpos($fileip, ",");
  64. $adeiValue[$id][$id2] = floatval(substr($fileip, $pos + 2));
  65. $fileip = substr($fileip, 0, $pos);
  66. //echo $id . " " . $id2 . " " . $adeiValue[$id][$id2] . PHP_EOL;
  67. }
  68. }
  69. ?>