View stats on frame view

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
schuitz
Posts: 11
Joined: Thu Jun 01, 2006 11:26 pm

View stats on frame view

Post by schuitz »

Maybe it's nitpicky, but on my rig I integrated zm_html_view_stats.php into zm_html_view_frame.php so I don't have to click the stats link and get yet another window when I want to see my alarm statistics.

I also moved the test:

Code: Select all

<?php if ( ZM_RECORD_EVENT_STATS && $alarm_frame ) { ?>
to below the last </table> tag of _view_frame.php, since there is no point of having a link for stats up at the top now. The test is now whether to display a stats table underneath the image or not.

It's a straightforward cut and paste of the SQL query php and stats table html, but if anyone else would like this, I can post it up.
Cheers
MikeS
Last edited by schuitz on Sun Jun 11, 2006 1:05 pm, edited 2 times in total.
unclerichy
Posts: 74
Joined: Wed Feb 25, 2004 5:06 pm

Post by unclerichy »

That would be handy. Post away! :D
schuitz
Posts: 11
Joined: Thu Jun 01, 2006 11:26 pm

Post by schuitz »

OK, here is the modified zm_html_view_frame.php, which integrates the statistics table:

Code: Select all

<?php
//
// ZoneMinder web frame view file, $Date: 2006/04/24 11:50:02 $, $Revision: 1.27 $
// Copyright (C) 2003, 2004, 2005, 2006  Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//

error_reporting( E_ALL );
if ( !canView( 'Events' ) )
{
	$view = "error";
	return;
}
$sql = "select E.*,M.Name as MonitorName,M.Width,M.Height,M.DefaultScale from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'";
$result = mysql_query( $sql );
if ( !$result )
	die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );

if ( $fid )
{
	$result = mysql_query( "select * from Frames where EventId = '$eid' and FrameId = '$fid'" );
	if ( !$result )
		die( mysql_error() );
	$frame = mysql_fetch_assoc( $result );
	mysql_free_result( $result );
}
else
{
	$result = mysql_query( "select * from Frames where EventId = '$eid' and Score = '".$event['MaxScore']."'" );
	if ( !$result )
		die( mysql_error() );
	$frame = mysql_fetch_assoc( $result );
	mysql_free_result( $result );
	$fid = $frame['FrameId'];
}

$max_fid = $event['Frames'];

$first_fid = 1;
$prev_fid = $fid-1;
$next_fid = $fid+1;
$last_fid = $max_fid;

$alarm_frame = $frame['Type']=='Alarm';

if ( !isset( $scale ) )
	$scale = max( reScale( SCALE_BASE, $event['DefaultScale'], ZM_WEB_DEFAULT_SCALE ), SCALE_BASE );

$image_data = getImageSrc( $event, $frame, $scale, (isset($show)&&$show=="capt") );

$image_path = $image_data['thumbPath'];
$event_path = $image_data['eventPath'];
$d_image_path = sprintf( "%s/%0".ZM_EVENT_IMAGE_DIGITS."d-diag-d.jpg", $event_path, $fid );
$r_image_path = sprintf( "%s/%0".ZM_EVENT_IMAGE_DIGITS."d-diag-r.jpg", $event_path, $fid );



// pasted this in from zm_html_view_stats.php
// why not show the stats right in the frame view?

$result = mysql_query( "select S.*,E.*,Z.Name as ZoneName,Z.Units,Z.Area,M.Name as MonitorName,M.Width,M.Height 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 = '$eid' and S.FrameId = '$fid' order by S.ZoneId" );
if ( !$result )
        die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{
        $stats[] = $row;
}
mysql_free_result( $result );





?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?= ZM_WEB_TITLE_PREFIX ?> - <?= $zmSlangFrame ?> <?= $eid."-".$fid ?></title>
<link rel="stylesheet" href="zm_html_styles.css" type="text/css">
<script type="text/javascript">
window.focus();
function newWindow(Url,Name,Width,Height)
{
   	var Win = window.open(Url,Name,"resizable,scrollbars,width="+Width+",height="+Height);
}
function closeWindow()
{
	window.close();
}
function deleteEvent()
{
	location.href = "<?= $PHP_SELF ?>?view=none&action=delete&mark_eid=<?= $eid ?>";
	//window.close();
}
</script>
</head>
<body>
<table width="96%" cellpadding="3" cellspacing="0" border="0">
<tr>
<td width="60%" class="smallhead"><?= $zmSlangFrame ?> <?= $eid."-".$fid." (".$frame['Score'].")" ?>
</td>
<td width="20%" align="center" class="text"><?php if ( canEdit( 'Events' ) ) { ?><a href="javascript: deleteEvent();"><?= $zmSlangDelete ?></a><?php } else { ?>&nbsp<?php } ?></td>
<td width="20%" align="right" class="text"><a href="javascript: closeWindow();"><?= $zmSlangClose ?></a></td>
</tr>
<tr>
<td colspan="3" align="center"><?php if ( $image_data['hasAnalImage'] ) { ?><a href="<?= $PHP_SELF ?>?view=frame&eid=<?= $eid ?>&fid=<?= $fid ?>&scale=<?= $scale ?>&show=<?= $image_data['isAnalImage']?"capt":"anal" ?>"><?php } ?><img src="<?= $image_path ?>" width="<?= reScale( $event['Width'], $event['DefaultScale'], $scale ) ?>" height="<?= reScale( $event['Height'], $event['DefaultScale'], $scale ) ?>" class="<?= $image_data['imageClass'] ?>"><?php if ( $image_data['hasAnalImage'] ) { ?></a><?php } ?></td>
</tr>
<tr>
<td colspan="3" align="center"><table width="96%" cellpadding="0" cellspacing="0" border="0"><tr>
<?php if ( $fid > 1 ) { ?>
<td align="center" width="25%" class="text"><a href="<?= $PHP_SELF ?>?view=frame&eid=<?= $eid ?>&fid=<?= $first_fid ?>&scale=<?= $scale ?>"><?= $zmSlangFirst ?></a></td>
<?php } else { ?>
<td align="center" width="25%" class="text">&nbsp;</td>
<?php } if ( $fid > 1 ) { ?>
<td align="center" width="25%" class="text"><a href="<?= $PHP_SELF ?>?view=frame&eid=<?= $eid ?>&fid=<?= $prev_fid ?>&scale=<?= $scale ?>"><?= $zmSlangPrev ?></a></td>
<?php } else { ?>
<td align="center" width="25%" class="text">&nbsp;</td>
<?php } if ( $fid < $max_fid ) { ?>
<td align="center" width="25%" class="text"><a href="<?= $PHP_SELF ?>?view=frame&eid=<?= $eid ?>&fid=<?= $next_fid ?>&scale=<?= $scale ?>"><?= $zmSlangNext ?></a></td>
<?php } else { ?>
<td align="center" width="25%" class="text">&nbsp;</td>
<?php } if ( $fid < $max_fid ) { ?>
<td align="center" width="25%" class="text"><a href="<?= $PHP_SELF ?>?view=frame&eid=<?= $eid ?>&fid=<?= $last_fid ?>&scale=<?= $scale ?>"><?= $zmSlangLast ?></a></td>
<?php } else { ?>
<td align="center" width="25%" class="text">&nbsp;</td>
<?php } ?>
</tr>
</table></td></tr>
<?php if (file_exists ($d_image_path)) { ?>
<tr><td colspan="3"><?= $d_image_path ?></tr>
<tr><td colspan="3"><img src="<?= $d_image_path ?>" width="<?= reScale( $event['Width'], $event['DefaultScale'], $scale ) ?>" height="<?= reScale( $event['He
ight'], $event['DefaultScale'], $scale ) ?>" class="<?= $image_data['imageClass'] ?>"></td></tr>
<?php } ?>
<?php if (file_exists ($r_image_path)) { ?>
<tr><td colspan="3"><?= $r_image_path ?></tr>
<tr><td colspan="3"><img src="<?= $r_image_path ?>" width="<?= reScale( $event['Width'], $event['DefaultScale'], $scale ) ?>" height="<?= reScale( $event['He
ight'], $event['DefaultScale'], $scale ) ?>" class="<?= $image_data['imageClass'] ?>"></td></tr>
<?php } ?>
</table>


<?php if ( ZM_RECORD_EVENT_STATS && $alarm_frame ) { ?>
<table align="center" width="96%" border="0">
<tr>
<td align="left" class="smallhead"><b><?= $zmSlangFrame ?> <?= $eid."-".$fid ?></b></td>
<td align="right" class="text"><a href="javascript: closeWindow();"><?= $zmSlangClose ?></a></td>
</tr>
<tr><td colspan="2"><table width="100%" border="0" bgcolor="#7F7FB2" cellpadding="3" cellspacing="1"><tr bgcolor="#FFFFFF">
<td class="smallhead"><?= $zmSlangZone ?></td>
<td class="smallhead" align="center"><?= $zmSlangPixelDiff ?></td>
<td class="smallhead" align="center"><?= $zmSlangAlarmPx ?></td>
<td class="smallhead" align="center"><?= $zmSlangFilterPx ?></td>
<td class="smallhead" align="center"><?= $zmSlangBlobPx ?></td>
<td class="smallhead" align="center"><?= $zmSlangBlobs ?></td>
<td class="smallhead" align="center"><?= $zmSlangBlobSizes ?></td>
<td class="smallhead" align="center"><?= $zmSlangAlarmLimits ?></td>
<td class="smallhead" align="center"><?= $zmSlangScore ?></td>
</tr>
<?php
if ( count($stats) )
{
	foreach ( $stats as $stat )
	{
?>
<tr bgcolor="#FFFFFF">
<td class="text"><?= $stat['ZoneName'] ?></td>
<td class="text" align="center"><?= $stat['PixelDiff'] ?></td>
<td class="text" align="center"><?= sprintf( "%d (%d%%)", $stat['AlarmPixels'], (100*$stat['AlarmPixels']/$stat['Area']) ) ?></td>
<td class="text" align="center"><?= sprintf( "%d (%d%%)", $stat['FilterPixels'], (100*$stat['FilterPixels']/$stat['Area']) ) ?></td>
<td class="text" align="center"><?= sprintf( "%d (%d%%)", $stat['BlobPixels'], (100*$stat['BlobPixels']/$stat['Area']) ) ?></td>
<td class="text" align="center"><?= $stat['Blobs'] ?></td>
<?php
if ( $stat['Blobs'] > 1 )
{
?>
<td class="text" align="center"><?= sprintf( "%d-%d (%d%%-%d%%)", $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$stat['Area']), (100*$stat['MaxBlobSize']/$stat['Area']) ) ?></td>
<?php
}
else
{
?>
<td class="text" align="center"><?= sprintf( "%d (%d%%)", $stat['MinBlobSize'], 100*$stat['MinBlobSize']/$stat['Area'] ) ?></td>
<?php
}
?>
<td class="text" align="center"><?= $stat['MinX'].",".$stat['MinY']."-".$stat['MaxX'].",".$stat['MaxY'] ?></td>
<td class="text" align="center"><?= $stat['Score'] ?></td>
</tr>
<?php
	}
}
else
{
?>
<tr bgcolor="#FFFFFF">
<td class="text" colspan="8" align="center"><br><?= $zmSlangNoStatisticsRecorded ?><br><br></td>
</tr>
<?php
}
?>
</table></td>
</tr>
</table>
<?php } ?>
</body>
</html>
I also hacked zm_html_view_event.php slightly so I don't have to resize the frame view window to see the stats:

Code: Select all

<a href="javascript: newWindow( '<?= $PHP_SELF ?>?view=frame&eid=<?= $eid ?>&fid=<?= $frame['FrameId'] ?>&scale=<?= $scale ?>', 'zmImage', <?= reScale( $event['Width'], $scale )+$jws['image']['w']  ?>, <?= reScale( $event['Height'], $scale )+$jws['image']['h']+100 ?> );"><img src="<?= $image_data['thumbPath'] ?>" width="<?= $thumb_width ?>" height="<?= $thumb_height ?>" class="<?= $image_data['imageClass'] ?>" alt="<?= $frame['FrameId'] ?>/<?= $frame['Type']=='alarm'?$frame['Score']:0 ?>"></a>
It's pretty shameful, I just added 100 to the height for the appropriate call to newWindow. I'm quite sure there's a more intelligent way to do it. But it works fine.

Back up your originals, in case something goes wonky.
MikeS
Post Reply