fix: correct stats percentage calculations for percentage-space zone area
The stats display was dividing pixel counts by the zone Area value directly, but Area is stored in percentage coordinate space (0-10000 for full frame). Convert Area to actual pixel area using the monitor dimensions before calculating percentages. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>pull/4704/head
parent
fc3eed8fab
commit
2874751c72
|
|
@ -1619,7 +1619,7 @@ function getStatsTableHTML($eid, $fid, $row='') {
|
|||
if ( !canView('Events') ) return;
|
||||
$result = '';
|
||||
|
||||
$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';
|
||||
$sql = 'SELECT S.*,E.*,Z.Name AS ZoneName,Z.Units,Z.Area,Z.Coords,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 = ? AND S.FrameId = ? ORDER BY S.ZoneId';
|
||||
$stats = dbFetchAll( $sql, NULL, array( $eid, $fid ) );
|
||||
|
||||
$result .= '<table id="contentStatsTable' .$row. '"'.PHP_EOL;
|
||||
|
|
@ -1648,18 +1648,23 @@ function getStatsTableHTML($eid, $fid, $row='') {
|
|||
|
||||
if ( count($stats) ) {
|
||||
foreach ( $stats as $stat ) {
|
||||
// Area is in percentage coordinate space (0-10000 for full frame).
|
||||
// Convert to pixel area for percentage calculations since Stats values are pixel counts.
|
||||
$pixelArea = $stat['Area'] / 10000.0 * $stat['Width'] * $stat['Height'];
|
||||
if ($pixelArea <= 0) $pixelArea = 1; // avoid division by zero
|
||||
|
||||
$result .= '<tr>'.PHP_EOL;
|
||||
$result .= '<td class="colZone">' .validHtmlStr($stat['ZoneName']). '</td>'.PHP_EOL;
|
||||
$result .= '<td class="colPixelDiff">' .validHtmlStr($stat['PixelDiff']). '</td>'.PHP_EOL;
|
||||
$result .= '<td class="colAlarmPx">' .sprintf( "%d (%d%%)", $stat['AlarmPixels'], (100*$stat['AlarmPixels']/$stat['Area']) ). '</td>'.PHP_EOL;
|
||||
$result .= '<td class="colFilterPx">' .sprintf( "%d (%d%%)", $stat['FilterPixels'], (100*$stat['FilterPixels']/$stat['Area']) ).'</td>'.PHP_EOL;
|
||||
$result .= '<td class="colBlobPx">' .sprintf( "%d (%d%%)", $stat['BlobPixels'], (100*$stat['BlobPixels']/$stat['Area']) ). '</td>'.PHP_EOL;
|
||||
$result .= '<td class="colAlarmPx">' .sprintf( "%d (%d%%)", $stat['AlarmPixels'], (100*$stat['AlarmPixels']/$pixelArea) ). '</td>'.PHP_EOL;
|
||||
$result .= '<td class="colFilterPx">' .sprintf( "%d (%d%%)", $stat['FilterPixels'], (100*$stat['FilterPixels']/$pixelArea) ).'</td>'.PHP_EOL;
|
||||
$result .= '<td class="colBlobPx">' .sprintf( "%d (%d%%)", $stat['BlobPixels'], (100*$stat['BlobPixels']/$pixelArea) ). '</td>'.PHP_EOL;
|
||||
$result .= '<td class="colBlobs">' .validHtmlStr($stat['Blobs']). '</td>'.PHP_EOL;
|
||||
|
||||
|
||||
if ( $stat['Blobs'] > 1 ) {
|
||||
$result .= '<td class="colBlobSizes">' .sprintf( "%d-%d (%d%%-%d%%)", $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$stat['Area']), (100*$stat['MaxBlobSize']/$stat['Area']) ). '</td>'.PHP_EOL;
|
||||
$result .= '<td class="colBlobSizes">' .sprintf( "%d-%d (%d%%-%d%%)", $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$pixelArea), (100*$stat['MaxBlobSize']/$pixelArea) ). '</td>'.PHP_EOL;
|
||||
} else {
|
||||
$result .= '<td class="colBlobSizes">' .sprintf( "%d (%d%%)", $stat['MinBlobSize'], 100*$stat['MinBlobSize']/$stat['Area'] ). '</td>'.PHP_EOL;
|
||||
$result .= '<td class="colBlobSizes">' .sprintf( "%d (%d%%)", $stat['MinBlobSize'], 100*$stat['MinBlobSize']/$pixelArea ). '</td>'.PHP_EOL;
|
||||
}
|
||||
|
||||
$result .= '<td class="colAlarmLimits">' .validHtmlStr($stat['MinX'].",".$stat['MinY']."-".$stat['MaxX'].",".$stat['MaxY']). '</td>'.PHP_EOL;
|
||||
|
|
|
|||
Loading…
Reference in New Issue