".$outfile."_cdat.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 330a_sdat > ".$outfile."_sdat.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 330a_heat > ".$outfile."_heat.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 330a_setpt > ".$outfile."_setpt.txt"); // Return an array with all of the names of the text files just created return array('name' => $outfile, 'dewar' => $outfile.'_cdat.txt', 'array' => $outfile.'_sdat.txt', 'heater' => $outfile.'_heat.txt', 'setpoint' => $outfile.'_setpt.txt'); } // Query all of the SensorData for the set parameters and write the txt files // Pre-condition: The path, script, database, table, how far back you want // to look, and the name you want for the graph function plot_tc208($path, $script, $database, $table, $sec_ago, $outfile) { // Set up the text files holding the data being graphed (tc208: channels 1-8) run_script($path, $script, $database." ".$table." ".$sec_ago." 208_ch1 > ".$outfile."_ch1.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 208_ch2 > ".$outfile."_ch2.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 208_ch3 > ".$outfile."_ch3.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 208_ch4 > ".$outfile."_ch4.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 208_ch5 > ".$outfile."_ch5.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 208_ch6 > ".$outfile."_ch6.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 208_ch7 > ".$outfile."_ch7.txt"); run_script($path, $script, $database." ".$table." ".$sec_ago." 208_ch8 > ".$outfile."_ch8.txt"); // Return an array with all of the names of the text files just created return array('name' => $outfile, 'ch1' => $outfile.'_ch1.txt', 'ch2' => $outfile.'_ch2.txt', 'ch3' => $outfile.'_ch3.txt', 'ch4' => $outfile.'_ch4.txt', 'ch5' => $outfile.'_ch5.txt', 'ch6' => $outfile.'_ch6.txt', 'ch7' => $outfile.'_ch7.txt', 'ch8' => $outfile.'_ch8.txt'); } // Set an array with // Pre-condition: The name of the graph function array_outfiles($outfile) { // If the array is for tc208... if (strpos($outfile, "tc208") !== False) { // Return an array with all of the names of the text files holding data from tc208 return array('name' => $outfile, 'ch1' => $outfile.'_ch1.txt', 'ch2' => $outfile.'_ch2.txt', 'ch3' => $outfile.'_ch3.txt', 'ch4' => $outfile.'_ch4.txt', 'ch5' => $outfile.'_ch5.txt', 'ch6' => $outfile.'_ch6.txt', 'ch7' => $outfile.'_ch7.txt', 'ch8' => $outfile.'_ch8.txt'); } else // if not for tc208... { // Return an array with all of the names of the text files holding data from tc330... return array('name' => $outfile, 'dewar' => $outfile.'_cdat.txt', 'array' => $outfile.'_sdat.txt', 'heater' => $outfile.'_heat.txt', 'setpoint' => $outfile.'_setpt.txt'); } } // Sets up the query // Pre-condition: The table with your data, how far back you want to // search, and the SensorID of the data you want. function query_SensorData($table, $sec_ago, $sensor_id) { // Returns the query with the parameters passed to this function return $query = "SELECT Timestamp, FROM_UNIXTIME(Timestamp) AS date, SensorData FROM ".$table." WHERE Timestamp > (UNIX_TIMESTAMP() - ".$sec_ago.") AND SensorID = '".$sensor_id."'"; } // Query MySQL and update the .txt file associated // Pre-condition: ID Prefix for the sensor you are looking up (bd, gd, spex), // Timeframe, file name with .txt, and the table the data is in function set_txts($query, $outfile) { // Open the .txt file being writen to $fh = fopen($outfile, 'w') or die("can't open file ".$outfile); // Collect the query results $results = mysql_query($query) or DIE("Error with Query: ".$query); // Write the results to the .txt file while ($row=mysql_fetch_array($results)){ $stringData = $row[0]."\t".$row[1]."\t".$row[2]."\n"; fwrite($fh, $stringData); } // Clear the query mysql_free_result($results); // Close the .txt file fclose($fh); } // List the text files in the array used to make the graph // Pre-condition: An array with your text file names function list_txt_files($array) { // Start the list $list = 'Data to make Graph:
'; // Go through each item in the array with key as $key and value as $value foreach($array as $key => $value) { // If key is not equal to name if ($key !== 'name') { // and value is not the last item in the array if (end($array) !== $value) { // Add value to the list and add a new line $list .= <<< DATA {$value}
DATA; } else // if it is the last item { // Just add the value to the list $list .= <<< DATA {$value} DATA; } } } // Return the list return $list; } ?>