Send all stats rows instead of just 1. Handle receiving all rows, and don't list event id and frame id

This commit is contained in:
Isaac Connor 2021-10-29 18:54:23 -04:00
parent bbf1269e6f
commit fa533d04ff
2 changed files with 51 additions and 54 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
if (empty($_REQUEST['eid'])) ajaxError('Event Id Not Provided');
if ( empty($_REQUEST['eid']) ) ajaxError('Event Id Not Provided'); if (empty($_REQUEST['fid'])) ajaxError('Frame Id Not Provided');
if ( empty($_REQUEST['fid']) ) ajaxError('Frame Id Not Provided');
$eid = $_REQUEST['eid']; $eid = $_REQUEST['eid'];
$fid = $_REQUEST['fid']; $fid = $_REQUEST['fid'];
@ -9,32 +8,26 @@ $row = ( isset($_REQUEST['row']) ) ? $_REQUEST['row'] : '';
$raw = isset($_REQUEST['raw']); $raw = isset($_REQUEST['raw']);
$data = array(); $data = array();
// Not sure if this is required if ($raw) {
if ( ZM_OPT_USE_AUTH && (ZM_AUTH_RELAY == 'hashed') ) { $sql = 'SELECT S.*,E.*,Z.Name AS ZoneName,Z.Units,Z.Area,M.Name AS MonitorName
$auth_hash = generateAuthHash(ZM_AUTH_HASH_IPS); 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
if ( isset($_REQUEST['auth']) and ($_REQUEST['auth'] != $auth_hash) ) { WHERE S.EventId = ? AND S.FrameId = ? ORDER BY S.ZoneId';
$data['auth'] = $auth_hash; $stats = dbFetchAll($sql, NULL, array($eid, $fid));
} foreach ($stats as $stat) {
}
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['ZoneName'] = validHtmlStr($stat['ZoneName']);
$stat['PixelDiff'] = validHtmlStr($stat['PixelDiff']); $stat['PixelDiff'] = validHtmlStr($stat['PixelDiff']);
$stat['AlarmPixels'] = sprintf( "%d (%d%%)", $stat['AlarmPixels'], (100*$stat['AlarmPixels']/$stat['Area']) ); $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['FilterPixels'] = sprintf('%d (%d%%)', $stat['FilterPixels'], (100*$stat['FilterPixels']/$stat['Area']));
$stat['BlobPixels'] = sprintf( "%d (%d%%)", $stat['BlobPixels'], (100*$stat['BlobPixels']/$stat['Area']) ); $stat['BlobPixels'] = sprintf('%d (%d%%)', $stat['BlobPixels'], (100*$stat['BlobPixels']/$stat['Area']));
$stat['Blobs'] = validHtmlStr($stat['Blobs']); $stat['Blobs'] = validHtmlStr($stat['Blobs']);
if ( $stat['Blobs'] > 1 ) { 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']) ); $stat['BlobSizes'] = sprintf('%d-%d (%d%%-%d%%)', $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$stat['Area']), (100*$stat['MaxBlobSize']/$stat['Area']));
} else { } else {
$stat['BlobSizes'] = sprintf( "%d (%d%%)", $stat['MinBlobSize'], 100*$stat['MinBlobSize']/$stat['Area'] ); $stat['BlobSizes'] = sprintf('%d (%d%%)', $stat['MinBlobSize'], 100*$stat['MinBlobSize']/$stat['Area']);
} }
$stat['AlarmLimits'] = validHtmlStr($stat['MinX'].",".$stat['MinY']."-".$stat['MaxX'].",".$stat['MaxY']); $stat['AlarmLimits'] = validHtmlStr($stat['MinX'].','.$stat['MinY'].'-'.$stat['MaxX'].','.$stat['MaxY']);
} $data['raw'][] = $stat;
$data['raw'] = $stat; } # end foreach stat/zone
} else { } else {
$data['html'] = getStatsTableHTML($eid, $fid, $row); $data['html'] = getStatsTableHTML($eid, $fid, $row);
$data['id'] = '#contentStatsTable' .$row; $data['id'] = '#contentStatsTable' .$row;

View File

@ -12,10 +12,10 @@ function changeScale() {
last: $j('#lastLink') last: $j('#lastLink')
}; };
if ( img ) { if (img) {
var baseWidth = $j('#base_width').val(); var baseWidth = $j('#base_width').val();
var baseHeight = $j('#base_height').val(); var baseHeight = $j('#base_height').val();
if ( ! parseInt(scale) ) { if (!parseInt(scale)) {
var newSize = scaleToFit(baseWidth, baseHeight, img, $j('#controls')); var newSize = scaleToFit(baseWidth, baseHeight, img, $j('#controls'));
newWidth = newSize.width; newWidth = newSize.width;
newHeight = newSize.height; newHeight = newSize.height;
@ -30,7 +30,7 @@ function changeScale() {
} }
setCookie('zmWatchScale', scale, 3600); setCookie('zmWatchScale', scale, 3600);
$j.each(controlsLinks, function(k, anchor) { //Make frames respect scale choices $j.each(controlsLinks, function(k, anchor) { //Make frames respect scale choices
if ( anchor ) { if (anchor) {
anchor.prop('href', anchor.prop('href').replace(/scale=.*&/, 'scale=' + scale + '&')); anchor.prop('href', anchor.prop('href').replace(/scale=.*&/, 'scale=' + scale + '&'));
} }
}); });
@ -39,11 +39,11 @@ function changeScale() {
onStatsResize(newWidth); onStatsResize(newWidth);
} }
function getFrmStatsCookie() { function getFrameStatsCookie() {
var cookie = 'zmFrameStats'; var cookie = 'zmFrameStats';
var stats = getCookie(cookie); var stats = getCookie(cookie);
if ( !stats ) { if (!stats) {
stats = 'on'; stats = 'on';
setCookie(cookie, stats, 10*365); setCookie(cookie, stats, 10*365);
} }
@ -53,16 +53,19 @@ function getFrmStatsCookie() {
function getStat(params) { function getStat(params) {
$j.getJSON(thisUrl + '?view=request&request=stats&raw=true', params) $j.getJSON(thisUrl + '?view=request&request=stats&raw=true', params)
.done(function(data) { .done(function(data) {
var stat = data.raw; var stats = data.raw;
$j('#frameStatsTable').empty().append('<tbody>'); $j('#frameStatsTable').empty().append('<tbody>');
$j.each( statHeaderStrings, function( key ) { for (const stat of stats) {
$j.each(statHeaderStrings, function(key) {
var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]); var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]);
var tdString; var tdString;
switch (stat ? key : 'n/a') { switch (stat ? key : 'n/a') {
case 'FrameId': case 'FrameId':
tdString = '<a href="?view=stats&amp;eid=' + params.eid + '&amp;fid=' + params.fid + '">' + stat[key] + '</a>'; case 'EventId':
//tdString = '<a href="?view=stats&amp;eid=' + params.eid + '&amp;fid=' + params.fid + '">' + stat[key] + '</a>';
break; break;
case 'n/a': case 'n/a':
tdString = 'n/a'; tdString = 'n/a';
@ -76,6 +79,7 @@ function getStat(params) {
$j('#frameStatsTable tbody').append(row); $j('#frameStatsTable tbody').append(row);
}); });
} // end foreach stat
}) })
.fail(logAjaxFail); .fail(logAjaxFail);
} }
@ -85,16 +89,16 @@ function onStatsResize(vidwidth) {
var width = $j(window).width() - vidwidth; var width = $j(window).width() - vidwidth;
// Hide the stats table if we have run out of room to show it properly // Hide the stats table if we have run out of room to show it properly
if ( width < minWidth ) { if (width < minWidth) {
statsBtn.prop('disabled', true); statsBtn.prop('disabled', true);
if ( table.is(':visible') ) { if (table.is(':visible')) {
table.toggle(false); table.toggle(false);
wasHidden = true; wasHidden = true;
} }
// Show the stats table if we hid it previously and sufficient room becomes available // Show the stats table if we hid it previously and sufficient room becomes available
} else if ( width >= minWidth ) { } else if (width >= minWidth) {
statsBtn.prop('disabled', false); statsBtn.prop('disabled', false);
if ( !table.is(':visible') && wasHidden ) { if (!table.is(':visible') && wasHidden) {
table.toggle(true); table.toggle(true);
wasHidden = false; wasHidden = false;
} }
@ -102,7 +106,7 @@ function onStatsResize(vidwidth) {
} }
function initPage() { function initPage() {
if ( scale == '0' || scale == 'auto' ) changeScale(); if (scale == '0' || scale == 'auto') changeScale();
// Don't enable the back button if there is no previous zm page to go back to // Don't enable the back button if there is no previous zm page to go back to
backBtn.prop('disabled', !document.referrer.length); backBtn.prop('disabled', !document.referrer.length);
@ -125,7 +129,7 @@ function initPage() {
var cookie = 'zmFrameStats'; var cookie = 'zmFrameStats';
// Toggle the visiblity of the stats table and write an appropriate cookie // Toggle the visiblity of the stats table and write an appropriate cookie
if ( table.is(':visible') ) { if (table.is(':visible')) {
setCookie(cookie, 'off', 10*365); setCookie(cookie, 'off', 10*365);
table.toggle(false); table.toggle(false);
} else { } else {
@ -143,7 +147,7 @@ function initPage() {
// Load the frame stats // Load the frame stats
getStat({eid: eid, fid: fid}); getStat({eid: eid, fid: fid});
if ( getFrmStatsCookie() != 'on' ) { if (getFrameStatsCookie() != 'on') {
table.toggle(false); table.toggle(false);
} else { } else {
onStatsResize($j('#base_width').val() * scale / SCALE_BASE); onStatsResize($j('#base_width').val() * scale / SCALE_BASE);