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:
losinshi 2007-02-18 15:25:41 +00:00
parent 154280671a
commit 022071a473
8 changed files with 156 additions and 111 deletions

View File

@ -12,7 +12,7 @@
/* Default-Werte */
$default_set = "small";
$default_chart_dir = "images/chart";
$average_interval = 30;
/* Graphen - Bilder */

View File

@ -52,7 +52,7 @@ class Connection{
$result = pg_query($this->conn, $query)
or die('Abfrage fehlgeschlagen: ' . pg_last_error(). "\n<br>\nquery: '".$query."'");
while($array = pg_fetch_assoc($result))
array_push($returnArray, $array);
$returnArray[] = $array;
return $returnArray;
}

View File

@ -21,6 +21,7 @@ class Module{
var $modName; /* Modul-Id */
var $sensId; /* Sensor-Id */
var $table; /* Tabellenname des Sensors */
var $connection; /* Connection - Instanz */
var $parserInstance = NULL; /* Parser - Instanz */
var $connectionInstance = NULL; /* Connection - Instanz */
@ -39,12 +40,20 @@ class Module{
$this->modName = $modName;
$this->connection = &$connection;
$this->parserInstance = &$parser;
$this->table = $this->_getTableName();
$parser->parseContent($this->_getModuleFilename("frame"), & $this, "top"); /* Oberen Modulrahmen parsen */
$parser->parseContent($this->_getModuleFilename($modName), & $this, NULL); /* Modul 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 */
function _getModuleFilename($modName){
global $path;
@ -61,42 +70,43 @@ class Module{
/* Instanz der Temp-Klasse holen */
function &_get_temp(){
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;
}
/* Instanz der Rain-Klasse holen */
function &_get_rain(){
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;
}
/* Instanz der Hum-Klasse holen */
function &_get_hum(){
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;
}
/* Instanz der Press-Klasse holen */
function &_get_press(){
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;
}
/* Instanz der Wind-Klasse holen */
function &_get_wind(){
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;
}
/* Callback-Funktion, wird ausgefuehrt wenn {content:fill:xyz} gefunden wird */
function fill($contentId){
$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 */
return $callObject->$funcName($content_split[1]); /* Methode ausfuehren (Wert holen) und zurueckgeben */

View File

@ -13,47 +13,50 @@ class Hum{
var $nowDate; /* datum des letzten Messvorgangs */
var $avVal = "nc"; /* Durchschnittswert */
var $avInter = "nc"; /* Interval des Durchschnittswertes */
var $minHum; /* Minimale Luftfeuchtigkeit */
var $minDate; /* Datum, wann die Minimale Luftfeuchtigkeit gemessen wurde */
var $maxHum; /* Maximale Luftfeuchtigkeit */
var $maxDate; /* Datum, wann die Max. Luftfeuchtigkeit. gemessen wurde */
var $minHum = "nc"; /* Minimale Luftfeuchtigkeit */
var $minDate = "nc"; /* Datum, wann die Minimale Luftfeuchtigkeit gemessen wurde */
var $maxHum = "nc"; /* Maximale Luftfeuchtigkeit */
var $maxDate = "nc"; /* Datum, wann die Max. Luftfeuchtigkeit. gemessen wurde */
var $changing = "nc"; /* Tendenz */
var $connection;
var $sensId;
var $table;
/* Konstruktor */
function Hum($sensId, & $connection){
$this->_fetchHumData($sensId, &$connection);
function Hum($sensId, & $connection, $table){
$this->connection = &$connection;
$this->sensId = $sensId;
$this->table = $table;
$this->_fetchHumData();
}
/* Funktion, die die Klasse mit den Weten initialisiert */
function _fetchHumData($sensId, &$connection){
$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'];
function _fetchHumData(){
/* 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";
$nowData = $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);
$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 = $this->connection->fetchQueryResultLine($nowQuery);
/* Bestimmte Werte den Klassenvariablen zuordnen */
$this->nowHum = $nowData['hum'];
$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 */
@ -124,18 +127,30 @@ class Hum{
}
function get_max_val(){
if($this->maxHum == "nc"){
$this->_fetchMinMax();
}
return $this->maxHum;
}
function get_max_date(){
if($this->minDate == "nc"){
$this->_fetchMinMaxDate();
}
return $this->maxDate;
}
function get_min_val(){
if($this->minHum == "nc"){
$this->_fetchMinMax();
}
return $this->minHum;
}
function get_min_date(){
if($this->maxDate == "nc"){
$this->_fetchMinMaxDate();
}
return $this->minDate;
}

View File

@ -12,47 +12,50 @@ class Press{
var $nowDate; /* datum des letzten Messvorgangs */
var $avVal = "nc"; /* Durchschnittswert */
var $avInter = "nc"; /* Interval des Durchschnittswertes */
var $minPress; /* Minimaler Luftdruck */
var $minDate; /* Datum, wann der Minimale Luftdruck gemessen wurde */
var $maxPress; /* Maximale Luftdruck */
var $maxDate; /* Datum, wann der Max. Luftdruck gemessen wurde */
var $minPress = "nc"; /* Minimaler Luftdruck */
var $minDate = "nc"; /* Datum, wann der Minimale Luftdruck gemessen wurde */
var $maxPress = "nc"; /* Maximale Luftdruck */
var $maxDate = "nc"; /* Datum, wann der Max. Luftdruck gemessen wurde */
var $changing = "nc"; /* Tendenz */
var $connection;
var $sensId;
var $table;
/* Konstruktor */
function Press($sensId, & $connection){
$this->_fetchPressData($sensId, &$connection);
function Press($sensId, & $connection, $table){
$this->connection = &$connection;
$this->sensId = $sensId;
$this->table = $table;
$this->_fetchPressData();
}
/* Funktion, die die Klasse mit den Weten initialisiert */
function _fetchPressData($sensId, &$connection){
$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'];
function _fetchPressData(){
/* 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";
$nowData = $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);
$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 = $this->connection->fetchQueryResultLine($nowQuery);
/* Bestimmte Werte den Klassenvariablen zuordnen */
$this->nowPress = $nowData['press'];
$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 */
@ -123,18 +126,30 @@ class Press{
}
function get_max_val(){
if($this->maxPress == "nc"){
$this->_fetchMinMax();
}
return $this->maxPress;
}
function get_max_date(){
if($this->minDate == "nc"){
$this->_fetchMinMaxDate();
}
return $this->maxDate;
}
function get_min_val(){
if($this->minPress == "nc"){
$this->_fetchMinMax();
}
return $this->minPress;
}
function get_min_date(){
if($this->maxDate == "nc"){
$this->_fetchMinMaxDate();
}
return $this->minDate;
}

View File

@ -26,16 +26,10 @@ class Rain{
var $sensId;
/* 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->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;
}
/* Momentane Werte aus der Datenbank holen */

View File

@ -12,47 +12,50 @@ class Temp{
var $nowDate; /* datum des letzten Messvorgangs */
var $avVal = "nc"; /* Durchschnittswert */
var $avInter = "nc"; /* 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 $minTemp = "nc"; /* Minimale Temparatur */
var $minDate = "nc"; /* Datum, wann die Minimale Temparatur gemessen wurde */
var $maxTemp = "nc"; /* Maximale Temparatur */
var $maxDate = "nc"; /* Datum, wann die Max. Temp. gemessen wurde */
var $changing = "nc"; /* Tendenz */
var $connection;
var $sensId;
var $table;
/* Konstruktor */
function Temp($sensId, & $connection){
$this->_fetchTempData($sensId, &$connection);
function Temp($sensId, & $connection, $table){
$this->connection = &$connection;
$this->sensId = $sensId;
$this->table = $table;
$this->_fetchTempData();
}
/* Funktion, die die Klasse mit den Weten initialisiert */
function _fetchTempData($sensId, &$connection){
$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'];
function _fetchTempData(){
/* 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";
$nowData = $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);
$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 = $this->connection->fetchQueryResultLine($nowQuery);
/* Bestimmte Werte den Klassenvariablen zuordnen */
$this->nowTemp = $nowData['temp'];
$this->nowDate = $nowData['text_timestamp'];
$this->maxTemp = $maxData['temp'];
$this->maxDate = $maxData['text_timestamp'];
$this->minTemp = $minData['temp'];
$this->minDate = $minData['text_timestamp'];
}
function _fetchMinMax(){
$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 */
@ -123,18 +126,30 @@ class Temp{
}
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(){
if($this->minDate == "nc"){
$this->_fetchMinMaxDate();
}
return $this->maxDate;
}
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(){
if($this->maxDate == "nc"){
$this->_fetchMinMaxDate();
}
return $this->minDate;
}

View File

@ -22,27 +22,23 @@ class Wind{
var $table;
/* Konstruktor */
function Wind($sensId, & $connection){
$this->_fetchWindData($sensId, &$connection);
function Wind($sensId, & $connection, $table){
$this->table = $table;
$this->connection = &$connection;
$this->sensId = $sensId;
$this->_fetchWindData();
}
/* Funktion, die die Klasse mit den Weten initialisiert */
function _fetchWindData($sensId, &$connection){
$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'];
function _fetchWindData(){
/* 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";
$nowData = $connection->fetchQueryResultLine($nowQuery);
$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 = $this->connection->fetchQueryResultLine($nowQuery);
/* 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";
$maxData = $connection->fetchQueryResultLine($maxQuery);
$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 = $this->connection->fetchQueryResultLine($maxQuery);
/* Bestimmte Werte den Klassenvariablen zuordnen */
$this->nowWind = $nowData['wind'];