performance optimizations at the frontend
git-svn-id: file:///home/jan/tmp/wetterstation/trunk@224 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
154280671a
commit
022071a473
|
|
@ -12,7 +12,7 @@
|
||||||
/* Default-Werte */
|
/* Default-Werte */
|
||||||
$default_set = "small";
|
$default_set = "small";
|
||||||
$default_chart_dir = "images/chart";
|
$default_chart_dir = "images/chart";
|
||||||
|
$average_interval = 30;
|
||||||
|
|
||||||
|
|
||||||
/* Graphen - Bilder */
|
/* Graphen - Bilder */
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class Connection{
|
||||||
$result = pg_query($this->conn, $query)
|
$result = pg_query($this->conn, $query)
|
||||||
or die('Abfrage fehlgeschlagen: ' . pg_last_error(). "\n<br>\nquery: '".$query."'");
|
or die('Abfrage fehlgeschlagen: ' . pg_last_error(). "\n<br>\nquery: '".$query."'");
|
||||||
while($array = pg_fetch_assoc($result))
|
while($array = pg_fetch_assoc($result))
|
||||||
array_push($returnArray, $array);
|
$returnArray[] = $array;
|
||||||
return $returnArray;
|
return $returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ class Module{
|
||||||
|
|
||||||
var $modName; /* Modul-Id */
|
var $modName; /* Modul-Id */
|
||||||
var $sensId; /* Sensor-Id */
|
var $sensId; /* Sensor-Id */
|
||||||
|
var $table; /* Tabellenname des Sensors */
|
||||||
var $connection; /* Connection - Instanz */
|
var $connection; /* Connection - Instanz */
|
||||||
var $parserInstance = NULL; /* Parser - Instanz */
|
var $parserInstance = NULL; /* Parser - Instanz */
|
||||||
var $connectionInstance = NULL; /* Connection - Instanz */
|
var $connectionInstance = NULL; /* Connection - Instanz */
|
||||||
|
|
@ -39,12 +40,20 @@ class Module{
|
||||||
$this->modName = $modName;
|
$this->modName = $modName;
|
||||||
$this->connection = &$connection;
|
$this->connection = &$connection;
|
||||||
$this->parserInstance = &$parser;
|
$this->parserInstance = &$parser;
|
||||||
|
$this->table = $this->_getTableName();
|
||||||
|
|
||||||
$parser->parseContent($this->_getModuleFilename("frame"), & $this, "top"); /* Oberen Modulrahmen parsen */
|
$parser->parseContent($this->_getModuleFilename("frame"), & $this, "top"); /* Oberen Modulrahmen parsen */
|
||||||
$parser->parseContent($this->_getModuleFilename($modName), & $this, NULL); /* Modul Parsen */
|
$parser->parseContent($this->_getModuleFilename($modName), & $this, NULL); /* Modul Parsen */
|
||||||
$parser->parseContent($this->_getModuleFilename("frame"), & $this, "bottom"); /* unteren Modulrahmen Parsen */
|
$parser->parseContent($this->_getModuleFilename("frame"), & $this, "bottom"); /* unteren Modulrahmen Parsen */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _getTableName(){
|
||||||
|
/* Tabelle des Sensors bestimmen */
|
||||||
|
$tableQuery = "SELECT tabelle FROM sensoren, typen WHERE sensoren.id=".$this->sensId." AND typen.typ = sensoren.typ";
|
||||||
|
$table = $this->connection->fetchQueryResultLine($tableQuery);
|
||||||
|
return $table['tabelle'];
|
||||||
|
}
|
||||||
|
|
||||||
/* Dateinamen des Modul-Files zusammenbauen */
|
/* Dateinamen des Modul-Files zusammenbauen */
|
||||||
function _getModuleFilename($modName){
|
function _getModuleFilename($modName){
|
||||||
global $path;
|
global $path;
|
||||||
|
|
@ -61,42 +70,43 @@ class Module{
|
||||||
/* Instanz der Temp-Klasse holen */
|
/* Instanz der Temp-Klasse holen */
|
||||||
function &_get_temp(){
|
function &_get_temp(){
|
||||||
if($this->tempInstance == NULL)
|
if($this->tempInstance == NULL)
|
||||||
$this->tempInstance = new Temp($this->sensId, $this->connection);
|
$this->tempInstance = new Temp($this->sensId, $this->connection, $this->table);
|
||||||
return $this->tempInstance;
|
return $this->tempInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Instanz der Rain-Klasse holen */
|
/* Instanz der Rain-Klasse holen */
|
||||||
function &_get_rain(){
|
function &_get_rain(){
|
||||||
if($this->rainInstance == NULL)
|
if($this->rainInstance == NULL)
|
||||||
$this->rainInstance = new Rain($this->sensId, $this->connection);
|
$this->rainInstance = new Rain($this->sensId, $this->connection, $this->table);
|
||||||
return $this->rainInstance;
|
return $this->rainInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Instanz der Hum-Klasse holen */
|
/* Instanz der Hum-Klasse holen */
|
||||||
function &_get_hum(){
|
function &_get_hum(){
|
||||||
if($this->humInstance == NULL)
|
if($this->humInstance == NULL)
|
||||||
$this->humInstance = new Hum($this->sensId, $this->connection);
|
$this->humInstance = new Hum($this->sensId, $this->connection, $this->table);
|
||||||
return $this->humInstance;
|
return $this->humInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Instanz der Press-Klasse holen */
|
/* Instanz der Press-Klasse holen */
|
||||||
function &_get_press(){
|
function &_get_press(){
|
||||||
if($this->pressInstance == NULL)
|
if($this->pressInstance == NULL)
|
||||||
$this->pressInstance = new Press($this->sensId, $this->connection);
|
$this->pressInstance = new Press($this->sensId, $this->connection, $this->table);
|
||||||
return $this->pressInstance;
|
return $this->pressInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Instanz der Wind-Klasse holen */
|
/* Instanz der Wind-Klasse holen */
|
||||||
function &_get_wind(){
|
function &_get_wind(){
|
||||||
if($this->windInstance == NULL)
|
if($this->windInstance == NULL)
|
||||||
$this->windInstance = new Wind($this->sensId, $this->connection);
|
$this->windInstance = new Wind($this->sensId, $this->connection, $this->table);
|
||||||
return $this->windInstance;
|
return $this->windInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback-Funktion, wird ausgefuehrt wenn {content:fill:xyz} gefunden wird */
|
/* Callback-Funktion, wird ausgefuehrt wenn {content:fill:xyz} gefunden wird */
|
||||||
function fill($contentId){
|
function fill($contentId){
|
||||||
$content_split = explode("_", $contentId); /* Modultyp bekommen */
|
$content_split = explode("_", $contentId); /* Modultyp bekommen */
|
||||||
$callObject = & call_user_method("_get_".$content_split[0], $this); /* Instanz der zum Modul gehoerenden Klasse */
|
$getMethod = "_get_".$content_split[0]; /* Instanz der zum Modul gehoerenden Klasse */
|
||||||
|
$callObject = & $this->$getMethod();; /* Instanz der zum Modul gehoerenden Klasse */
|
||||||
$funcName = "get".substr($contentId, strlen($content_split[0]), strlen($contentId)-strlen($content_split[0])); /* Namen der In der Instanz aufzurufenden Methode zusammenbauen */
|
$funcName = "get".substr($contentId, strlen($content_split[0]), strlen($contentId)-strlen($content_split[0])); /* Namen der In der Instanz aufzurufenden Methode zusammenbauen */
|
||||||
|
|
||||||
return $callObject->$funcName($content_split[1]); /* Methode ausfuehren (Wert holen) und zurueckgeben */
|
return $callObject->$funcName($content_split[1]); /* Methode ausfuehren (Wert holen) und zurueckgeben */
|
||||||
|
|
|
||||||
|
|
@ -13,49 +13,52 @@ class Hum{
|
||||||
var $nowDate; /* datum des letzten Messvorgangs */
|
var $nowDate; /* datum des letzten Messvorgangs */
|
||||||
var $avVal = "nc"; /* Durchschnittswert */
|
var $avVal = "nc"; /* Durchschnittswert */
|
||||||
var $avInter = "nc"; /* Interval des Durchschnittswertes */
|
var $avInter = "nc"; /* Interval des Durchschnittswertes */
|
||||||
var $minHum; /* Minimale Luftfeuchtigkeit */
|
var $minHum = "nc"; /* Minimale Luftfeuchtigkeit */
|
||||||
var $minDate; /* Datum, wann die Minimale Luftfeuchtigkeit gemessen wurde */
|
var $minDate = "nc"; /* Datum, wann die Minimale Luftfeuchtigkeit gemessen wurde */
|
||||||
var $maxHum; /* Maximale Luftfeuchtigkeit */
|
var $maxHum = "nc"; /* Maximale Luftfeuchtigkeit */
|
||||||
var $maxDate; /* Datum, wann die Max. Luftfeuchtigkeit. gemessen wurde */
|
var $maxDate = "nc"; /* Datum, wann die Max. Luftfeuchtigkeit. gemessen wurde */
|
||||||
var $changing = "nc"; /* Tendenz */
|
var $changing = "nc"; /* Tendenz */
|
||||||
var $connection;
|
var $connection;
|
||||||
var $sensId;
|
var $sensId;
|
||||||
var $table;
|
var $table;
|
||||||
|
|
||||||
/* Konstruktor */
|
/* Konstruktor */
|
||||||
function Hum($sensId, & $connection){
|
function Hum($sensId, & $connection, $table){
|
||||||
$this->_fetchHumData($sensId, &$connection);
|
$this->connection = &$connection;
|
||||||
|
$this->sensId = $sensId;
|
||||||
|
$this->table = $table;
|
||||||
|
$this->_fetchHumData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Funktion, die die Klasse mit den Weten initialisiert */
|
/* Funktion, die die Klasse mit den Weten initialisiert */
|
||||||
function _fetchHumData($sensId, &$connection){
|
function _fetchHumData(){
|
||||||
$this->connection = &$connection;
|
|
||||||
$this->sensId = $sensId;
|
|
||||||
|
|
||||||
/* Tabelle des Sensors bestimmen */
|
|
||||||
$tableQuery = "SELECT tabelle FROM sensoren, typen WHERE sensoren.id=".$sensId." AND typen.typ = sensoren.typ";
|
|
||||||
$table = $connection->fetchQueryResultLine($tableQuery);
|
|
||||||
$this->table = $table['tabelle'];
|
|
||||||
|
|
||||||
/* Aktuelle Luftfeuchtigkeit bestimmen */
|
/* Aktuelle Luftfeuchtigkeit bestimmen */
|
||||||
$nowQuery = "SELECT hum, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." ORDER BY timestamp DESC LIMIT 1";
|
$nowQuery = "SELECT hum, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$this->table." WHERE sens_id=".$this->sensId." ORDER BY timestamp DESC LIMIT 1";
|
||||||
$nowData = $connection->fetchQueryResultLine($nowQuery);
|
$nowData = $this->connection->fetchQueryResultLine($nowQuery);
|
||||||
|
|
||||||
/* Max und Min-Werte bestimmen */
|
|
||||||
$maxQuery = "SELECT hum, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND hum=(SELECT max(hum) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.") ORDER BY timestamp DESC LIMIT 1";
|
|
||||||
$maxData = $connection->fetchQueryResultLine($maxQuery);
|
|
||||||
$minQuery = "SELECT hum, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND hum=(SELECT min(hum) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.") ORDER BY timestamp DESC LIMIT 1";
|
|
||||||
$minData = $connection->fetchQueryResultLine($minQuery);
|
|
||||||
|
|
||||||
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
||||||
$this->nowHum = $nowData['hum'];
|
$this->nowHum = $nowData['hum'];
|
||||||
$this->nowDate = $nowData['text_timestamp'];
|
$this->nowDate = $nowData['text_timestamp'];
|
||||||
$this->maxHum = $maxData['hum'];
|
|
||||||
$this->maxDate = $maxData['text_timestamp'];
|
|
||||||
$this->minHum = $minData['hum'];
|
|
||||||
$this->minDate = $minData['text_timestamp'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _fetchMinMax(){
|
||||||
|
$Query = "SELECT max(hum) as max, min(hum) as min FROM ".$this->table." WHERE sens_id=".$this->sensId."";
|
||||||
|
$Data = $this->connection->fetchQueryResultLine($Query);
|
||||||
|
$this->minHum = $Data['min'];
|
||||||
|
$this->maxHum = $Data['max'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function _fetchMinMaxDate(){
|
||||||
|
if($this->maxHum == "nc" || $this->minHum == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
|
$Query = "SELECT to_char(max(timestamp), 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$this->table." WHERE sens_id=".$this->sensId." AND hum=".$this->maxHum." OR hum=".$this->minHum." GROUP BY hum ORDER BY hum ASC LIMIT 2";
|
||||||
|
$Data = $this->connection->fetchQueryResultSet($Query);
|
||||||
|
$this->minDate = $Data[0]['text_timestamp'];
|
||||||
|
$this->maxDate = $Data[1]['text_timestamp'];
|
||||||
|
}
|
||||||
|
|
||||||
/* liefert den Durchschnittswert in einem bestimmtem Interval */
|
/* liefert den Durchschnittswert in einem bestimmtem Interval */
|
||||||
function _getAverage($interval){
|
function _getAverage($interval){
|
||||||
$avQuery = "SELECT avg(hum) as average, count(hum) as count FROM ".$this->table." WHERE sens_id=".$this->sensId." AND timestamp>(current_timestamp - INTERVAL '".$interval."')";
|
$avQuery = "SELECT avg(hum) as average, count(hum) as count FROM ".$this->table." WHERE sens_id=".$this->sensId." AND timestamp>(current_timestamp - INTERVAL '".$interval."')";
|
||||||
|
|
@ -124,18 +127,30 @@ class Hum{
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_max_val(){
|
function get_max_val(){
|
||||||
|
if($this->maxHum == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
return $this->maxHum;
|
return $this->maxHum;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_max_date(){
|
function get_max_date(){
|
||||||
|
if($this->minDate == "nc"){
|
||||||
|
$this->_fetchMinMaxDate();
|
||||||
|
}
|
||||||
return $this->maxDate;
|
return $this->maxDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_min_val(){
|
function get_min_val(){
|
||||||
|
if($this->minHum == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
return $this->minHum;
|
return $this->minHum;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_min_date(){
|
function get_min_date(){
|
||||||
|
if($this->maxDate == "nc"){
|
||||||
|
$this->_fetchMinMaxDate();
|
||||||
|
}
|
||||||
return $this->minDate;
|
return $this->minDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,49 +12,52 @@ class Press{
|
||||||
var $nowDate; /* datum des letzten Messvorgangs */
|
var $nowDate; /* datum des letzten Messvorgangs */
|
||||||
var $avVal = "nc"; /* Durchschnittswert */
|
var $avVal = "nc"; /* Durchschnittswert */
|
||||||
var $avInter = "nc"; /* Interval des Durchschnittswertes */
|
var $avInter = "nc"; /* Interval des Durchschnittswertes */
|
||||||
var $minPress; /* Minimaler Luftdruck */
|
var $minPress = "nc"; /* Minimaler Luftdruck */
|
||||||
var $minDate; /* Datum, wann der Minimale Luftdruck gemessen wurde */
|
var $minDate = "nc"; /* Datum, wann der Minimale Luftdruck gemessen wurde */
|
||||||
var $maxPress; /* Maximale Luftdruck */
|
var $maxPress = "nc"; /* Maximale Luftdruck */
|
||||||
var $maxDate; /* Datum, wann der Max. Luftdruck gemessen wurde */
|
var $maxDate = "nc"; /* Datum, wann der Max. Luftdruck gemessen wurde */
|
||||||
var $changing = "nc"; /* Tendenz */
|
var $changing = "nc"; /* Tendenz */
|
||||||
var $connection;
|
var $connection;
|
||||||
var $sensId;
|
var $sensId;
|
||||||
var $table;
|
var $table;
|
||||||
|
|
||||||
/* Konstruktor */
|
/* Konstruktor */
|
||||||
function Press($sensId, & $connection){
|
function Press($sensId, & $connection, $table){
|
||||||
$this->_fetchPressData($sensId, &$connection);
|
$this->connection = &$connection;
|
||||||
|
$this->sensId = $sensId;
|
||||||
|
$this->table = $table;
|
||||||
|
$this->_fetchPressData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Funktion, die die Klasse mit den Weten initialisiert */
|
/* Funktion, die die Klasse mit den Weten initialisiert */
|
||||||
function _fetchPressData($sensId, &$connection){
|
function _fetchPressData(){
|
||||||
$this->connection = &$connection;
|
|
||||||
$this->sensId = $sensId;
|
|
||||||
|
|
||||||
/* Tabelle des Sensors bestimmen */
|
|
||||||
$tableQuery = "SELECT tabelle FROM sensoren, typen WHERE sensoren.id=".$sensId." AND typen.typ = sensoren.typ";
|
|
||||||
$table = $connection->fetchQueryResultLine($tableQuery);
|
|
||||||
$this->table = $table['tabelle'];
|
|
||||||
|
|
||||||
/* Aktuelle Luftdruck bestimmen */
|
/* Aktuelle Luftdruck bestimmen */
|
||||||
$nowQuery = "SELECT press, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." ORDER BY timestamp DESC LIMIT 1";
|
$nowQuery = "SELECT press, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$this->table." WHERE sens_id=".$this->sensId." ORDER BY timestamp DESC LIMIT 1";
|
||||||
$nowData = $connection->fetchQueryResultLine($nowQuery);
|
$nowData = $this->connection->fetchQueryResultLine($nowQuery);
|
||||||
|
|
||||||
/* Max und Min-Werte bestimmen */
|
|
||||||
$maxQuery = "SELECT press, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND press=(SELECT max(press) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.") ORDER BY timestamp DESC LIMIT 1";
|
|
||||||
$maxData = $connection->fetchQueryResultLine($maxQuery);
|
|
||||||
$minQuery = "SELECT press, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND press=(SELECT min(press) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.") ORDER BY timestamp DESC LIMIT 1";
|
|
||||||
$minData = $connection->fetchQueryResultLine($minQuery);
|
|
||||||
|
|
||||||
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
||||||
$this->nowPress = $nowData['press'];
|
$this->nowPress = $nowData['press'];
|
||||||
$this->nowDate = $nowData['text_timestamp'];
|
$this->nowDate = $nowData['text_timestamp'];
|
||||||
$this->maxPress = $maxData['press'];
|
|
||||||
$this->maxDate = $maxData['text_timestamp'];
|
|
||||||
$this->minPress = $minData['press'];
|
|
||||||
$this->minDate = $minData['text_timestamp'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _fetchMinMax(){
|
||||||
|
$Query = "SELECT max(press) as max, min(press) as min FROM ".$this->table." WHERE sens_id=".$this->sensId."";
|
||||||
|
$Data = $this->connection->fetchQueryResultLine($Query);
|
||||||
|
$this->minPress = $Data['min'];
|
||||||
|
$this->maxPress = $Data['max'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function _fetchMinMaxDate(){
|
||||||
|
if($this->maxHum == "nc" || $this->minHum == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
|
$Query = "SELECT to_char(max(timestamp), 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$this->table." WHERE sens_id=".$this->sensId." AND press=".$this->maxPress." OR press=".$this->minPress." GROUP BY press ORDER BY press ASC LIMIT 2";
|
||||||
|
$Data = $this->connection->fetchQueryResultSet($Query);
|
||||||
|
$this->minDate = $Data[0]['text_timestamp'];
|
||||||
|
$this->maxDate = $Data[1]['text_timestamp'];
|
||||||
|
}
|
||||||
|
|
||||||
/* liefert den Durchschnittswert in einem bestimmtem Interval */
|
/* liefert den Durchschnittswert in einem bestimmtem Interval */
|
||||||
function _getAverage($interval){
|
function _getAverage($interval){
|
||||||
$avQuery = "SELECT avg(press) as average, count(press) as count FROM ".$this->table." WHERE sens_id=".$this->sensId." AND timestamp>(current_timestamp - INTERVAL '".$interval."')";
|
$avQuery = "SELECT avg(press) as average, count(press) as count FROM ".$this->table." WHERE sens_id=".$this->sensId." AND timestamp>(current_timestamp - INTERVAL '".$interval."')";
|
||||||
|
|
@ -123,18 +126,30 @@ class Press{
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_max_val(){
|
function get_max_val(){
|
||||||
|
if($this->maxPress == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
return $this->maxPress;
|
return $this->maxPress;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_max_date(){
|
function get_max_date(){
|
||||||
|
if($this->minDate == "nc"){
|
||||||
|
$this->_fetchMinMaxDate();
|
||||||
|
}
|
||||||
return $this->maxDate;
|
return $this->maxDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_min_val(){
|
function get_min_val(){
|
||||||
|
if($this->minPress == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
return $this->minPress;
|
return $this->minPress;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_min_date(){
|
function get_min_date(){
|
||||||
|
if($this->maxDate == "nc"){
|
||||||
|
$this->_fetchMinMaxDate();
|
||||||
|
}
|
||||||
return $this->minDate;
|
return $this->minDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,16 +26,10 @@ class Rain{
|
||||||
var $sensId;
|
var $sensId;
|
||||||
|
|
||||||
/* Konstruktor, Holt die Werte aus der Datenbank und fuellt die Variablen damit */
|
/* Konstruktor, Holt die Werte aus der Datenbank und fuellt die Variablen damit */
|
||||||
function Rain($sensId, & $connection){
|
function Rain($sensId, & $connection, $table){
|
||||||
$this->connection = &$connection;
|
$this->connection = &$connection;
|
||||||
$this->sensId = $sensId;
|
$this->sensId = $sensId;
|
||||||
|
|
||||||
/* 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']);
|
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Momentane Werte aus der Datenbank holen */
|
/* Momentane Werte aus der Datenbank holen */
|
||||||
|
|
|
||||||
|
|
@ -12,47 +12,50 @@ class Temp{
|
||||||
var $nowDate; /* datum des letzten Messvorgangs */
|
var $nowDate; /* datum des letzten Messvorgangs */
|
||||||
var $avVal = "nc"; /* Durchschnittswert */
|
var $avVal = "nc"; /* Durchschnittswert */
|
||||||
var $avInter = "nc"; /* Interval des Durchschnittswertes */
|
var $avInter = "nc"; /* Interval des Durchschnittswertes */
|
||||||
var $minTemp; /* Minimale Temparatur */
|
var $minTemp = "nc"; /* Minimale Temparatur */
|
||||||
var $minDate; /* Datum, wann die Minimale Temparatur gemessen wurde */
|
var $minDate = "nc"; /* Datum, wann die Minimale Temparatur gemessen wurde */
|
||||||
var $maxTemp; /* Maximale Temparatur */
|
var $maxTemp = "nc"; /* Maximale Temparatur */
|
||||||
var $maxDate; /* Datum, wann die Max. Temp. gemessen wurde */
|
var $maxDate = "nc"; /* Datum, wann die Max. Temp. gemessen wurde */
|
||||||
var $changing = "nc"; /* Tendenz */
|
var $changing = "nc"; /* Tendenz */
|
||||||
var $connection;
|
var $connection;
|
||||||
var $sensId;
|
var $sensId;
|
||||||
var $table;
|
var $table;
|
||||||
|
|
||||||
/* Konstruktor */
|
/* Konstruktor */
|
||||||
function Temp($sensId, & $connection){
|
function Temp($sensId, & $connection, $table){
|
||||||
$this->_fetchTempData($sensId, &$connection);
|
$this->connection = &$connection;
|
||||||
|
$this->sensId = $sensId;
|
||||||
|
$this->table = $table;
|
||||||
|
$this->_fetchTempData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Funktion, die die Klasse mit den Weten initialisiert */
|
/* Funktion, die die Klasse mit den Weten initialisiert */
|
||||||
function _fetchTempData($sensId, &$connection){
|
function _fetchTempData(){
|
||||||
$this->connection = &$connection;
|
|
||||||
$this->sensId = $sensId;
|
|
||||||
|
|
||||||
/* Tabelle des Sensors bestimmen */
|
|
||||||
$tableQuery = "SELECT tabelle FROM sensoren, typen WHERE sensoren.id=".$sensId." AND typen.typ = sensoren.typ";
|
|
||||||
$table = $connection->fetchQueryResultLine($tableQuery);
|
|
||||||
$this->table = $table['tabelle'];
|
|
||||||
|
|
||||||
/* Aktuelle Temperatur bestimmen */
|
/* Aktuelle Temperatur bestimmen */
|
||||||
$nowQuery = "SELECT temp, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." ORDER BY timestamp DESC LIMIT 1";
|
$nowQuery = "SELECT temp, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$this->table." WHERE sens_id=".$this->sensId." ORDER BY timestamp DESC LIMIT 1";
|
||||||
$nowData = $connection->fetchQueryResultLine($nowQuery);
|
$nowData = $this->connection->fetchQueryResultLine($nowQuery);
|
||||||
|
|
||||||
/* Max und Min-Werte bestimmen */
|
|
||||||
$maxQuery = "SELECT temp, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND temp=(SELECT max(temp) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.") ORDER BY timestamp DESC LIMIT 1";
|
|
||||||
$maxData = $connection->fetchQueryResultLine($maxQuery);
|
|
||||||
$minQuery = "SELECT temp, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND temp=(SELECT min(temp) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.") ORDER BY timestamp DESC LIMIT 1";
|
|
||||||
$minData = $connection->fetchQueryResultLine($minQuery);
|
|
||||||
|
|
||||||
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
||||||
$this->nowTemp = $nowData['temp'];
|
$this->nowTemp = $nowData['temp'];
|
||||||
$this->nowDate = $nowData['text_timestamp'];
|
$this->nowDate = $nowData['text_timestamp'];
|
||||||
$this->maxTemp = $maxData['temp'];
|
}
|
||||||
$this->maxDate = $maxData['text_timestamp'];
|
|
||||||
$this->minTemp = $minData['temp'];
|
function _fetchMinMax(){
|
||||||
$this->minDate = $minData['text_timestamp'];
|
$Query = "SELECT max(temp) as max, min(temp) as min FROM ".$this->table." WHERE sens_id=".$this->sensId."";
|
||||||
|
$Data = $this->connection->fetchQueryResultLine($Query);
|
||||||
|
$this->minTemp = $Data['min'];
|
||||||
|
$this->maxTemp = $Data['max'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function _fetchMinMaxDate(){
|
||||||
|
if($this->maxHum == "nc" || $this->minHum == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
|
$Query = "SELECT to_char(max(timestamp), 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$this->table." WHERE sens_id=".$this->sensId." AND temp=".$this->maxTemp." OR temp=".$this->minTemp." GROUP BY temp ORDER BY temp ASC LIMIT 2";
|
||||||
|
$Data = $this->connection->fetchQueryResultSet($Query);
|
||||||
|
$this->minDate = $Data[0]['text_timestamp'];
|
||||||
|
$this->maxDate = $Data[1]['text_timestamp'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* liefert den Durchschnittswert in einem bestimmtem Interval */
|
/* liefert den Durchschnittswert in einem bestimmtem Interval */
|
||||||
|
|
@ -123,18 +126,30 @@ class Temp{
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_max_val(){
|
function get_max_val(){
|
||||||
return $this->maxTemp * 0.1;
|
if($this->maxTemp == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
|
return round($this->maxTemp*0.1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_max_date(){
|
function get_max_date(){
|
||||||
|
if($this->minDate == "nc"){
|
||||||
|
$this->_fetchMinMaxDate();
|
||||||
|
}
|
||||||
return $this->maxDate;
|
return $this->maxDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_min_val(){
|
function get_min_val(){
|
||||||
return $this->minTemp * 0.1;
|
if($this->minTemp == "nc"){
|
||||||
|
$this->_fetchMinMax();
|
||||||
|
}
|
||||||
|
return round($this->minTemp*0.1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_min_date(){
|
function get_min_date(){
|
||||||
|
if($this->maxDate == "nc"){
|
||||||
|
$this->_fetchMinMaxDate();
|
||||||
|
}
|
||||||
return $this->minDate;
|
return $this->minDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,27 +22,23 @@ class Wind{
|
||||||
var $table;
|
var $table;
|
||||||
|
|
||||||
/* Konstruktor */
|
/* Konstruktor */
|
||||||
function Wind($sensId, & $connection){
|
function Wind($sensId, & $connection, $table){
|
||||||
$this->_fetchWindData($sensId, &$connection);
|
$this->table = $table;
|
||||||
|
$this->connection = &$connection;
|
||||||
|
$this->sensId = $sensId;
|
||||||
|
$this->_fetchWindData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Funktion, die die Klasse mit den Weten initialisiert */
|
/* Funktion, die die Klasse mit den Weten initialisiert */
|
||||||
function _fetchWindData($sensId, &$connection){
|
function _fetchWindData(){
|
||||||
$this->connection = &$connection;
|
|
||||||
$this->sensId = $sensId;
|
|
||||||
|
|
||||||
/* Tabelle des Sensors bestimmen */
|
|
||||||
$tableQuery = "SELECT tabelle FROM sensoren, typen WHERE sensoren.id=".$sensId." AND typen.typ = sensoren.typ";
|
|
||||||
$table = $connection->fetchQueryResultLine($tableQuery);
|
|
||||||
$this->table = $table['tabelle'];
|
|
||||||
|
|
||||||
/* Aktuelle Wind bestimmen */
|
/* Aktuelle Wind bestimmen */
|
||||||
$nowQuery = "SELECT geschw as wind, richt as dir, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." ORDER BY timestamp DESC LIMIT 1";
|
$nowQuery = "SELECT geschw as wind, richt as dir, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$this->table." WHERE sens_id=".$this->sensId." ORDER BY timestamp DESC LIMIT 1";
|
||||||
$nowData = $connection->fetchQueryResultLine($nowQuery);
|
$nowData = $this->connection->fetchQueryResultLine($nowQuery);
|
||||||
|
|
||||||
/* Max und Min-Werte bestimmen */
|
/* Max und Min-Werte bestimmen */
|
||||||
$maxQuery = "SELECT geschw as wind, richt as dir, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$table['tabelle']." WHERE sens_id=".$sensId." AND geschw=(SELECT max(geschw) FROM ".$table['tabelle']." WHERE sens_id=".$sensId.") ORDER BY timestamp DESC LIMIT 1";
|
$maxQuery = "SELECT geschw as wind, richt as dir, to_char(timestamp, 'DD.MM.YYYY HH24:MI') as text_timestamp FROM ".$this->table." WHERE sens_id=".$this->sensId." AND geschw=(SELECT max(geschw) FROM ".$this->table." WHERE sens_id=".$this->sensId.") ORDER BY timestamp DESC LIMIT 1";
|
||||||
$maxData = $connection->fetchQueryResultLine($maxQuery);
|
$maxData = $this->connection->fetchQueryResultLine($maxQuery);
|
||||||
|
|
||||||
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
/* Bestimmte Werte den Klassenvariablen zuordnen */
|
||||||
$this->nowWind = $nowData['wind'];
|
$this->nowWind = $nowData['wind'];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue