<?php /******************************************* /* Programm diff_count.php4 /* displays differences of temperature /* (c) Copyright 2002, Jens Bierkandt /* e-mail: jens@bierkandt.org /* Entstanden im Rahmen meiner Diplomarbeit /******************************************* */ error_reporting(63); set_time_limit(60); $total = time(); include ("jpgraph-1.6.1/src/jpgraph.php"); include ("jpgraph-1.6.1/src/jpgraph_line.php"); include ("/home/schtorch/public_html/diplom/config.php4"); // Check variables and initialize if (!isset($table)) Header("Location: index.php4"); // Forward user to main page to reselect table if (!isset($average)) $average = 10; if ($average > 999) $average = 999; if (!isset($diff_min)) $diff_min = 5; // minimum time in seconds of a temperature change in one direction if (!isset($diff_max)) $diff_max = 30; if ($diff_min <= 0) $diff_min = 0.1; if ($diff_max <= 0) $diff_max = 0.3; if (!isset($start_diff)) $start_diff = 2; if (!isset($temp_diff)) $temp_diff = 2; if ($start_diff < 1) $start_diff = 2; if ($temp_diff < 1) $temp_diff = 2; $diff_min *= 10; // cause we stored the data in 1/10 sec $diff_max *= 10; // Initialize connection to DB $db = mysql_connect($hostname, $username, $password); mysql_select_db($database, $db); echo mysql_error(); // Select data for ($sens = 0; $sens < sizeof($sensor); $sens++) { $result = "SELECT "; $result .= "`sensor".$sensor[$sens]."`,"; $result = substr($result, 0, strlen($result)-1); //$result.="timestamp "; $result .= "FROM `tmp` WHERE `sensor".$sensor[$sens]."`!='' ORDER BY id"; $result = mysql_query($result, $db); echo mysql_error(); $row = mysql_fetch_row($result); $row[0] = round($row[0]); $inc = TRUE; $last_row = $row[0]; $start_temp = $row[0]; $row_diff = 0; $i = 1; while($row = mysql_fetch_row($result)) { $row[0] = round($row[0]); $i++; //echo $row[0]."<br>"; // Check, if we still have increasing values if (($last_row <= $row[0]) && $inc == TRUE) { $row_diff = $row[0]-$start_temp; $last_row = $row[0]; //echo "up<br>"; continue; } // Check, if we still have decreasing values if (($last_row >= $row[0]) AND $inc == FALSE) { $row_diff = $start_temp-$row[0]; $last_row = $row[0]; //echo "down<br>"; continue; } // The temperature changed direction // Did the last change of temperature direction took long enough? if ($i >= $diff_min AND $i <= $diff_max) { if ($inc) { // save incresing temperature changes if (!isset($datax[$start_temp][$row_diff])) $datax[$start_temp][$row_diff] = "0"; $datax[$start_temp][$row_diff]++; //echo "Starttemp: $start_temp, Temperaturhub: $row_diff, Länge: $i, Anzahl: ".$datax[$start_temp][$row_diff]."<br>"; } else { if (!isset($datax_min[$start_temp][$row_diff])) $datax_min[$start_temp][$row_diff] = "0"; $datax_min[$start_temp][$row_diff]++; //echo "Starttemp: $start_temp, Temperaturhub: $row_diff, Länge: $i, Anzahl: ".$datax_min[$start_temp][$row_diff]."<br>"; } } $start_temp = $last_row; $row_diff = abs($last_row-$row[0]); $last_row = $row[0]; if ($inc == TRUE) $inc = FALSE; else $inc = TRUE; $i = 1; } // Get last change $i++; if ($i >= $diff_min AND $i <= $diff_max) { if ($inc) { // save incresing temperature changes if (!isset($datax[$start_temp][$row_diff])) $datax[$start_temp][$row_diff] = "0"; $datax[$start_temp][$row_diff]++; //echo "Starttemp: $start_temp, Temperaturhub: $row_diff, Länge: $i, Anzahl: ".$datax[$start_temp][$row_diff]."<br>"; } else { if (!isset($datax_min[$start_temp][$row_diff])) $datax_min[$start_temp][$row_diff] = "0"; $datax_min[$start_temp][$row_diff]++; //echo "Starttemp: $start_temp, Temperaturhub: $row_diff, Länge: $i, Anzahl: ".$datax_min[$start_temp][$row_diff]."<br>"; } } // Start output for positive temperature changes // Get min and max of 3-dimensional array $min_temp = 127; $max_temp = 0; $min_start = 127; $max_start = 0; for ($a = 1; $a < 127; $a++) { for ($i = 1; $i < 127; $i++) { if (!isset($datax[$a][$i])) continue; else { if ($min_temp > $i) $min_temp = $i; if ($max_temp < $i) $max_temp = $i; if ($min_start > $a) $min_start = $a; if ($max_start < $a) $max_start = $a; } } } echo "<h3>Positive Temperaturhübe für $computer, Sensor $sensor[$sens]<br>"; echo "Hübe zwischen ".($diff_min/10)." und ".($diff_max/10)." Sekunden</h3>"; echo "<table><tr><td>Starttemperatur in °C</td>"; for ($start_temp = $min_start; $start_temp <= $max_start; $start_temp = $start_temp+$start_diff) { echo "<td align=right width=30>$start_temp"; if ($start_diff > 1) echo " bis ".($start_temp+$start_diff); echo "</td>"; } echo "</tr>"; echo "<tr><td>Temperaturhub in K</td></tr>"; $i = 0; for ($row_diff = $min_temp; $row_diff <= $max_temp; $row_diff = $row_diff+$temp_diff) { if ($i%2) echo "<tr>"; else echo "<tr bgcolor=#FFFFCC>"; echo "<td align=left>$row_diff"; if ($temp_diff > 1) echo " bis ".($row_diff+$temp_diff); echo "</td>"; for ($start_temp = $min_start; $start_temp <= $max_start; $start_temp = $start_temp+$start_diff) { $temp = ""; for ($b = $start_temp; $b < $start_temp+$start_diff; $b++) { for ($c = $row_diff; $c < $row_diff+$temp_diff; $c++) { if (isset($datax[$b][$c])) { $temp += $datax[$b][$c]; } } } if ($temp) { echo "<td align=right>".$temp."</td>"; } else { echo "<td align=right>-</td>"; } } echo "</tr>\n"; $i++; } echo "</tr></table>"; // Start output for negative temperature changes // Get min and max of 3-dimensional array $min_temp = 127; $max_temp = 0; $min_start = 127; $max_start = 0; for ($a = 1; $a < 127; $a++) { for ($i = 1; $i < 127; $i++) { if (!isset($datax_min[$a][$i])) continue; else { if ($min_temp > $i) $min_temp = $i; if ($max_temp < $i) $max_temp = $i; if ($min_start > $a) $min_start = $a; if ($max_start < $a) $max_start = $a; } } } echo "<h3>Negative Temperaturhübe für $computer, Sensor $sensor[$sens]<br>"; echo "Hübe zwischen ".($diff_min/10)." und ".($diff_max/10)." Sekunden</h3>"; echo "<table><tr><td>Starttemperatur in °C</td>"; for ($start_temp = $min_start; $start_temp <= $max_start; $start_temp = $start_temp+$start_diff) { echo "<td align=right width=30>$start_temp"; if ($start_diff > 1) echo " bis ".($start_temp+$start_diff); echo "</td>"; } echo "</tr>"; echo "<tr><td>Temperaturhub in K</td></tr>"; $i = 0; for ($row_diff = $min_temp; $row_diff <= $max_temp; $row_diff = $row_diff+$temp_diff) { if ($i%2) echo "<tr>"; else echo "<tr bgcolor=#FFFFCC>"; echo "<td align=left>-$row_diff"; if ($temp_diff > 1) echo " bis -".($row_diff+$temp_diff); echo "</td>"; for ($start_temp = $min_start; $start_temp <= $max_start; $start_temp = $start_temp+$start_diff) { $temp = ""; for ($b = $start_temp; $b < $start_temp+$start_diff; $b++) { for ($c = $row_diff; $c < $row_diff+$temp_diff; $c++) { if (isset($datax_min[$b][$c])) { $temp += $datax_min[$b][$c]; } } } if ($temp) { echo "<td align=right>".$temp."</td>"; } else { echo "<td align=right>-</td>"; } } echo "</tr>\n"; $i++; } echo "</tr></table>"; } ?>