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.

116 lines
3.9 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. // BID/EID are global ids of one report file (see report_files.php)
  76. list( $SLOT, $RBID, $REID ) = reportResolveRange( $BID, $EID );
  77. $QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$RBID} AND `id`<={$REID} ORDER BY `ts` ASC, `ts_ms` ASC";
  78. $ZIZI = reportOpenSlot( $DS, $SLOT );
  79. $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
  80. if( count( $LREC ) ){
  81. foreach( $LREC as $REC ){
  82. $bid = serchInBubbles( $REC );
  83. if( $bid < 0 ){
  84. createBubble( $REC, $BS );
  85. } else {
  86. updateBubble( $bid, $REC );
  87. };
  88. };
  89. if( count( $Bubbles ) ){
  90. $Data['status']='ok';
  91. unset( $Data['msg'] );
  92. $Data['bubbles'] = array();
  93. $idx = 0;
  94. foreach( $Bubbles as $B ){
  95. $CR['id'] = $idx;
  96. $CR['range'] = sprintf( "%0.2f", $B['range'] );
  97. $CR['az'] = sprintf( "%0.2f", $B['az'] );
  98. $CR['el'] = sprintf( "%0.2f", $B['el']);
  99. $CD = sqrt( pow( $B['x'], 2 )+pow( $B['y'], 2 )+pow( $B['z'], 2 ) );
  100. $CR['r'] = intval( ( $CD * 2048.0)/ 65.0 );
  101. $CR['x'] = $B['x'];
  102. $CR['y'] = $B['y'];
  103. $CR['z'] = $B['z'];
  104. $CR['count'] = $B['count'];
  105. $Data['bubbles'][] = $CR;
  106. $idx++;
  107. };
  108. };
  109. } else {
  110. $Data['msg']='No Target to Analyze!';
  111. };
  112. };
  113. echo json_encode( $Data );
  114. ?>