From fa533d04fff55404b63b7b32b12bdb34b150146d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 29 Oct 2021 18:54:23 -0400 Subject: [PATCH] Send all stats rows instead of just 1. Handle receiving all rows, and don't list event id and frame id --- web/ajax/stats.php | 41 ++++++++---------- web/skins/classic/views/js/frame.js | 64 +++++++++++++++-------------- 2 files changed, 51 insertions(+), 54 deletions(-) diff --git a/web/ajax/stats.php b/web/ajax/stats.php index 06ce9d733..9226814b4 100644 --- a/web/ajax/stats.php +++ b/web/ajax/stats.php @@ -1,7 +1,6 @@ 1 ) { - $stat['BlobSizes'] = sprintf( "%d-%d (%d%%-%d%%)", $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$stat['Area']), (100*$stat['MaxBlobSize']/$stat['Area']) ); + 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['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; + $stat['AlarmLimits'] = validHtmlStr($stat['MinX'].','.$stat['MinY'].'-'.$stat['MaxX'].','.$stat['MaxY']); + $data['raw'][] = $stat; + } # end foreach stat/zone } else { $data['html'] = getStatsTableHTML($eid, $fid, $row); $data['id'] = '#contentStatsTable' .$row; diff --git a/web/skins/classic/views/js/frame.js b/web/skins/classic/views/js/frame.js index c10b6e87a..1040d5a48 100644 --- a/web/skins/classic/views/js/frame.js +++ b/web/skins/classic/views/js/frame.js @@ -12,10 +12,10 @@ function changeScale() { last: $j('#lastLink') }; - if ( img ) { + if (img) { var baseWidth = $j('#base_width').val(); var baseHeight = $j('#base_height').val(); - if ( ! parseInt(scale) ) { + if (!parseInt(scale)) { var newSize = scaleToFit(baseWidth, baseHeight, img, $j('#controls')); newWidth = newSize.width; newHeight = newSize.height; @@ -30,7 +30,7 @@ function changeScale() { } setCookie('zmWatchScale', scale, 3600); $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 + '&')); } }); @@ -39,11 +39,11 @@ function changeScale() { onStatsResize(newWidth); } -function getFrmStatsCookie() { +function getFrameStatsCookie() { var cookie = 'zmFrameStats'; var stats = getCookie(cookie); - if ( !stats ) { + if (!stats) { stats = 'on'; setCookie(cookie, stats, 10*365); } @@ -53,29 +53,33 @@ function getFrmStatsCookie() { function getStat(params) { $j.getJSON(thisUrl + '?view=request&request=stats&raw=true', params) .done(function(data) { - var stat = data.raw; + var stats = data.raw; + $j('#frameStatsTable').empty().append(''); - $j.each( statHeaderStrings, function( key ) { - var th = $j('').addClass('text-right').text(statHeaderStrings[key]); - var tdString; + for (const stat of stats) { + $j.each(statHeaderStrings, function(key) { + var th = $j('').addClass('text-right').text(statHeaderStrings[key]); + var tdString; - switch (stat ? key : 'n/a') { - case 'FrameId': - tdString = '' + stat[key] + ''; - break; - case 'n/a': - tdString = 'n/a'; - break; - default: - tdString = stat[key]; - } + switch (stat ? key : 'n/a') { + case 'FrameId': + case 'EventId': + //tdString = '' + stat[key] + ''; + break; + case 'n/a': + tdString = 'n/a'; + break; + default: + tdString = stat[key]; + } - var td = $j('').html(tdString); - var row = $j('').append(th, td); + var td = $j('').html(tdString); + var row = $j('').append(th, td); - $j('#frameStatsTable tbody').append(row); - }); + $j('#frameStatsTable tbody').append(row); + }); + } // end foreach stat }) .fail(logAjaxFail); } @@ -85,16 +89,16 @@ function onStatsResize(vidwidth) { var width = $j(window).width() - vidwidth; // 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); - if ( table.is(':visible') ) { + if (table.is(':visible')) { table.toggle(false); wasHidden = true; } // 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); - if ( !table.is(':visible') && wasHidden ) { + if (!table.is(':visible') && wasHidden) { table.toggle(true); wasHidden = false; } @@ -102,7 +106,7 @@ function onStatsResize(vidwidth) { } 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 backBtn.prop('disabled', !document.referrer.length); @@ -125,7 +129,7 @@ function initPage() { var cookie = 'zmFrameStats'; // 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); table.toggle(false); } else { @@ -143,7 +147,7 @@ function initPage() { // Load the frame stats getStat({eid: eid, fid: fid}); - if ( getFrmStatsCookie() != 'on' ) { + if (getFrameStatsCookie() != 'on') { table.toggle(false); } else { onStatsResize($j('#base_width').val() * scale / SCALE_BASE);