diff --git a/webstuff/frontend/content/modules/mod_rain.html b/webstuff/frontend/content/modules/mod_rain.html new file mode 100644 index 0000000..88631e9 --- /dev/null +++ b/webstuff/frontend/content/modules/mod_rain.html @@ -0,0 +1,35 @@ +

Regen - {content:fill:sens_location}

+

{content:fill:sens_description}

+

Aktuelle Werte

+ + + + + + + + + + + + + + + + +
Letze Stunde:{content:fill:rain_now_hour} l/m2
Heute:{content:fill:rain_now_day} l/m2 
Diesen Monat:{content:fill:rain_now_month} l/m2 
Dies Jahr:{content:fill:rain_now_year} l/m2 
Seit Messbegin:{content:fill:rain_now_all} l/m2 
+

Extrema

+ + + + + + + + + + + + + +
Regenreichste Stunde:{content:fill:rain_max_hour_val} l/m2{content:fill:rain_max_hour_date}
Regenreichster Tag:{content:fill:rain_max_day_val} l/m2{content:fill:rain_max_day_date}
Regenreichster Monat:{content:fill:rain_max_month_val} l/m2{content:fill:rain_max_month_date}
Regenreichstes Jahr:{content:fill:rain_max_year_val} l/m2{content:fill:rain_max_year_date}
diff --git a/webstuff/frontend/php_inc/rain.inc.php b/webstuff/frontend/php_inc/rain.inc.php new file mode 100644 index 0000000..b816016 --- /dev/null +++ b/webstuff/frontend/php_inc/rain.inc.php @@ -0,0 +1,106 @@ +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']; + } + +} +?> diff --git a/webstuff/frontend/php_inc/sensor.inc.php b/webstuff/frontend/php_inc/sensor.inc.php new file mode 100644 index 0000000..2e4bd07 --- /dev/null +++ b/webstuff/frontend/php_inc/sensor.inc.php @@ -0,0 +1,54 @@ +_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; + } +} + +?> diff --git a/webstuff/frontend/php_inc/temp.inc.php b/webstuff/frontend/php_inc/temp.inc.php new file mode 100644 index 0000000..8848134 --- /dev/null +++ b/webstuff/frontend/php_inc/temp.inc.php @@ -0,0 +1,129 @@ +_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; + } + +} +?>