more fixes

This commit is contained in:
Isaac Connor 2017-07-04 11:51:23 -04:00
parent 892f3a06c7
commit f87a89a5ce
2 changed files with 111 additions and 88 deletions

View File

@ -88,14 +88,18 @@ function loadImage2Monitor(monId,url) {
} else { } else {
if ( monitorImageObject[monId].src == url ) return; // do nothing if it's the same if ( monitorImageObject[monId].src == url ) return; // do nothing if it's the same
if ( url == 'no data' ) { if ( url == 'no data' ) {
monitorCanvasCtx[monId].fillStyle="white"; if ( ! monitorCanvasCtx[monId] ) {
monitorCanvasCtx[monId].fillRect(0,0,monitorCanvasObj[monId].width,monitorCanvasObj[monId].height); alert("No ctx for " + monId);
var textSize=monitorCanvasObj[monId].width * 0.15; } else {
var text="No Data"; monitorCanvasCtx[monId].fillStyle="white";
monitorCanvasCtx[monId].font = "600 " + textSize.toString() + "px Arial"; monitorCanvasCtx[monId].fillRect(0,0,monitorCanvasObj[monId].width,monitorCanvasObj[monId].height);
monitorCanvasCtx[monId].fillStyle="black"; var textSize=monitorCanvasObj[monId].width * 0.15;
var textWidth = monitorCanvasCtx[monId].measureText(text).width; var text="No Data";
monitorCanvasCtx[monId].fillText(text,monitorCanvasObj[monId].width/2 - textWidth/2,monitorCanvasObj[monId].height/2); monitorCanvasCtx[monId].font = "600 " + textSize.toString() + "px Arial";
monitorCanvasCtx[monId].fillStyle="black";
var textWidth = monitorCanvasCtx[monId].measureText(text).width;
monitorCanvasCtx[monId].fillText(text,monitorCanvasObj[monId].width/2 - textWidth/2,monitorCanvasObj[monId].height/2);
}
} else { } else {
monitorLoading[monId]=true; monitorLoading[monId]=true;
monitorLoadStartTimems[monId]=new Date().getTime(); monitorLoadStartTimems[monId]=new Date().getTime();
@ -655,38 +659,42 @@ function maxfit2(divW, divH)
// >>>>>>>>>>>>>>>> Handles individual monitor clicks and navigation to the standard event/watch display // >>>>>>>>>>>>>>>> Handles individual monitor clicks and navigation to the standard event/watch display
function showOneMonitor(monId) // link out to the normal view of one event's data function showOneMonitor(monId) {
{ // link out to the normal view of one event's data
// We know the monitor, need to determine the event based on current time // We know the monitor, need to determine the event based on current time
var url; var url;
if(liveMode!=0) url="?view=watch&mid=" + monId.toString(); if ( liveMode != 0 )
else url="?view=watch&mid=" + monId.toString();
for(var i=0; i<eId.length; i++) else
if(eMonId[i]==monId && currentTimeSecs >= eStartSecs[i] && currentTimeSecs <= eEndSecs[i]) for ( var i=0, len=eId.length; i<len; i++ ) {
url="?view=event&eid=" + eId[i] + '&fid=' + parseInt(Math.max(1, Math.min(eventFrames[i], eventFrames[i] * (currentTimeSecs - eStartSecs[i]) / (eEndSecs[i] - eStartSecs[i] + 1) ) )); if ( eMonId[i] == monId && currentTimeSecs >= eStartSecs[i] && currentTimeSecs <= eEndSecs[i] )
url="?view=event&eid=" + eId[i] + '&fid=' + parseInt(Math.max(1, Math.min(eventFrames[i], eventFrames[i] * (currentTimeSecs - eStartSecs[i]) / (eEndSecs[i] - eStartSecs[i] + 1) ) ));
break;
}
createPopup(url, 'zmEvent', 'event', monitorWidth[eMonId[i]], monitorHeight[eMonId[i]]); createPopup(url, 'zmEvent', 'event', monitorWidth[eMonId[i]], monitorHeight[eMonId[i]]);
} }
function zoom(monId,scale) function zoom(monId,scale) {
{ var lastZoomMonPriorScale = monitorZoomScale[monId];
var lastZoomMonPriorScale=monitorZoomScale[monId]; monitorZoomScale[monId] *= scale;
monitorZoomScale[monId] *= scale; if ( redrawScreen() == 0 ) {// failure here is probably because we zoomed too far
if(redrawScreen()==0) // failure here is probably because we zoomed too far monitorZoomScale[monId] = lastZoomMonPriorScale;
{ alert("You can't zoom that far -- rolling back");
monitorZoomScale[monId]=lastZoomMonPriorScale; redrawScreen(); // put things back and hope it works
alert("You can't zoom that far -- rolling back"); }
redrawScreen(); // put things back and hope it works
}
} }
function clickMonitor(event,monId) function clickMonitor(event,monId) {
{ var monitor_element = $("Monitor"+monId.toString());
var pos_x = event.offsetX ? (event.offsetX) : event.pageX - $("Monitor"+monId.toString()).offsetLeft; var pos_x = event.offsetX ? (event.offsetX) : event.pageX - monitor_element.offsetLeft;
var pos_y = event.offsetY ? (event.offsetY) : event.pageY - $("Monitor"+monId.toString()).offsetTop; var pos_y = event.offsetY ? (event.offsetY) : event.pageY - monitor_element.offsetTop;
if(pos_x < $("Monitor"+monId.toString()).width/4 && pos_y < $("Monitor"+monId.toString()).height/4) zoom(monId,1.15); if ( pos_x < monitor_element.width/4 && pos_y < monitor_element.height/4 )
else if(pos_x > $("Monitor"+monId.toString()).width * 3/4 && pos_y < $("Monitor"+monId.toString()).height/4) zoom(monId,1/1.15); zoom(monId,1.15);
else showOneMonitor(monId); else if ( pos_x > monitor_element.width * 3/4 && pos_y < monitor_element.height/4 )
return; zoom(monId,1/1.15);
else
showOneMonitor(monId);
return;
} }
// >>>>>>>>> Initialization that runs on window load by being at the bottom // >>>>>>>>> Initialization that runs on window load by being at the bottom
@ -694,10 +702,21 @@ function clickMonitor(event,monId)
function initPage() { function initPage() {
canvas=$("timeline"); canvas=$("timeline");
ctx=canvas.getContext('2d'); ctx=canvas.getContext('2d');
for ( var i = 0; i < monitorPtr.length; i += 1 ) { for ( var i = 0, len=monitorPtr.length; i < len; i += 1 ) {
var monId = monitorPtr[i]; var monId = monitorPtr[i];
if ( ! monId ) continue;
monitorCanvasObj[monId] = $('Monitor'+monId ); monitorCanvasObj[monId] = $('Monitor'+monId );
monitorCanvasCtx[monId]=monitorCanvasObj[monId].getContext('2d'); if ( ! monitorCanvasObj[monId] ) {
alert("Couldn't find DOM element for Monitor"+monId + "monitorPtr.length="+len);
} else {
monitorCanvasCtx[monId]=monitorCanvasObj[monId].getContext('2d');
monitorImageObject[monId]=new Image();
monitorImageObject[monId].src = monitorImageURL[monId];
monitorImageObject[monId].monId = monId;
monitorImageObject[monId].onload = function() {imagedone(this, this.monId, true )};
monitorImageObject[monId].onerror = function() {imagedone(this, this.monId, false )};
}
} }
drawGraph(); drawGraph();
setSpeed(speedIndex); setSpeed(speedIndex);

View File

@ -24,8 +24,8 @@ var groupStr=<?php if($group=="") echo '""'; else echo "\"&group=$group\""; ?>;
// Because we might not have time as the criteria, figure out the min/max time when we run the query // Because we might not have time as the criteria, figure out the min/max time when we run the query
$minTimeSecs = strtotime("2036-01-01 01:01:01"); $minTimeSecs = strtotime('2036-01-01 01:01:01');
$maxTimeSecs = strtotime("1950-01-01 01:01:01"); $maxTimeSecs = strtotime('1950-01-01 01:01:01');
// This builds the list of events that are eligible from this range // This builds the list of events that are eligible from this range
@ -33,34 +33,36 @@ $index=0;
$anyAlarms=false; $anyAlarms=false;
foreach( dbFetchAll( $eventsSql ) as $event ) { foreach( dbFetchAll( $eventsSql ) as $event ) {
if( $minTimeSecs > $event['StartTimeSecs']) $minTimeSecs = $event['StartTimeSecs']; if ( $minTimeSecs > $event['StartTimeSecs'] ) $minTimeSecs = $event['StartTimeSecs'];
if( $maxTimeSecs < $event['CalcEndTimeSecs']) $maxTimeSecs = $event['CalcEndTimeSecs']; if ( $maxTimeSecs < $event['CalcEndTimeSecs'] ) $maxTimeSecs = $event['CalcEndTimeSecs'];
echo "eMonId[$index]=" . $event['MonitorId'] . "; echo "
eId[$index]=" . $event['Id'] . "; eMonId[$index]=" . $event['MonitorId'] . ";
eStartSecs[$index]=" . $event['StartTimeSecs'] . "; eId[$index]=" . $event['Id'] . ";
eEndSecs[$index]=" . $event['CalcEndTimeSecs'] . "; eStartSecs[$index]=" . $event['StartTimeSecs'] . ";
eventFrames[$index]=" . $event['Frames'] . ";\n"; eEndSecs[$index]=" . $event['CalcEndTimeSecs'] . ";
eventFrames[$index]=" . $event['Frames'] . ";
$index = $index + 1; ";
if($event['MaxScore']>0)
$anyAlarms = true; $index = $index + 1;
echo "\n"; if ( $event['MaxScore'] > 0 )
$anyAlarms = true;
} }
// if there is no data set the min/max to the passed in values // if there is no data set the min/max to the passed in values
if($index == 0) { if ( $index == 0 ) {
if(isset($minTime) && isset($maxTime)) { if ( isset($minTime) && isset($maxTime) ) {
$minTimeSecs = strtotime($minTime); $minTimeSecs = strtotime($minTime);
$maxTimeSecs = strtotime($maxTime); $maxTimeSecs = strtotime($maxTime);
} else { } else {
// this is the case of no passed in times AND no data -- just set something arbitrary // this is the case of no passed in times AND no data -- just set something arbitrary
$minTimeSecs=strtotime('1950-06-01 01:01:01'); // random time so there's something to display $minTimeSecs = strtotime('1950-06-01 01:01:01'); // random time so there's something to display
$maxTimeSecs=time() + 86400; $maxTimeSecs = time() + 86400;
} }
} }
// We only reset the calling time if there was no calling time // We only reset the calling time if there was no calling time
if(!isset($minTime) || !isset($maxTime)) { if ( !isset($minTime) || !isset($maxTime) ) {
$maxTime = strftime($maxTimeSecs); $maxTime = strftime($maxTimeSecs);
$minTime = strftime($minTimeSecs); $minTime = strftime($minTimeSecs);
} else { } else {
@ -82,42 +84,47 @@ $fromSecs=-1;
$toSecs=-1; $toSecs=-1;
$maxScore=-1; $maxScore=-1;
if($anyAlarms) { if ( $anyAlarms ) {
foreach( dbFetchAll ($frameSql) as $frame ) { foreach( dbFetchAll ($frameSql) as $frame ) {
if($mId<0) { if ( $mId < 0 ) {
$mId=$frame['MonitorId']; $mId = $frame['MonitorId'];
$fromSecs=$frame['TimeStampSecs']; $fromSecs = $frame['TimeStampSecs'];
$toSecs=$frame['TimeStampSecs']; $toSecs = $frame['TimeStampSecs'];
$maxScore=$frame['Score']; $maxScore = $frame['Score'];
} else if ($mId != $frame['MonitorId'] || $frame['TimeStampSecs'] - $toSecs > 10) { } else if ( $mId != $frame['MonitorId'] || $frame['TimeStampSecs'] - $toSecs > 10 ) {
// dump this one start a new // dump this one start a new
$index++; $index++;
echo " fMonId[$index]=" . $mId . ";"; echo "
echo " fTimeFromSecs[$index]=" . $fromSecs . ";"; fMonId[$index]= $mId;
echo " fTimeToSecs[$index]=" . $toSecs . ";"; fTimeFromSecs[$index]= $fromSecs;
echo " fScore[$index]=" . $maxScore . ";\n"; fTimeToSecs[$index]= $toSecs;
$mId=$frame['MonitorId']; fScore[$index]= $maxScore;
$fromSecs=$frame['TimeStampSecs']; ";
$toSecs=$frame['TimeStampSecs']; $mId = $frame['MonitorId'];
$maxScore=$frame['Score']; $fromSecs = $frame['TimeStampSecs'];
$toSecs = $frame['TimeStampSecs'];
$maxScore = $frame['Score'];
} else { } else {
// just add this one on // just add this one on
$toSecs=$frame['TimeStampSecs']; $toSecs = $frame['TimeStampSecs'];
if($maxScore < $frame['Score']) $maxScore=$frame['Score']; if ( $maxScore < $frame['Score'] ) $maxScore = $frame['Score'];
} }
} }
} }
if($mId>0) { if ( $mId > 0 ) {
echo " fMonId[$index]=" . $mId . ";"; echo "
echo " fTimeFromSecs[$index]=" . $fromSecs . ";"; fMonId[$index]= $mId;
echo " fTimeToSecs[$index]=" . $toSecs . ";"; fTimeFromSecs[$index]= $fromSecs;
echo " fScore[$index]=" . $maxScore . ";\n"; fTimeToSecs[$index]= $toSecs;
fScore[$index]= $maxScore;
";
} }
echo "var maxScore=$maxScore;\n"; // used to skip frame load if we find no alarms. echo "var maxScore=$maxScore;\n"; // used to skip frame load if we find no alarms.
echo "var monitorName = [];\n"; echo "var monitorName = [];\n";
echo "var monitorLoading = [];\n"; echo "var monitorLoading = [];\n";
echo "var monitorImageObject = [];\n"; echo "var monitorImageObject = [];\n";
echo "var monitorImageURL = [];\n";
echo "var monitorLoadingStageURL = [];\n"; echo "var monitorLoadingStageURL = [];\n";
echo "var monitorLoadStartTimems = [];\n"; echo "var monitorLoadStartTimems = [];\n";
echo "var monitorLoadEndTimems = [];\n"; echo "var monitorLoadEndTimems = [];\n";
@ -135,20 +142,17 @@ echo "var monitorPtr = []; // monitorName[monitorPtr[0]] is first monitor\n";
$numMonitors=0; // this array is indexed by the monitor ID for faster access later, so it may be sparse $numMonitors=0; // this array is indexed by the monitor ID for faster access later, so it may be sparse
$avgArea=floatval(0); // Calculations the normalizing scale $avgArea=floatval(0); // Calculations the normalizing scale
foreach ($monitors as $m) { foreach ( $monitors as $m ) {
$avgArea = $avgArea + floatval($m->Width() * $m->Height()); $avgArea = $avgArea + floatval($m->Width() * $m->Height());
$numMonitors++; $numMonitors++;
} }
if($numMonitors>0) $avgArea= $avgArea / $numMonitors; if ( $numMonitors > 0 ) $avgArea = $avgArea / $numMonitors;
$numMonitors=0; $numMonitors = 0;
foreach ($monitors as $m) { foreach ( $monitors as $m ) {
echo " monitorLoading[" . $m->Id() . "]=false;\n"; echo " monitorLoading[" . $m->Id() . "]=false;\n";
echo " monitorImageObject[" . $m->Id() . "]=new Image();\n"; echo " monitorImageURL[" . $m->Id() . "]='".$m->getStreamSrc( array('mode'=>'single','scale'=>$defaultScale), '&' )."';\n";
echo " monitorImageObject[" . $m->Id() . "].src='".$m->getStreamSrc( array('mode'=>'single','scale'=>$defaultScale) )."';\n";
echo " monitorImageObject[" . $m->Id() . "].onload = function() {imagedone(this, ".$m->Id().",true )};\n";
echo " monitorImageObject[" . $m->Id() . "].onerror = function() {imagedone(this, ".$m->Id().",false )};\n";
echo " monitorLoadingStageURL[" . $m->Id() . "] = '';\n"; echo " monitorLoadingStageURL[" . $m->Id() . "] = '';\n";
echo " monitorColour[" . $m->Id() . "]=\"" . $m->WebColour() . "\";\n"; echo " monitorColour[" . $m->Id() . "]=\"" . $m->WebColour() . "\";\n";
echo " monitorWidth[" . $m->Id() . "]=" . $m->Width() . ";\n"; echo " monitorWidth[" . $m->Id() . "]=" . $m->Width() . ";\n";
@ -174,13 +178,13 @@ if(isset($defaultCurrentTime))
else else
echo "var currentTimeSecs=" . ($minTimeSecs + $maxTimeSecs)/2 . ";\n"; echo "var currentTimeSecs=" . ($minTimeSecs + $maxTimeSecs)/2 . ";\n";
echo "var speeds=["; echo 'var speeds=[';
for ($i=0; $i<count($speeds); $i++) for ($i=0; $i<count($speeds); $i++)
echo (($i>0)?", ":"") . $speeds[$i]; echo (($i>0)?', ':'') . $speeds[$i];
echo "];\n"; echo "];\n";
?> ?>
var scrubAsObject=document.getElementById('scrub'); var scrubAsObject=$('scrub');
var cWidth; // save canvas width var cWidth; // save canvas width
var cHeight; // save canvas height var cHeight; // save canvas height
var canvas; // global canvas definition so we don't have to keep looking it up var canvas; // global canvas definition so we don't have to keep looking it up