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.
 
 
 
 

115 lines
3.8 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'] );
$Data = array( 'status'=>'nok', 'msg'=>'Access Denied!' );
$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( '/srv/www/web/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';
unset( $Data['msg'] );
$Data['bubbles'] = array();
$idx = 0;
foreach( $Bubbles as $B ){
$CR['id'] = $idx;
$CR['range'] = sprintf( "%0.2f", $B['range'] );
$CR['az'] = sprintf( "%0.2f", $B['az'] );
$CR['el'] = sprintf( "%0.2f", $B['el']);
$CD = sqrt( pow( $B['x'], 2 )+pow( $B['y'], 2 )+pow( $B['z'], 2 ) );
$CR['r'] = intval( ( $CD * 2048.0)/ 65.0 );
$CR['x'] = $B['x'];
$CR['y'] = $B['y'];
$CR['z'] = $B['z'];
$CR['count'] = $B['count'];
$Data['bubbles'][] = $CR;
$idx++;
};
};
} else {
$Data['msg']='No Target to Analyze!';
};
};
echo json_encode( $Data );
?>