[Firebug-cvs] firebug/web/demo temphum.php,1.1,1.2
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2004-04-02 23:03:39
|
Update of /cvsroot/firebug/firebug/web/demo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1926/demo Modified Files: temphum.php Log Message: Plotting temperature and humidity works for one mote at a time. Index: temphum.php =================================================================== RCS file: /cvsroot/firebug/firebug/web/demo/temphum.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** temphum.php 2 Apr 2004 16:41:32 -0000 1.1 --- temphum.php 2 Apr 2004 22:51:24 -0000 1.2 *************** *** 5,11 **** <html> <head> ! <title>Results demo script</title> ! <link rel="SHORTCUT ICON" href="../images/favicon.ico"> ! <link type="text/css" rel="stylesheet" href="../firebug.css"> </head> --- 5,11 ---- <html> <head> ! <title>Results demo script</title> ! <link rel="SHORTCUT ICON" href="../images/favicon.ico"> ! <link type="text/css" rel="stylesheet" href="../firebug.css"> </head> *************** *** 18,271 **** <?php ! $dbname = "gpsradio"; ! $tblname = "location"; ! //$dbname = $HTTP_POST_VARS["db1"]; ! //$tblname = $HTTP_SESSION_VARS["tblname"]; ! //$checkboxname = $HTTP_SESSION_VARS["cb"]; ! $radiox = $HTTP_POST_VARS["radiox"]; ! $radioy = $HTTP_POST_VARS["radioy"]; ! $xmin = $HTTP_POST_VARS["xmin"]; ! $xmax = $HTTP_POST_VARS["xmax"]; ! //echo "Radio x: ".$radiox;echo "Radio y: ".$radioy; ! mysql_connect("localhost","root","") or die("Error: ".mysql_error()." in mysql_connect."); ! $dblink=mysql_select_db("$dbname") or die("Error: ".mysql_error()." in mysql_select_db."); ! ?> - <?php - //include "db_print_table.php"; - ?> ! <table> ! <tr> ! <td> ! <form action="graphem.php" method="post"> ! <table> ! <tr> ! <td>mote_id</td> ! <td><input type=radio name=radiox value="mote_id"</td> ! <td><input type=radio name=radioy value="mote_id"</td> ! </tr> - <tr> - <td>gps_hours</td> - <td><input type=radio name=radiox value="gps_hours"</td> - <td><input type=radio name=radioy value="gps_hours"</td> - </tr> - <tr> - <td>gps_minutes</td> - <td><input type=radio name=radiox value="gps_minutes"</td> - <td><input type=radio name=radioy value="gps_minutes"</td> - </tr> ! <tr> ! <td>gps_seconds</td> ! <td><input type=radio name=radiox value="gps_seconds"</td> ! <td><input type=radio name=radioy value="gps_seconds"</td> ! </tr> ! <tr> ! <td>lat_deg</td> ! <td><input type=radio name=radiox value="lat_deg"</td> ! <td><input type=radio name=radioy value="lat_deg"</td> ! </tr> ! <tr> ! <td>lat_dec_min</td> ! <td><input type=radio name=radiox value="lat_dec_min"</td> ! <td><input type=radio name=radioy value="lat_dec_min"</td> ! </tr> ! <tr> ! <td>long_deg</td> ! <td><input type=radio name=radiox value="long_deg"</td> ! <td><input type=radio name=radioy value="long_deg"</td> ! </tr> - <tr> - <td>long_dec_min</td> - <td><input type=radio name=radiox value="long_dec_min"</td> - <td><input type=radio name=radioy value="long_dec_min"</td> - </tr> ! <tr> ! <td>nsew</td> ! <td><input type=radio name=radiox value="nsew"</td> ! <td><input type=radio name=radioy value="nsew"</td> ! </tr> ! ! <tr> ! <td>numsats</td> ! <td><input type=radio name=radiox value="numsats"</td> ! <td><input type=radio name=radioy value="numsats"</td> ! </tr> - </table> - <input type=hidden name=db1 value="dbname"> - <input type=submit value="Plot"> - </form> - </td> - <!-- - <form action="graphem.php" method="post"> <table> <tr> ! <td>mote_id</td> ! <td><input type=radio name=radiox value="mote_id"</td> ! <td><input type=radio name=radioy value="mote_id"</td> ! </tr> ! <tr> ! <td>time</td> ! <td><input type=radio name=radiox value="time"</td> ! <td><input type=radio name=radioy value="time"</td> ! </tr> <tr> ! <td>count</td> ! <td><input type=radio name=radiox value="cnt"</td> ! <td><input type=radio name=radioy value="cnt"</td> ! </tr> ! <tr> ! <td>RSSI</td> ! <td><input type=radio name=radiox value="rssi"</td> ! <td><input type=radio name=radioy value="rssi"</td> </tr> - </table> <input type=hidden name=db1 value="dbname"> <input type=submit value="Plot"> </form> - --> - - <?php - - - $dbname = "gpsradio"; - $statement = "use $dbname"; - mysql_query($statement) or die("Error: ".mysql_error()." changing databases"); - - - if ($radioy == null) { - print("Error, must choose a y value\n"); - // statement for selecting against y value only. - } - - if ($radiox == null) { - $statement = "select $radioy from location where lat_deg = 37 and long_deg = 122"; - } else { - $statement = "select $radiox,$radioy from location where lat_deg = 37 and long_deg = 122"; - } - - $result = mysql_query($statement) or die("Error: ".mysql_error()." in select statement"); - - - if (!$ofp=fopen("test.dat","w")) { - echo "Unable to open data output file for writing.\n"; - } - - if(!chmod ("test.dat", 0775)) { - echo "chmod failed\n"; - } - - function print_row($item2,$key) { - fwrite($ofp,$item2); - } - - if ($row = mysql_fetch_row($result)) { - - // for each row - do { - // For each column... - $row = array_values($row); - $size = count($row); - for ($i=0; $i<$size; $i++) { - // This is no good for multiple columns. - fwrite($ofp,$row[$i]." "); - } - fwrite($ofp,"\n"); - } while ($row = mysql_fetch_row($result)); - } - fclose($ofp); - // This stuff doesn't work yet, but would be - // be a better way to do this. Move all this - // kind of stuff into dedicated functions. - //$command = "echo -e 'set term png\n"; - $command = "'set term png\n"; - $command .= "set size 0.4\n"; - //$command .= "plot \"test2.dat\"\n'"; - $command .= "plot \"test.dat\"\n'"; - //$command .= "| C:/gp373w32/pgnuplot.exe > test.png"; - $command .= "| C:/gp373w32/pgnuplot.exe > test.png"; - - //$plotcommand = "echo -e 'set term png\n"; - $plotcommand = "'set term png\n"; - $plotcommand .= "set size 0.4\n"; - $plotcommand .= "set output \"test.png\"\n"; - $plotcommand .= "plot \"test.dat\" with lines 2'"; - - $plotstring = "set term png\n"; - $plotstring .= "set size 0.5\n"; - $plotstring .= "set output \"test.png\"\n"; - $plotstring .= "plot \"test.dat\" with lines 2"; - - - $gnuplot = " | C:\\gp373w32\\pgnuplot.exe"; - - //echo $command; - - // System call - $systemcall = $plotcommand; - $systemcall .= $gnuplot; - - $gnufile = "test2.gnu"; - //$ofp = fopen("test1.gnu","w"); - $ofp = fopen($gnufile,"w"); - fwrite($ofp,$plotstring); - fclose($ofp); - //system("C:\\gp373w32\\pgnuplot.exe < ./test1.gnu"); - //Try the redirect going the other way with an output file name. - system("C:\\gp373w32\\pgnuplot.exe < ./$gnufile"); // > $outfile.png ! /* ! print("<pre>"); ! print($plotcommand.$gnuplot); ! print("</pre>"); ! */ ! //This doesn't work either. ! //`$plotcommand.$gnuplot`; ! /* ! $systemcall = $plotcommand; ! $systemcall .= $gnuplot; ! $e = escapeshellcmd($systemcall); ! // This would be preferable, but doesn't seem to work. ! if(system("echo -e $systemcall",$error)) { ! echo "System call succeeded\n"; ! } else { ! echo "System call failed with error $error\n"; ! } ! print("<pre>"); ! print($e); ! print("</pre>"); ! */ ?> - - <td> - <img src="test.png"> </td> </tr> --- 18,150 ---- <?php + $dbname = "foobar"; + $tblname = "cumulative"; + $mote_id = $HTTP_POST_VARS["motes"]; + $radioy = $HTTP_POST_VARS["radioy"]; + mysql_connect("localhost","root","") or die("Error: ".mysql_error()." in mysql_connect."); + $dblink=mysql_select_db("$dbname") or die("Error: ".mysql_error()." in mysql_select_db."); ! function extract_mote_id($result) { ! if ($row = mysql_fetch_row($result)) { ! // for each row ! do { ! // For each column... ! $row = array_values($row); ! echo "<option value=\"$row[0]\">"; ! print($row[0]); ! echo "</option>\n"; ! } while ($row = mysql_fetch_row($result)); ! ! } ! } ! function write_data_to_file($result,$datafile) { ! if (!$ofp=fopen($datafile,"w")) { ! echo "Unable to open data output file for writing.\n"; ! } + if(!chmod ($datafile, 0775)) { + echo "chmod failed\n"; + } ! if ($row = mysql_fetch_row($result)) { ! // for each row ! do { ! // For each column... ! $row = array_values($row); ! $size = count($row); ! for ($i=0; $i<$size; $i++) { ! fwrite($ofp,$row[$i]." "); ! } ! fwrite($ofp,"\n"); ! } while ($row = mysql_fetch_row($result)); ! } ! fclose($ofp); ! } ! function plot($outfile,$datafile,$gnufile) { ! $plotstring = "set term png\n"; ! $plotstring .= "set size 0.5\n"; ! $plotstring .= "set output \"$outfile\"\n"; ! $plotstring .= "plot \"$datafile\" with lines 2"; ! $ofp = fopen($gnufile,"w"); ! fwrite($ofp,$plotstring); ! fclose($ofp); ! system("C:\\gp373w32\\pgnuplot.exe < ./$gnufile"); ! } ! ?> <table> <tr> ! <td> ! <form action="temphum.php" method="post"> + <table> <tr> ! <td>Temperature</td> ! <td><input type=radio name=radiox value="temp"</td> ! <td><input type=radio name=radioy value="temp"</td> ! </tr> <tr> ! <td>Relative humidity</td> ! <td><input type=radio name=radiox value="rel_hum"</td> ! <td><input type=radio name=radioy value="rel_hum"</td> ! </tr> ! <tr> ! <td>Barometric pressure</td> ! <td><input type=radio name=radiox value="baro_pres"</td> ! <td><input type=radio name=radioy value="baro_pres"</td> ! </tr> ! <tr> ! <td>Select mote id for plotting: ! <select name=motes> ! <?php ! $statement = "select distinct mote_id from cumulative"; ! $result = mysql_query($statement) or die("Error in distinct mote id: ".mysql_error()." in select statement"); ! extract_mote_id($result); ! ?> ! </select> ! </td> </tr> </table> + <input type=hidden name=db1 value="dbname"> <input type=submit value="Plot"> </form> + </td> ! <?php ! ! $statement = "select $radioy from cumulative where mote_id = $mote_id"; ! $result = mysql_query($statement) or die("Error in plot data select: ".mysql_error()." in select statement"); ! $datafile = "temp.dat"; ! $gnufile = "temp.gnu"; ! $outfile = "temp.png"; ! write_data_to_file($result,$datafile); ! plot($outfile,$datafile,$gnufile); + echo "<td>\n"; + echo "<img src=\"$outfile\">\n"; ?> </td> </tr> *************** *** 274,281 **** <?php include("../nav_footer.php"); - //$radiox = null; - //$radioy = null; ?> --- 153,159 ---- + <?php include("../nav_footer.php"); ?> *************** *** 283,290 **** <hr /> ! <p> ! Last Updated: $Date$ ! by $Author$. ! </p> </body> --- 161,168 ---- <hr /> ! <p> ! Last Updated: $Date$ ! by $Author$. ! </p> </body> |