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.

123 lines
4.4 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. $SBID = $_POST['SBID'];
  9. $Data = array( 'status'=>'nok', 'msg'=>'Access Denied!','out'=>array() );
  10. $Bubbles = array();
  11. if( $BS < 0.2 ) $BS = 0.2;
  12. function sphericalToCartesian( $radius, $theta, $phi ) {
  13. global $Data;
  14. // Ensure angles are in radians if they are not already.
  15. // Use deg2rad() if your input angles are in degrees.
  16. $theta = deg2rad($theta);
  17. $phi = deg2rad($phi);
  18. $x = $radius * cos($phi) * cos($theta);
  19. $y = $radius * cos($phi) * sin($theta);
  20. $z = $radius * sin($phi);
  21. return array( 'x' => $x, 'y' => $y, 'z' => $z );
  22. };
  23. function serchInBubbles( $REC ){
  24. global $Bubbles, $Data;
  25. $CR = array();
  26. $CR['range'] = floatval( $REC['range'] );
  27. $CR['az'] = floatval( $REC['azimuth'] );
  28. $CR['el'] = floatval( $REC['elevation'] );
  29. $CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
  30. $CR['x'] = $CC['x'];
  31. $CR['y'] = $CC['y'];
  32. $CR['z'] = $CC['z'];
  33. $idx = 0;
  34. foreach( $Bubbles as $B ){
  35. $CD = sqrt( pow( ( $B['x']-$CR['x'] ), 2 )+pow( ( $B['y']-$CR['y'] ), 2 )+pow( ( $B['z']-$CR['z'] ), 2 ) );
  36. if( $CD < $B['size'] ) return $idx;
  37. $idx++;
  38. };
  39. return -1;
  40. };
  41. function createBubble( $REC, $BSize = 0.5 ){
  42. global $Bubbles, $Data;
  43. $CR = array();
  44. $CR['range'] = floatval( $REC['range'] );
  45. $CR['az'] = floatval( $REC['azimuth'] );
  46. $CR['el'] = floatval( $REC['elevation'] );
  47. $CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
  48. $CR['x'] = $CC['x'];
  49. $CR['y'] = $CC['y'];
  50. $CR['z'] = $CC['z'];
  51. $CR['count']=1;
  52. $CR['size'] = $BSize;
  53. //$Data['out'][]="R:{$CR['range']} Az:{$CR['az']} El:{$CR['el']} X:{$CR['x']} Y:{$CR['y']} Z:{$CR['z']}";
  54. $Bubbles[] = $CR;
  55. };
  56. function updateBubble( $idx, $REC ){
  57. global $Bubbles;
  58. $CR = array();
  59. $CR['range'] = floatval( $REC['range'] );
  60. $CR['az'] = floatval( $REC['azimuth'] );
  61. $CR['el'] = floatval( $REC['elevation'] );
  62. $CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
  63. $CR['x'] = $CC['x'];
  64. $CR['y'] = $CC['y'];
  65. $CR['z'] = $CC['z'];
  66. $Bubbles[$idx]['range'] = ($Bubbles[$idx]['range']+$CR['range'])/2.0;
  67. $Bubbles[$idx]['az'] = ($Bubbles[$idx]['az']+$CR['az'])/2.0;
  68. $Bubbles[$idx]['el'] = ($Bubbles[$idx]['el']+$CR['el'])/2.0;
  69. $Bubbles[$idx]['x'] = ($Bubbles[$idx]['x']+$CR['x'])/2.0;
  70. $Bubbles[$idx]['y'] = ($Bubbles[$idx]['y']+$CR['y'])/2.0;
  71. $Bubbles[$idx]['z'] = ($Bubbles[$idx]['z']+$CR['z'])/2.0;
  72. $Bubbles[$idx]['count']++;
  73. };
  74. if( $UID > 1 && $DTS ){
  75. $DS = date("Y/m/d", $DTS );
  76. // BID/EID are global ids of one report file (see report_files.php)
  77. list( $SLOT, $RBID, $REID ) = reportResolveRange( $BID, $EID );
  78. $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";
  79. $ZIZI = reportOpenSlot( $DS, $SLOT );
  80. $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
  81. if( count( $LREC ) ){
  82. foreach( $LREC as $REC ){
  83. $bid = serchInBubbles( $REC );
  84. if( $bid < 0 ){
  85. createBubble( $REC, $BS );
  86. } else {
  87. updateBubble( $bid, $REC );
  88. };
  89. };
  90. if( count( $Bubbles ) ){
  91. $Data['status']='ok';
  92. $TArr = explode(',', $SBID );
  93. $SEID = array();
  94. foreach( $TArr as $T ){
  95. $Z = intval( $T );
  96. if( $Z > -1 ) $SEID[] = $Z;
  97. };
  98. $idx = 0;
  99. $cr_cnt = 0;
  100. $ex_cnt = 0;
  101. foreach( $Bubbles as $B ){
  102. if( in_array( $idx, $SEID ) ){
  103. //check if allready exists
  104. $QS = "SELECT `id` FROM `target_bubbles` WHERE ( ABS(`CENTER_X`-({$B['x']})) < `BOUNDARY` ) AND ( ABS(`CENTER_Y`-({$B['y']})) < `BOUNDARY` ) AND ( ABS(`CENTER_Z`-({$B['z']})) < `BOUNDARY` ) LIMIT 1";
  105. $J = $DATABASE->Query( $QS );
  106. if( count( $J ) == 0 ){
  107. $QS="INSERT INTO `target_bubbles`(`CENTER_X`,`CENTER_Y`,`CENTER_Z`,`BOUNDARY`,`BLOCK_COUNS`) VALUES({$B['x']},{$B['y']},{$B['z']},{$BS},255)";
  108. $cr_cnt++;
  109. $DATABASE->Query( $QS );
  110. } else $ex_cnt++;
  111. };
  112. $idx++;
  113. };
  114. $Data['msg'] = "<center>Created {$cr_cnt} Permanent Bubble(s)<br/>{$ex_cnt} Permanent Bubbles already Existed on Same Place(s)</center>";
  115. };
  116. } else {
  117. $Data['msg']='No Target to Analyze!';
  118. };
  119. };
  120. echo json_encode( $Data );
  121. ?>