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:
parent
1168fc52a5
commit
224b34d69d
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
if ( empty($_REQUEST['eid']) ) ajaxError('Event Id Not Provided');
|
||||
if ( empty($_REQUEST['fid']) ) ajaxError('Frame Id Not Provided');
|
||||
if (empty($_REQUEST['eid'])) ajaxError('Event Id Not Provided');
|
||||
if (empty($_REQUEST['fid'])) ajaxError('Frame Id Not Provided');
|
||||
|
||||
$eid = $_REQUEST['eid'];
|
||||
$fid = $_REQUEST['fid'];
|
||||
|
@ -9,32 +8,26 @@ $row = ( isset($_REQUEST['row']) ) ? $_REQUEST['row'] : '';
|
|||
$raw = isset($_REQUEST['raw']);
|
||||
$data = array();
|
||||
|
||||
// Not sure if this is required
|
||||
if ( ZM_OPT_USE_AUTH && (ZM_AUTH_RELAY == 'hashed') ) {
|
||||
$auth_hash = generateAuthHash(ZM_AUTH_HASH_IPS);
|
||||
if ( isset($_REQUEST['auth']) and ($_REQUEST['auth'] != $auth_hash) ) {
|
||||
$data['auth'] = $auth_hash;
|
||||
}
|
||||
}
|
||||
|
||||
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 ) {
|
||||
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';
|
||||
$stats = dbFetchAll($sql, NULL, array($eid, $fid));
|
||||
foreach ($stats as $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['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']) );
|
||||
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;
|
||||
|
|
|
@ -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('<tbody>');
|
||||
$j.each( statHeaderStrings, function( key ) {
|
||||
var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]);
|
||||
var tdString;
|
||||
for (const stat of stats) {
|
||||
$j.each(statHeaderStrings, function(key) {
|
||||
var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]);
|
||||
var tdString;
|
||||
|
||||
switch (stat ? key : 'n/a') {
|
||||
case 'FrameId':
|
||||
tdString = '<a href="?view=stats&eid=' + params.eid + '&fid=' + params.fid + '">' + stat[key] + '</a>';
|
||||
break;
|
||||
case 'n/a':
|
||||
tdString = 'n/a';
|
||||
break;
|
||||
default:
|
||||
tdString = stat[key];
|
||||
}
|
||||
switch (stat ? key : 'n/a') {
|
||||
case 'FrameId':
|
||||
case 'EventId':
|
||||
//tdString = '<a href="?view=stats&eid=' + params.eid + '&fid=' + params.fid + '">' + stat[key] + '</a>';
|
||||
break;
|
||||
case 'n/a':
|
||||
tdString = 'n/a';
|
||||
break;
|
||||
default:
|
||||
tdString = stat[key];
|
||||
}
|
||||
|
||||
var td = $j('<td>').html(tdString);
|
||||
var row = $j('<tr>').append(th, td);
|
||||
var td = $j('<td>').html(tdString);
|
||||
var row = $j('<tr>').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);
|
||||
|
|
Loading…
Reference in New Issue