\n"; ?>
50*60) // 50 minutes { $interval = 15; } // 15 minutes if ($seconds > 150*60) // 150 minutes { $interval = 30; } // 30 minutes if ($seconds > 300*60) // 300 minutes { $interval = 60; } // 1 hour if ($seconds > 10*60*60) // 10 hours { $interval = 3*60; } // 3 hours if ($seconds > 30*60*60) // 30 hours { $interval = 6*60; } // 6 hours if ($seconds > 60*60*60) // 60 hours { $interval = 24*60; } // 1 day if ($seconds > 10*24*60*60) // 10 days { $interval = 0; } // No label on tics (for now). if ($DEBUG) { echo "Interval: $interval seconds.
\n"; } $xtics = "set xtics ("; // Now query for rows from less than $seconds seconds ago. // We want all fields, the number of seconds since midnight, and the time // in 24-hour HH:MM format (for use in labelling X axis.) $query="select time, temp0, temp1, temp2, mod(hour(time)*60+minute(time),$interval),date_format(time,\"%H:%i\") from temps where unix_timestamp(now())-unix_timestamp(time) < $seconds order by id"; if (!mysql_pconnect("localhost:3306","XXXXX","XXXXXXXXX")) { echo "Connection failed!

"; echo mysql_errno().": ".mysql_error()."
"; echo "

"; } if (!mysql_select_db("temp")) { echo "Could not connect to 'web' database!

"; echo mysql_errno().": ".mysql_error()."
"; echo "

"; } if (!($id=mysql_query("$query"))) { echo "Error with query:"; echo mysql_errno().": ".mysql_error()."
"; echo "

"; print "$query

\n"; } $rows=mysql_num_rows($id); srand((double)microtime()*1000000); $randval = rand(); $ext=rand(0,999999); if (!file_exists("/tmp/tempdata")) { echo "Creating /tmp/tempdata...

"; mkdir ("/tmp/tempdata",0755); } chdir ("/tmp/tempdata"); if (isset($crawlspace)) { if (!$crawlspace_fp=fopen("/tmp/tempdata/crawlspace.$ext","w")) { echo "Couldn't open /tmp/tempdata/crawlspace.$ext for writing!\n"; } } if (isset($outside)) { if (!$outside_fp=fopen("/tmp/tempdata/outside.$ext","w")) { echo "Couldn't open /tmp/tempdata/outside.$ext for writing!\n"; } } if (isset($office)) { if (!$office_fp=fopen("/tmp/tempdata/office.$ext","w")) { echo "Couldn't open /tmp/tempdata/office.$ext for writing!\n"; } } $rownum=0; while (list($datestamp,$crawlspace_temp,$outside_temp,$office_temp,$mod,$time)=mysql_fetch_row($id)) { if (!$rownum) $begin=$datestamp; if ($corf=="C") { // For those people who don't grok Fahrenheit $crawlspace_temp=(($crawlspace_temp-32)*5)/9; $outside_temp=(($outside_temp-32)*5)/9; $office_temp=(($office_temp-32)*5)/9; } if (isset($crawlspace)) { fputs ($crawlspace_fp,$crawlspace_temp."\n"); } if (isset($outside)) { fputs ($outside_fp,$outside_temp."\n"); } if (isset($office)) { fputs ($office_fp,$office_temp."\n"); } $end=$datestamp; if (!$mod) { // This falls on an $interval boundary $xtics.="\"$time\" $rownum,"; } $rownum++; } if (isset($crawlspace_fp)) fclose ($crawlspace_fp); if (isset($outside_fp)) fclose ($outside_fp); if (isset($office_fp)) fclose ($office_fp); // After this we have an extra comma on the end of $xtics, which gnuplot // won't like: $xtics=substr($xtics,0,strlen($xtics)-1); $xtics.=")\n"; if (!$interval) $xtics="set noxtics;\n"; // Thanks to Ashley Clark for this: $command = "echo -e 'set term png color small\n"; if ($corf=="F") { $command .= "set ylabel \"degrees Fahrenheit\"\n"; } else { $command .= "set ylabel \"degrees Celcius\"\n"; } $command .= $xtics."\n"; $command .= "set xlabel \"Pacific time\"\n"; $command .= "set title \"Temperature"; $command .= " for past $num $units\"\n"; if (isset($crawlspace)) { $command .= "plot \"crawlspace.$ext\" with lines 1"; } if (isset($outside)) { if (isset($crawlspace)) $command.=","; if (!isset($crawlspace)) $command.="plot "; $command .= "\"outside.$ext\" with lines 2"; } if (isset($office)) { if (isset($crawlspace) || isset($outside)) $command.=","; if (!isset($crawlspace) && !isset($outside)) $command.="plot "; $command .= "\"office.$ext\" with lines 3"; } $command .= "'| /usr/bin/gnuplot > /web/content/temp/tempdata/$ext.png"; if ($DEBUG) echo "$command
"; passthru($command); if ($DEBUG) { echo "$xtics
\n"; } echo "

\n"; echo "

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo ""; echo ""; echo "
BEGIN: $beginEND: $end
$rows data points found.Back to Temperature Page
\n"; ?>