insert frame stats into frame view

This commit is contained in:
Andrew Bauer 2020-12-13 13:20:26 -06:00
parent 71d1607f69
commit c24564e0cd
4 changed files with 65 additions and 3 deletions

View File

@ -6,6 +6,7 @@ if ( empty($_REQUEST['fid']) ) ajaxError('Frame Id Not Provided');
$eid = $_REQUEST['eid'];
$fid = $_REQUEST['fid'];
$row = ( isset($_REQUEST['row']) ) ? $_REQUEST['row'] : '';
$raw = isset($_REQUEST['raw']);
$data = array();
// Not sure if this is required
@ -16,8 +17,28 @@ if ( ZM_OPT_USE_AUTH && (ZM_AUTH_RELAY == 'hashed') ) {
}
}
$data['html'] = getStatsTableHTML($eid, $fid, $row);
$data['id'] = '#contentStatsTable' .$row;
if ( $raw ) {
$sql = 'SELECT S.*,E.*,Z.Name AS ZoneName,Z.Units,Z.Area,M.Name AS MonitorName FROM Stats AS S LEFT JOIN Events AS E ON S.EventId = E.Id LEFT JOIN Zones AS Z ON S.ZoneId = Z.Id LEFT JOIN Monitors AS M ON E.MonitorId = M.Id WHERE S.EventId = ? AND S.FrameId = ? ORDER BY S.ZoneId';
$stat = dbFetchOne( $sql, NULL, array( $eid, $fid ) );
if ( $stat ) {
$stat['ZoneName'] = validHtmlStr($stat['ZoneName']);
$stat['PixelDiff'] = validHtmlStr($stat['PixelDiff']);
$stat['AlarmPixels'] = sprintf( "%d (%d%%)", $stat['AlarmPixels'], (100*$stat['AlarmPixels']/$stat['Area']) );
$stat['FilterPixels'] = sprintf( "%d (%d%%)", $stat['FilterPixels'], (100*$stat['FilterPixels']/$stat['Area']) );
$stat['BlobPixels'] = sprintf( "%d (%d%%)", $stat['BlobPixels'], (100*$stat['BlobPixels']/$stat['Area']) );
$stat['Blobs'] = validHtmlStr($stat['Blobs']);
if ( $stat['Blobs'] > 1 ) {
$stat['BlobSizes'] = sprintf( "%d-%d (%d%%-%d%%)", $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$stat['Area']), (100*$stat['MaxBlobSize']/$stat['Area']) );
} else {
$stat['BlobSizes'] = sprintf( "%d (%d%%)", $stat['MinBlobSize'], 100*$stat['MinBlobSize']/$stat['Area'] );
}
$stat['AlarmLimits'] = validHtmlStr($stat['MinX'].",".$stat['MinY']."-".$stat['MaxX'].",".$stat['MaxY']);
}
$data['raw'] = $stat;
} else {
$data['html'] = getStatsTableHTML($eid, $fid, $row);
$data['id'] = '#contentStatsTable' .$row;
}
ajaxResponse($data);
return;

View File

@ -103,7 +103,14 @@ xhtmlHeaders(__FILE__, translate('Frame').' - '.$Event->Id().' - '.$Frame->Frame
</form>
</div>
<div id="content">
<div id="content" class="d-flex flex-row justify-content-center">
<table id="frameStatsTable" class="table-sm table-borderless pr-3">
<!-- FRAME STATISTICS POPULATED BY AJAX -->
</table>
<div>
<p id="image">
<?php if ( $imageData['hasAnalImage'] ) {
echo sprintf('<a href="?view=frame&amp;eid=%d&amp;fid=%d&scale=%d&amp;show=%s">', $Event->Id(), $Frame->FrameId(), $scale, ( $show=='anal'?'capt':'anal' ) );
@ -152,6 +159,7 @@ if ( file_exists($rImagePath) ) {
class="<?php echo $imageData['imageClass'] ?>"
/>
</p>
</div>
<?php } ?>
</div>
</div>

View File

@ -40,6 +40,24 @@ document.addEventListener('DOMContentLoaded', function onDCL() {
document.getElementById('scaleControl').addEventListener('change', changeScale);
});
function getStat(params) {
$j.getJSON(thisUrl + '?view=request&request=stats&raw=true', params)
.done(function(data) {
var stat = data.raw;
$j('#frameStatsTable').empty().append('<tbody>');
$j.each( statHeaderStrings, function( key ) {
var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]);
var tdString = ( stat ) ? stat[key] : 'n/a';
var td = $j('<td>').text(tdString);
var row = $j('<tr>').append(th, td);
$j('#frameStatsTable tbody').append(row);
});
})
.fail(logAjaxFail);
}
function initPage() {
var backBtn = $j('#backBtn');
@ -65,6 +83,9 @@ function initPage() {
evt.preventDefault();
window.location.href = thisUrl+'?view=stats&eid='+eid+'&fid='+fid;
});
// Load the frame stats
getStat({eid:eid, fid:fid});
}
$j(document).ready(function() {

View File

@ -13,3 +13,15 @@ var eid = <?php echo $eid ?>;
var fid = <?php echo $fid ?>;
var record_event_stats = <?php echo ZM_RECORD_EVENT_STATS ?>;
var alarmFrame = <?php echo $alarmFrame ?>;
var statHeaderStrings = {};
statHeaderStrings.ZoneName = "<?php echo translate('Zone') ?>";
statHeaderStrings.PixelDiff = "<?php echo translate('PixelDiff') ?>";
statHeaderStrings.AlarmPixels = "<?php echo translate('AlarmPx') ?>";
statHeaderStrings.FilterPixels = "<?php echo translate('FilterPx') ?>";
statHeaderStrings.BlobPixels = "<?php echo translate('BlobPx') ?>";
statHeaderStrings.Blobs = "<?php echo translate('Blobs') ?>";
statHeaderStrings.BlobSizes = "<?php echo translate('BlobSizes') ?>";
statHeaderStrings.AlarmLimits = "<?php echo translate('AlarmLimits') ?>";
statHeaderStrings.Score = "<?php echo translate('Score') ?>";