Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. $UID = intval( $CUser->Data['id'] );
  4. $BID = intval( $_POST['BID'] );
  5. $BS = floatval( $_POST['BS'] );
  6. $EID = intval( $_POST['EID'] );
  7. $DTS = intval( $_POST['TS'] );
  8. $Data = array( 'status'=>'nok', 'msg'=>'Access Denied!' );
  9. $Bubbles = array();
  10. if( $BS < 0.2 ) $BS = 0.2;
  11. function sphericalToCartesian( $radius, $theta, $phi ) {
  12. global $Data;
  13. // Ensure angles are in radians if they are not already.
  14. // Use deg2rad() if your input angles are in degrees.
  15. $theta = deg2rad($theta);
  16. $phi = deg2rad($phi);
  17. $x = $radius * cos($phi) * cos($theta);
  18. $y = $radius * cos($phi) * sin($theta);
  19. $z = $radius * sin($phi);
  20. return array( 'x' => $x, 'y' => $y, 'z' => $z );
  21. };
  22. function serchInBubbles( $REC ){
  23. global $Bubbles, $Data;
  24. $CR = array();
  25. $CR['range'] = floatval( $REC['range'] );
  26. $CR['az'] = floatval( $REC['azimuth'] );
  27. $CR['el'] = floatval( $REC['elevation'] );
  28. $CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
  29. $CR['x'] = $CC['x'];
  30. $CR['y'] = $CC['y'];
  31. $CR['z'] = $CC['z'];
  32. $idx = 0;
  33. foreach( $Bubbles as $B ){
  34. $CD = sqrt( pow( ( $B['x']-$CR['x'] ), 2 )+pow( ( $B['y']-$CR['y'] ), 2 )+pow( ( $B['z']-$CR['z'] ), 2 ) );
  35. if( $CD < $B['size'] ) return $idx;
  36. $idx++;
  37. };
  38. return -1;
  39. };
  40. function createBubble( $REC, $BSize = 0.5 ){
  41. global $Bubbles, $Data;
  42. $CR = array();
  43. $CR['range'] = floatval( $REC['range'] );
  44. $CR['az'] = floatval( $REC['azimuth'] );
  45. $CR['el'] = floatval( $REC['elevation'] );
  46. $CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
  47. $CR['x'] = $CC['x'];
  48. $CR['y'] = $CC['y'];
  49. $CR['z'] = $CC['z'];
  50. $CR['count']=1;
  51. $CR['size'] = $BSize;
  52. //$Data['out'][]="R:{$CR['range']} Az:{$CR['az']} El:{$CR['el']} X:{$CR['x']} Y:{$CR['y']} Z:{$CR['z']}";
  53. $Bubbles[] = $CR;
  54. };
  55. function updateBubble( $idx, $REC ){
  56. global $Bubbles;
  57. $CR = array();
  58. $CR['range'] = floatval( $REC['range'] );
  59. $CR['az'] = floatval( $REC['azimuth'] );
  60. $CR['el'] = floatval( $REC['elevation'] );
  61. $CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
  62. $CR['x'] = $CC['x'];
  63. $CR['y'] = $CC['y'];
  64. $CR['z'] = $CC['z'];
  65. $Bubbles[$idx]['range'] = ($Bubbles[$idx]['range']+$CR['range'])/2.0;
  66. $Bubbles[$idx]['az'] = ($Bubbles[$idx]['az']+$CR['az'])/2.0;
  67. $Bubbles[$idx]['el'] = ($Bubbles[$idx]['el']+$CR['el'])/2.0;
  68. $Bubbles[$idx]['x'] = ($Bubbles[$idx]['x']+$CR['x'])/2.0;
  69. $Bubbles[$idx]['y'] = ($Bubbles[$idx]['y']+$CR['y'])/2.0;
  70. $Bubbles[$idx]['z'] = ($Bubbles[$idx]['z']+$CR['z'])/2.0;
  71. $Bubbles[$idx]['count']++;
  72. };
  73. if( $UID > 1 && $DTS ){
  74. $DS = date("Y/m/d", $DTS );
  75. $QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$BID} AND `id`<={$EID} ORDER BY `ts` ASC, `ts_ms` ASC";
  76. $ZIZI = new SQLite_DB( '/srv/www/web/lib/controller/data/reports/'.$DS.'/report.db');
  77. $LREC = $ZIZI->Query( $QS );
  78. if( count( $LREC ) ){
  79. foreach( $LREC as $REC ){
  80. $bid = serchInBubbles( $REC );
  81. if( $bid < 0 ){
  82. createBubble( $REC, $BS );
  83. } else {
  84. updateBubble( $bid, $REC );
  85. };
  86. };
  87. if( count( $Bubbles ) ){
  88. $Data['status']='ok';
  89. unset( $Data['msg'] );
  90. $Data['bubbles'] = array();
  91. $idx = 0;
  92. foreach( $Bubbles as $B ){
  93. $CR['id'] = $idx;
  94. $CR['range'] = sprintf( "%0.2f", $B['range'] );
  95. $CR['az'] = sprintf( "%0.2f", $B['az'] );
  96. $CR['el'] = sprintf( "%0.2f", $B['el']);
  97. $CD = sqrt( pow( $B['x'], 2 )+pow( $B['y'], 2 )+pow( $B['z'], 2 ) );
  98. $CR['r'] = intval( ( $CD * 2048.0)/ 65.0 );
  99. $CR['x'] = $B['x'];
  100. $CR['y'] = $B['y'];
  101. $CR['z'] = $B['z'];
  102. $CR['count'] = $B['count'];
  103. $Data['bubbles'][] = $CR;
  104. $idx++;
  105. };
  106. };
  107. } else {
  108. $Data['msg']='No Target to Analyze!';
  109. };
  110. };
  111. echo json_encode( $Data );
  112. ?>