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.
122 lines
4.3 KiB
122 lines
4.3 KiB
<?php
|
|
require_once('../ajax_asm.php');
|
|
$UID = intval( $CUser->Data['id'] );
|
|
|
|
$BID = intval( $_POST['BID'] );
|
|
$BS = floatval( $_POST['BS'] );
|
|
$EID = intval( $_POST['EID'] );
|
|
$DTS = intval( $_POST['TS'] );
|
|
$SBID = $_POST['SBID'];
|
|
$Data = array( 'status'=>'nok', 'msg'=>'Access Denied!','out'=>array() );
|
|
$Bubbles = array();
|
|
if( $BS < 0.2 ) $BS = 0.2;
|
|
function sphericalToCartesian( $radius, $theta, $phi ) {
|
|
global $Data;
|
|
// Ensure angles are in radians if they are not already.
|
|
// Use deg2rad() if your input angles are in degrees.
|
|
$theta = deg2rad($theta);
|
|
$phi = deg2rad($phi);
|
|
|
|
$x = $radius * cos($phi) * cos($theta);
|
|
$y = $radius * cos($phi) * sin($theta);
|
|
$z = $radius * sin($phi);
|
|
return array( 'x' => $x, 'y' => $y, 'z' => $z );
|
|
};
|
|
|
|
function serchInBubbles( $REC ){
|
|
global $Bubbles, $Data;
|
|
$CR = array();
|
|
$CR['range'] = floatval( $REC['range'] );
|
|
$CR['az'] = floatval( $REC['azimuth'] );
|
|
$CR['el'] = floatval( $REC['elevation'] );
|
|
$CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
|
|
$CR['x'] = $CC['x'];
|
|
$CR['y'] = $CC['y'];
|
|
$CR['z'] = $CC['z'];
|
|
$idx = 0;
|
|
foreach( $Bubbles as $B ){
|
|
$CD = sqrt( pow( ( $B['x']-$CR['x'] ), 2 )+pow( ( $B['y']-$CR['y'] ), 2 )+pow( ( $B['z']-$CR['z'] ), 2 ) );
|
|
if( $CD < $B['size'] ) return $idx;
|
|
$idx++;
|
|
};
|
|
return -1;
|
|
};
|
|
function createBubble( $REC, $BSize = 0.5 ){
|
|
global $Bubbles, $Data;
|
|
$CR = array();
|
|
$CR['range'] = floatval( $REC['range'] );
|
|
$CR['az'] = floatval( $REC['azimuth'] );
|
|
$CR['el'] = floatval( $REC['elevation'] );
|
|
$CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
|
|
$CR['x'] = $CC['x'];
|
|
$CR['y'] = $CC['y'];
|
|
$CR['z'] = $CC['z'];
|
|
$CR['count']=1;
|
|
$CR['size'] = $BSize;
|
|
//$Data['out'][]="R:{$CR['range']} Az:{$CR['az']} El:{$CR['el']} X:{$CR['x']} Y:{$CR['y']} Z:{$CR['z']}";
|
|
$Bubbles[] = $CR;
|
|
};
|
|
function updateBubble( $idx, $REC ){
|
|
global $Bubbles;
|
|
$CR = array();
|
|
$CR['range'] = floatval( $REC['range'] );
|
|
$CR['az'] = floatval( $REC['azimuth'] );
|
|
$CR['el'] = floatval( $REC['elevation'] );
|
|
$CC = sphericalToCartesian( $CR['range'], $CR['az'], $CR['el'] );
|
|
$CR['x'] = $CC['x'];
|
|
$CR['y'] = $CC['y'];
|
|
$CR['z'] = $CC['z'];
|
|
$Bubbles[$idx]['range'] = ($Bubbles[$idx]['range']+$CR['range'])/2.0;
|
|
$Bubbles[$idx]['az'] = ($Bubbles[$idx]['az']+$CR['az'])/2.0;
|
|
$Bubbles[$idx]['el'] = ($Bubbles[$idx]['el']+$CR['el'])/2.0;
|
|
$Bubbles[$idx]['x'] = ($Bubbles[$idx]['x']+$CR['x'])/2.0;
|
|
$Bubbles[$idx]['y'] = ($Bubbles[$idx]['y']+$CR['y'])/2.0;
|
|
$Bubbles[$idx]['z'] = ($Bubbles[$idx]['z']+$CR['z'])/2.0;
|
|
$Bubbles[$idx]['count']++;
|
|
};
|
|
if( $UID > 1 && $DTS ){
|
|
$DS = date("Y/m/d", $DTS );
|
|
$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";
|
|
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db');
|
|
$LREC = $ZIZI->Query( $QS );
|
|
if( count( $LREC ) ){
|
|
foreach( $LREC as $REC ){
|
|
$bid = serchInBubbles( $REC );
|
|
if( $bid < 0 ){
|
|
createBubble( $REC, $BS );
|
|
} else {
|
|
updateBubble( $bid, $REC );
|
|
};
|
|
};
|
|
if( count( $Bubbles ) ){
|
|
$Data['status']='ok';
|
|
$TArr = explode(',', $SBID );
|
|
$SEID = array();
|
|
foreach( $TArr as $T ){
|
|
$Z = intval( $T );
|
|
if( $Z > -1 ) $SEID[] = $Z;
|
|
};
|
|
$idx = 0;
|
|
$cr_cnt = 0;
|
|
$ex_cnt = 0;
|
|
foreach( $Bubbles as $B ){
|
|
if( in_array( $idx, $SEID ) ){
|
|
//check if allready exists
|
|
$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";
|
|
$J = $DATABASE->Query( $QS );
|
|
if( count( $J ) == 0 ){
|
|
$QS="INSERT INTO `target_bubbles`(`CENTER_X`,`CENTER_Y`,`CENTER_Z`,`BOUNDARY`,`BLOCK_COUNS`) VALUES({$B['x']},{$B['y']},{$B['z']},{$BS},255)";
|
|
$cr_cnt++;
|
|
$DATABASE->Query( $QS );
|
|
} else $ex_cnt++;
|
|
};
|
|
$idx++;
|
|
};
|
|
$Data['msg'] = "<center>Created {$cr_cnt} Permanent Bubble(s)<br/>{$ex_cnt} Permanent Bubbles already Existed on Same Place(s)</center>";
|
|
};
|
|
} else {
|
|
$Data['msg']='No Target to Analyze!';
|
|
};
|
|
};
|
|
echo json_encode( $Data );
|
|
?>
|