Finished temperature module in Webfrontend

git-svn-id: file:///home/jan/tmp/wetterstation/trunk@25 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2006-08-17 16:13:47 +00:00
parent 4249404692
commit f27798bc3f
6 changed files with 93 additions and 49 deletions

View File

@ -1 +1 @@
{content:addModule:temp_1}{content:addModule:temp_2}
{content:addModule:temp_1}{content:addModule:temp_4}

View File

@ -2,22 +2,22 @@
<p class="mod_description">{content:fill:sens_description}</p>
<h4 class="mod_subhead">Momentane Werte</h4>
<table class="mod_temp_now_data">
<tr>
<td>Momentan:</td><td>{content:fill:temp_now_val}</td><td>{content:fill:temp_now_date}</td>
<tr class="mod_temp_current_row">
<td class="mod_line_desc">Momentan:</td><td class="mod_line_val">{content:fill:temp_now_val}&deg;C</td><td class="mod_line_date">{content:fill:temp_now_date}</td>
</tr>
<tr>
<td>Durchschnitt (halbe std.):</td><td>{content:fill:temp_av_value}</td><td>&nbsp;</td>
<tr class="mod_temp_average_row">
<td class="mod_line_desc">Durchschnitt ({content:fill:temp_av_interval} min.):</td><td class="mod_line_val">{content:fill:temp_av_value}&deg;C</td><td>&nbsp;</td>
</tr>
<tr>
<td>Tendenz (2 std.):</td><td>{content:fill:temp_changing}</td><td>&nbsp;</td>
<tr class="mod_temp_moving_row">
<td class="mod_line_desc">Tendenz (2 std.):</td><td class="mod_line_val">{content:fill:temp_changing}</td><td>&nbsp;</td>
</tr>
</table>
<h4>Extrema</h4>
<h4 class="mod_subhead">Extrema</h4>
<table>
<tr>
<td>Max:</td><td>{content:fill:temp_max_val}</td><td>{content:fill:temp_max_date}</td>
<tr class="mod_temp_max_row">
<td class="mod_line_desc">Max:</td><td class="mod_line_val">{content:fill:temp_max_val}&deg;C</td><td class="mod_line_date">{content:fill:temp_max_date}</td>
</tr>
<tr>
<td>Min:</td><td>{content:fill:temp_min_val}</td><td>{content:fill:temp_min_date}</td>
<tr class="mod_temp_min_row">
<td class="mod_line_desc">Min:</td><td class="mod_line_val">{content:fill:temp_min_val}&deg;C</td><td class="mod_line_date">{content:fill:temp_min_date}</td>
</tr>
</table>

View File

@ -0,0 +1,44 @@
<?
class Connection{
var $conn = NULL;
function Connection(){
$this->conn = NULL;
}
function _createConn(){
if($this->conn == NULL){
$this->conn = pg_connect("host=141.30.228.39 dbname=wetter user=losinshi")
or die('Verbindungsaufbau fehlgeschlagen: ' . pg_last_error());
}
}
function closeConn(){
if($this->conn != NULL){
pg_close($this->conn);
$this->conn = NULL;
}
}
function fetchQueryResultLine($query){
$this->_createConn();
$result = pg_query($this->conn, $query)
or die('Abfrage fehlgeschlagen: ' . pg_last_error());
$array = pg_fetch_assoc($result);
//print_r($array);
return $array;
}
function fetchQueryResultSet($query){
$returnArray = array();
$this->_createConn();
$result = pg_query($this->conn, $query)
or die('Abfrage fehlgeschlagen: ' . pg_last_error());
while($array = pg_fetch_assoc($result))
array_push($returnArray, $array);
return $returnArray;
}
}
?>

View File

@ -13,37 +13,40 @@ class Module{
var $tempInstance = NULL; /* Temp-Instanz */
function Module($modName, $sensId, $parser, $connection){
$this->$sensId = $sensId;
$this->$connection = $connection;
function Module($modName, $sensId, &$parser, &$connection){
$this->sensId = $sensId;
$this->connection = &$connection;
$this->parserInstance = &$parser;
$parser->parseContent($this->_getModuleFilename("frame"), $this, "top");
$parser->parseContent($this->_getModuleFilename($modName), $this, NULL);
$parser->parseContent($this->_getModuleFilename("frame"), $this, "bottom");
$parser->parseContent($this->_getModuleFilename("frame"), & $this, "top");
$parser->parseContent($this->_getModuleFilename($modName), & $this, NULL);
$parser->parseContent($this->_getModuleFilename("frame"), & $this, "bottom");
}
function _getModuleFilename($modName){
return "content/modules/mod_".$modName.".html";
}
function _get_sens(){
if($sensInstance == NULL)
$this->$sensInstance = new Sensor($this->$sensId, $this->$connection);
return $this->$sensInstance;
function &_get_sens(){
if($this->sensInstance == NULL)
$this->sensInstance = new Sensor($this->sensId, $this->connection);
return $this->sensInstance;
}
function _get_temp(){
if($tempInstance == NULL)
$this->$tempInstance = new Temp($this->$sensId, $this->$connection);
return $this->$tempInstance;
function &_get_temp(){
if($this->tempInstance == NULL)
$this->tempInstance = new Temp($this->sensId, $this->connection);
return $this->tempInstance;
}
function fill($contentId){
$content_split = explode("_", $contentId);
$callObject = call_user_method("_get_".$content_split[0], $this);
$callObject = & call_user_method("_get_".$content_split[0], $this);
$funcName = "get".substr($contentId, strlen($content_split[0]), strlen($contentId)-strlen($content_split[0]));
echo "\n\naufruf: ".$funcName."()\n\n";
return $callObject->$funcName($content_split[1]);
}

View File

@ -1,6 +1,7 @@
<?
include_once("php_inc/module.inc.php");
include_once("php_inc/parser.inc.php");
include_once("php_inc/connection.inc.php");
/* Klasse, die die ModuleSets Verwaltet */
@ -10,10 +11,9 @@ class ModuleSet{
/* Konstruktor */
function ModuleSet($setName){
$parser = $this->_getParserInstance(); /* Parserinstanz holen */
$parser->parseContent($this->_getSetFilename($setName), $this, NULL); /* Set Parsen */
$parser = & $this->_getParserInstance(); /* Parserinstanz holen */
$parser->parseContent($this->_getSetFilename($setName), &$this, NULL); /* Set Parsen */
echo "\n\n";
$parser->printContent();
}
@ -23,20 +23,22 @@ class ModuleSet{
}
/* Parser Instanzieren (wenn noch nicht ist) und zurückgeben */
function _getParserInstance(){
if($this->$parserInstance==NULL)
$this->$parserInstance = new Parser();
return $this->$parserInstance;
function &_getParserInstance(){
if($this->parserInstance==NULL)
$this->parserInstance = new Parser();
return $this->parserInstance;
}
function _getConnInstance(){
// TODO: Muss noch Implementiert werden!!
return $connInstance;
function &_getConnInstance(){
if($connInstance == NULL){
$this->connInstance = new Connection();
}
return $this->connInstance;
}
/* Ein Modul hinzufügen */
function addModule($modName){
$params = explode("_",$modName); /* Modulname und Sensorid trennen */
$params = explode("_",$modName); /* Modulname und Sensorid trennen */
new Module($params[0], $params[1], $this->_getParserInstance(), $this->_getConnInstance());
}
}

View File

@ -1,6 +1,7 @@
<?
class Parser{
var $contentArray;
var $ts = 0;
function Parser(){
$this->contentArray = array();
@ -14,9 +15,7 @@ class Parser{
function appendContent($newContent){
if(is_array($newContent)){
for($i = 0; $i < count($newContent); $i++){
echo "adding: ".$newContent[$i]."\n";
array_push($this->contentArray, $newContent[$i]);
echo "added: ".$this->contentArray[count($this->contentArray)-1]."\n";
}
} else {
array_push($this->contentArray, $newContent);
@ -25,28 +24,24 @@ class Parser{
/* Zeigt den Geparsten Inhalt an */
function printContent(){
echo "\n ---- Printing ----\n";
echo "";
$array = &$this->getContentArray();
$array = $this->getContentArray();
for ($i = 0; $i < count($array); $i++){
echo $array[$i];
}
}
function parseContent($fileName, $callingObject, $filePart=null){
echo "\n\nparse: ".$fileName."\n\n";
function parseContent($fileName, & $callingObject, $filePart=null){
$fileArray = file($fileName); /* File als Array einlesen */
if($filePart != null){
$fileArray = $this->_fetchFilePart(&$fileArray, $filePart); /* Wenn File aus mehreren Template-Teilen besteht, dann wird hir der relevante Zeil geholt */
}
for($i = 0; $i < count($fileArray); $i++){ /* Das Array durchlaufen ... */
echo "Zeile: ".$i." = ".$fileArray[$i]."\n";
if(0 != preg_match_all("/\{content:([a-z]+):([a-z0-9_]+)\}/i", $fileArray[$i], $results)){
//print_r($results);
for($j = 0; $j < count($results[1]); $j++){
$callingObject->$results[1][$j]($results[2][$j]);
//$fileArray[$i] = preg_replace("/\{content:fill:".$results[1][$j]."\}/i", $fileContents[$results[1][$j]], $fileArray[$i]);
$insert = $callingObject->$results[1][$j]($results[2][$j]);
$fileArray[$i] = preg_replace("/\{content:".$results[1][$j].":".$results[2][$j]."\}/i", $insert, $fileArray[$i]);
}
}
}