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.

121 lines
4.3 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. $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";
  77. $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db');
  78. $LREC = $ZIZI->Query( $QS );
  79. if( count( $LREC ) ){
  80. foreach( $LREC as $REC ){
  81. $bid = serchInBubbles( $REC );
  82. if( $bid < 0 ){
  83. createBubble( $REC, $BS );
  84. } else {
  85. updateBubble( $bid, $REC );
  86. };
  87. };
  88. if( count( $Bubbles ) ){
  89. $Data['status']='ok';
  90. $TArr = explode(',', $SBID );
  91. $SEID = array();
  92. foreach( $TArr as $T ){
  93. $Z = intval( $T );
  94. if( $Z > -1 ) $SEID[] = $Z;
  95. };
  96. $idx = 0;
  97. $cr_cnt = 0;
  98. $ex_cnt = 0;
  99. foreach( $Bubbles as $B ){
  100. if( in_array( $idx, $SEID ) ){
  101. //check if allready exists
  102. $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";
  103. $J = $DATABASE->Query( $QS );
  104. if( count( $J ) == 0 ){
  105. $QS="INSERT INTO `target_bubbles`(`CENTER_X`,`CENTER_Y`,`CENTER_Z`,`BOUNDARY`,`BLOCK_COUNS`) VALUES({$B['x']},{$B['y']},{$B['z']},{$BS},255)";
  106. $cr_cnt++;
  107. $DATABASE->Query( $QS );
  108. } else $ex_cnt++;
  109. };
  110. $idx++;
  111. };
  112. $Data['msg'] = "<center>Created {$cr_cnt} Permanent Bubble(s)<br/>{$ex_cnt} Permanent Bubbles already Existed on Same Place(s)</center>";
  113. };
  114. } else {
  115. $Data['msg']='No Target to Analyze!';
  116. };
  117. };
  118. echo json_encode( $Data );
  119. ?>