Adding some forgotten Files
git-svn-id: file:///home/jan/tmp/wetterstation/trunk@28 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
7d9466a0d2
commit
133f8dcec5
|
|
@ -0,0 +1,35 @@
|
||||||
|
<h3 class="mod_headline">Regen - {content:fill:sens_location}</h3>
|
||||||
|
<p class="mod_description">{content:fill:sens_description}</p>
|
||||||
|
<h4 class="mod_subhead">Aktuelle Werte</h4>
|
||||||
|
<table class="mod_rain_now_data">
|
||||||
|
<tr class="mod_rain_hour_row">
|
||||||
|
<td class="mod_line_desc">Letze Stunde:</td><td class="mod_line_val">{content:fill:rain_now_hour} l/m<sup>2</sup></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="mod_rain_day_row">
|
||||||
|
<td class="mod_line_desc">Heute:</td><td class="mod_line_val">{content:fill:rain_now_day} l/m<sup>2</sup></td><td> </td>
|
||||||
|
</tr>
|
||||||
|
<tr class="mod_rain_month_row">
|
||||||
|
<td class="mod_line_desc">Diesen Monat:</td><td class="mod_line_val">{content:fill:rain_now_month} l/m<sup>2</sup></td><td> </td>
|
||||||
|
</tr>
|
||||||
|
<tr class="mod_rain_year_row">
|
||||||
|
<td class="mod_line_desc">Dies Jahr:</td><td class="mod_line_val">{content:fill:rain_now_year} l/m<sup>2</sup></td><td> </td>
|
||||||
|
</tr>
|
||||||
|
<tr class="mod_rain_all_row">
|
||||||
|
<td class="mod_line_desc">Seit Messbegin:</td><td class="mod_line_val">{content:fill:rain_now_all} l/m<sup>2</sup></td><td> </td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h4 class="mod_subhead">Extrema</h4>
|
||||||
|
<table>
|
||||||
|
<tr class="mod_rain_max_hour_row">
|
||||||
|
<td class="mod_line_desc">Regenreichste Stunde:</td><td class="mod_line_val">{content:fill:rain_max_hour_val} l/m<sup>2</sup></td><td class="mod_line_date">{content:fill:rain_max_hour_date}</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="mod_rain_max_day_row">
|
||||||
|
<td class="mod_line_desc">Regenreichster Tag:</td><td class="mod_line_val">{content:fill:rain_max_day_val} l/m<sup>2</sup></td><td class="mod_line_date">{content:fill:rain_max_day_date}</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="mod_rain_max_month_row">
|
||||||
|
<td class="mod_line_desc">Regenreichster Monat:</td><td class="mod_line_val">{content:fill:rain_max_month_val} l/m<sup>2</sup></td><td class="mod_line_date">{content:fill:rain_max_month_date}</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="mod_rain_max_year_row">
|
||||||
|
<td class="mod_line_desc">Regenreichstes Jahr:</td><td class="mod_line_val">{content:fill:rain_max_year_val} l/m<sup>2</sup></td><td class="mod_line_date">{content:fill:rain_max_year_date}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
@ -0,0 +1,106 @@
|
||||||
|
<?
|
||||||
|
|
||||||
|
include_once("php_inc/connection.inc.php");
|
||||||
|
|
||||||
|
/* Rain-Klasse für das Rain-Modul */
|
||||||
|
class Rain{
|
||||||
|
|
||||||
|
var $nowHour; /* Regen in der momentanen Stunde */
|
||||||
|
var $nowDay; /* Regen in heute */
|
||||||
|
var $nowMonth; /* Regen diesen Monat */
|
||||||
|
var $nowYear; /* Regen dies Jahr */
|
||||||
|
var $nowAll; /* Regen seit Messbeginn */
|
||||||
|
var $maxHourData; /* Stunde mit dem meistem Regen */
|
||||||
|
var $maxDayData; /* Tag mit dem meistem Regen */
|
||||||
|
var $maxMonthData; /* Monat mit dem meistem Regen */
|
||||||
|
var $maxYearData; /* Jahr mit dem meistem Regen */
|
||||||
|
|
||||||
|
/* Konstruktor, Holt die Werte aus der Datenbank und füllt die Variablen damit */
|
||||||
|
function Rain($sensId, & $connection){
|
||||||
|
|
||||||
|
/* Tabelle des Sensors bestimmen */
|
||||||
|
$tableQuery = "SELECT tabelle FROM sensoren, typen WHERE sensoren.id=".$sensId." AND typen.typ = sensoren.typ";
|
||||||
|
$table = $connection->fetchQueryResultLine($tableQuery);
|
||||||
|
$table = trim($table['tabelle']);
|
||||||
|
|
||||||
|
/* Aktuelle Werte holen */
|
||||||
|
$this->nowHour = $this->_getNowValues($sensId, & $connection, $table, "1 hours");
|
||||||
|
$this->nowDay = $this->_getNowValues($sensId, & $connection, $table, "1 days");
|
||||||
|
$this->nowMonth = $this->_getNowValues($sensId, & $connection, $table, "1 months");
|
||||||
|
$this->nowYear = $this->_getNowValues($sensId, & $connection, $table, "1 years");
|
||||||
|
$this->nowAll = $connection->fetchQueryResultLine("SELECT sum(count) as rain FROM ".$table." WHERE sens_id=".$sensId);
|
||||||
|
|
||||||
|
/* Maximale Werte holen */
|
||||||
|
$this->maxHourData = $this->_getMaxValues($sensId, & $connection, $table, "hour", "DD.MM.YYYY HH24:MI");
|
||||||
|
$this->maxDayData = $this->_getMaxValues($sensId, & $connection, $table, "day", "DD.MM.YYYY");
|
||||||
|
$this->maxMonthData = $this->_getMaxValues($sensId, & $connection, $table, "month", "MM.YYYY");
|
||||||
|
$this->maxYearData = $this->_getMaxValues($sensId, & $connection, $table, "year", "YYYY");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Momentane Werte aus der Datenbank holen */
|
||||||
|
function _getNowValues($sensId, & $connection, $table, $interval){
|
||||||
|
$result = $connection->fetchQueryResultLine("SELECT sum(count) as rain FROM ".$table." WHERE sens_id=".$sensId." AND timestamp>(current_timestamp - INTERVAL '".$interval."')");
|
||||||
|
return $result['rain'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Maximal gemessene Werte aus der Datenbank holen */
|
||||||
|
function _getMaxValues($sensId, & $connection, $table, $unit, $dateFormat){ // unit = hour, minute, ...
|
||||||
|
return $connection->fetchQueryResultLine("SELECT to_char(ts, '".$dateFormat."') as date, val FROM ".$table."_".$unit." WHERE sens_id=".$sensId." AND val=(SELECT max(val) FROM ".$table."_".$unit." WHERE sens_id=".$sensId.")");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --- Funktionen, die die Werte für die Ausgabe zurückgeben --- */
|
||||||
|
function get_now_hour(){
|
||||||
|
return round($this->nowHour * 0.001,3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_now_day(){
|
||||||
|
return round($this->nowDay * 0.001,3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_now_month(){
|
||||||
|
return round($this->nowMonth * 0.001,3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_now_year(){
|
||||||
|
return round($this->nowYear * 0.001,3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_now_all(){
|
||||||
|
return round($this->nowAll['rain'] * 0.001,3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_hour_val(){
|
||||||
|
return round($this->maxHourData['val'] * 0.001, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_hour_date(){
|
||||||
|
return $this->maxHourData['date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_day_val(){
|
||||||
|
return round($this->maxDayData['val'] * 0.001, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_day_date(){
|
||||||
|
return $this->maxDayData['date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_month_val(){
|
||||||
|
return round($this->maxMonthData['val'] * 0.001, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_month_date(){
|
||||||
|
return $this->maxMonthData['date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_year_val(){
|
||||||
|
return round($this->maxYearData['val'] * 0.001, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_year_date(){
|
||||||
|
return $this->maxYearData['date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?
|
||||||
|
|
||||||
|
include_once("php_inc/connection.inc.php");
|
||||||
|
|
||||||
|
|
||||||
|
/* Klasse, Die Daten üben die Einzelnen Sensoren bereitstellt */
|
||||||
|
class Sensor{
|
||||||
|
|
||||||
|
var $id; /* Die ID des Sensors */
|
||||||
|
var $location; /* Der Standort des Sensors */
|
||||||
|
var $descr; /* Beschreibung des Sensors */
|
||||||
|
var $typ; /* Typ des Sensors */
|
||||||
|
var $address; /* Addresse des Sensors */
|
||||||
|
|
||||||
|
/* Konstruktor, Initialisiert die Klasse mit den Werten */
|
||||||
|
function Sensor($sensId, & $connection){
|
||||||
|
$this->_fetchSensorData($sensId, &$connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Holt die Daten über den Sensor aus der Datenbank */
|
||||||
|
function _fetchSensorData($sensId, &$connection){
|
||||||
|
$query = "SELECT * FROM sensoren WHERE id=".$sensId;
|
||||||
|
$data = $connection->fetchQueryResultLine($query);
|
||||||
|
|
||||||
|
$this->id = $data['id'];
|
||||||
|
$this->location = $data['standort'];
|
||||||
|
$this->descr = $data['beschreibung'];
|
||||||
|
$this->typ = $data['typ'];
|
||||||
|
$this->address = $data['addresse'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- Funktionen, die die Einzelnen Eigenschaften des Sensors zurückgeben --- */
|
||||||
|
function get_id(){
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_location(){
|
||||||
|
return $this->location;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_description(){
|
||||||
|
return $this->descr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_type(){
|
||||||
|
return $this->typ;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_address(){
|
||||||
|
return $this->address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -0,0 +1,129 @@
|
||||||
|
<?
|
||||||
|
class Temp{
|
||||||
|
|
||||||
|
var $nowTemp; /* Momentane Temparatur */
|
||||||
|
var $nowDate; /* datum des letzten Messvorgangs */
|
||||||
|
var $avVal; /* Durchschnittswert */
|
||||||
|
var $avInter; /* Interval des Durchschnittswertes */
|
||||||
|
var $minTemp; /* Minimale Temparatur */
|
||||||
|
var $minDate; /* Datum, wann die Minimale Temparatur gemessen wurde */
|
||||||
|
var $maxTemp; /* Maximale Temparatur */
|
||||||
|
var $maxDate; /* Datum, wann die Max. Temp. gemessen wurde */
|
||||||
|
var $changing; /* Tendenz */
|
||||||
|
|
||||||
|
/* Konstruktor */
|
||||||
|
function Temp($sensId, & $connection){
|
||||||
|
$this->_fetchTempData($sensId, &$connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Funktion, die die Klasse mit den Weten initialisiert */
|
||||||
|
function _fetchTempData($sensId, &$connection){
|
||||||
|
|
||||||
|
/* Tabelle des Sensors bestimmen */
|
||||||
|
$tableQuery = "SELECT tabelle FROM sensoren, typen WHERE sensoren.id=".$sensId." AND typen.typ = sensoren.typ";
|
||||||
|
$table = $connection->fetchQueryResultLine($tableQuery);
|
||||||
|
|
||||||
|
/* Aktuelle Temperatur bestimmen */
|
||||||
|
$nowQuery = "SELECT temp, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as timestamp FROM ".$table['tabelle']." WHERE timestamp=(select max(timestamp) from ".$table['tabelle']." where sens_id=".$sensId.")";
|
||||||
|
$nowData = $connection->fetchQueryResultLine($nowQuery);
|
||||||
|
|
||||||
|
/* Max und Min-Werte bestimmen */
|
||||||
|
$maxQuery = "SELECT temp, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND temp=(SELECT max(temp) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.")";
|
||||||
|
$maxData = $connection->fetchQueryResultLine($maxQuery);
|
||||||
|
$minQuery = "SELECT temp, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND temp=(SELECT min(temp) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.")";
|
||||||
|
$minData = $connection->fetchQueryResultLine($minQuery);
|
||||||
|
|
||||||
|
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
||||||
|
$this->nowTemp = $nowData['temp'];
|
||||||
|
$this->nowDate = $nowData['timestamp'];
|
||||||
|
$this->maxTemp = $maxData['temp'];
|
||||||
|
$this->maxDate = $maxData['timestamp'];
|
||||||
|
$this->minTemp = $minData['temp'];
|
||||||
|
$this->minDate = $minData['timestamp'];
|
||||||
|
|
||||||
|
/* Durchschnittswert bestimmen lassen */
|
||||||
|
$this->_fetchAverage($sensId, $table['tabelle'], &$connection);
|
||||||
|
|
||||||
|
/* Tendenz bestimmen lassen */
|
||||||
|
$this->_fetchMoving($sensId, $table['tabelle'], &$connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* liefert den Durchschnittswert in einem bestimmtem Interval */
|
||||||
|
function _getAverage($sensId, $table, &$connection, $interval){
|
||||||
|
$avQuery = "SELECT (sum(temp)/count(temp)) as average, count(temp) as count FROM ".$table." WHERE sens_id=".$sensId." AND timestamp>(current_timestamp - INTERVAL '".$interval."')";
|
||||||
|
$avData = $connection->fetchQueryResultLine($avQuery);
|
||||||
|
return $avData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* momentanen Durchschnittswert bestimmen */
|
||||||
|
function _fetchAverage($sensId, $table, &$connection){
|
||||||
|
$avData = array('average'=>0, 'count'=>0); /* Array initialisieren */
|
||||||
|
$i = 3; /* Laufvariable */
|
||||||
|
while($avData['count']<5){ /* Schleife prüft, in welchem Interval 5 Werte zusammenkommen */
|
||||||
|
$avData = $this->_getAverage($sensId, $table, &$connection, ($i*10)." minutes"); /* Holt Werte mit gegebenem Interval */
|
||||||
|
$i++; /* Laufvariable erhöhen */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Werte den Klassenvariablen zuordnen */
|
||||||
|
$this->avVal = $avData['average'];
|
||||||
|
$this->avInter = $i*10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bestimmt die Tendenz */
|
||||||
|
function _fetchMoving($sensId, $table, &$connection){
|
||||||
|
$shortAvData = $this->_getAverage($sensId, $table, &$connection, "15 minutes"); /* Durchschnitt der letzten 15 minuten */
|
||||||
|
$longAvData = $this->_getAverage($sensId, $table, &$connection, "120 minutes"); /* Durchschnitt der letzten 120 Minuten */
|
||||||
|
if($shortAvData['count'] < 1 || $longAvData['count'] < 2){ /* Wenn in den letzten 5 minuten kein Wert kam oder in den letzten 120 min weniger als 3 Werte kamen */
|
||||||
|
$this->changing = "Berechnung momentan nicht möglich"; /* Dann ausgeben, dass momentan nichts berechnet werden kann */
|
||||||
|
return; /* und aus der Funktion huepfen */
|
||||||
|
}
|
||||||
|
$changing = $shortAvData['average'] - $longAvData['average']; /* Aenderung berechnen */
|
||||||
|
if($changing > 0){ /* Wenn Aenderung positiv */
|
||||||
|
$this->changing = "steigend (+ ".abs($changing * 0.1)."°C)"; /* dann steigende Tendenz ausgeben */
|
||||||
|
} elseif($changing < 0) { /* wenn Negativ */
|
||||||
|
$this->changing = "fallend (- ".abs($changing * 0.1)."°C)"; /* Fallende Tendenz ausgeben */
|
||||||
|
} else { /* an sonsten */
|
||||||
|
$this->changing = "gleichbleibend (± 0°C)"; /* sagen, das es gleich geblieben ist */
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- Funktionen, die aufgerufen werden um die geholeten Werte auszugeben --- */
|
||||||
|
function get_now_val(){
|
||||||
|
return $this->nowTemp * 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_now_date(){
|
||||||
|
return $this->nowDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_av_value(){
|
||||||
|
return $this->avVal * 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_av_interval(){
|
||||||
|
return $this->avInter;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_changing(){
|
||||||
|
return $this->changing;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_val(){
|
||||||
|
return $this->maxTemp * 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_max_date(){
|
||||||
|
return $this->maxDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_min_val(){
|
||||||
|
return $this->minTemp * 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_min_date(){
|
||||||
|
return $this->minDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue