Compare commits

..

1 Commits

Author SHA1 Message Date
agp8x 15cc9ce813 added basic support for climaDiagrams 2014-02-07 16:47:08 +01:00
15 changed files with 112 additions and 359 deletions

8
.gitignore vendored
View File

@ -1,8 +0,0 @@
data/
*~
*.png
*.svg
charts/
config.php
newData

View File

@ -1 +0,0 @@
bb0bfa4

View File

@ -1,8 +1,3 @@
#WeatherstationServer #WeatherstationServer
##Overview ##Overview
PHP, CSS, psChart, pChart, DBLib PHP, CSS, psChart, pChart, DBLib
# TODO
* http://www.clemensklug.de/temp/new/?mode=month&year=2014&month=5
* wrong min_temp | 04.05.14

View File

@ -1,11 +0,0 @@
<?php
$database = array(
'host' => "localhost",
'user' => "temp",
'password' => "temppw",
'database' => "temp",
);
$start_year_of_recordings=2012;

View File

@ -1,7 +1,6 @@
get-modifiers:<br> get-modifiers:<br>
-force : redraw chart<br> -force : redraw chart<br>
-totalforce : rewrite database-entry +redraw chart<br> -totalforce : rewrite database-entry +redraw chart<br>
-lib (+force) : use custom svg-lib<br> -lib[=old] (+force) : use custom svg-lib<br>
-short : linked (png only)<br> -short : linked<br>
-abs : absolut values instead of rounded<br>
-mode=last + num=[x] : display last x hours -mode=last + num=[x] : display last x hours

View File

@ -11,13 +11,13 @@ function generateChart($today,$mode,$hours=0,$dateInput){
global $day; global $day;
global $month; global $month;
global $year; global $year;
global $db;
$diffuse=0; # 10min -+ start/end time $diffuse=0; # 10min -+ start/end time
$types=array('ambi1','ambi2','humi1','temp1','temp2','baro1'); $types=array('ambi1','ambi2','humi1','temp1','temp2','baro1');
$dummy=array(array(),array()); $dummy=array(array(),array());
$db=new DBLib('localhost','temp','temppw','temp');
$stats=""; $stats="";
$selectionStart=$selectionEnd=0; $selectionStart=$selectionEnd=0;
$chartname=""; $chartname="";
@ -44,7 +44,7 @@ function generateChart($today,$mode,$hours=0,$dateInput){
}elseif($mode==3){ }elseif($mode==3){
$selectionStart=mktime(0,0,0,$dateInput[1],1,$dateInput[0]); $selectionStart=mktime(0,0,0,$dateInput[1],1,$dateInput[0]);
$days=date("t",$selectionStart); $days=date("t",$selectionStart);
$selectionEnd=$selectionStart+(($days)*24*60*60); $selectionEnd=$selectionStart+($days*24*60*60);
$chartname="month_".$type."_".$month.".".$year; $chartname="month_".$type."_".$month.".".$year;
$chartdistance=60*24; $chartdistance=60*24;
}else{ }else{
@ -57,13 +57,15 @@ function generateChart($today,$mode,$hours=0,$dateInput){
$datas[]=$db->selectRange($type.$i,'*',$rangeSelector); $datas[]=$db->selectRange($type.$i,'*',$rangeSelector);
if($datas[$i-1]===false){ if($datas[$i-1]===false){
$html.='No values ('.$type.$i.')'; $html.='No values ('.$type.$i.')';
$datas[$i-1]=array(0,0); if($type!="ambi"){
return;
}
} }
} }
}else{ }else{
$where=array('year'=>$year,'month'=>$month); $where=array('year'=>$year,'month'=>$month);
//$db->toggleDevmode(); $db->toggleDevmode();
$summary=$db->select('summary','*',$where,"ORDER BY day"); $summary=$db->select('summary','*',$where);
if($summary===false){ if($summary===false){
$html.="No values (".$type.")"; $html.="No values (".$type.")";
return; return;
@ -84,9 +86,7 @@ function generateChart($today,$mode,$hours=0,$dateInput){
$data_tmp=array(); $data_tmp=array();
$data_tmp1=array(); $data_tmp1=array();
$data_tmp2=array(); $data_tmp2=array();
#var_dump(sizeof($summary));
foreach($summary as $daysum){ foreach($summary as $daysum){
#var_dump($daysum);
$mintmp= (str_replace($unit,'',$daysum[$name.'-min'])); $mintmp= (str_replace($unit,'',$daysum[$name.'-min']));
if($min[0]>$mintmp){ if($min[0]>$mintmp){
$min[0]=$mintmp; $min[0]=$mintmp;
@ -129,14 +129,7 @@ function generateChart($today,$mode,$hours=0,$dateInput){
$date_array=array('year'=>$year,'month'=>$month,'day'=>$day); $date_array=array('year'=>$year,'month'=>$month,'day'=>$day);
$summary=$db->select('summary','*',$date_array,'ORDER BY id DESC'); $summary=$db->select('summary','*',$date_array,'ORDER BY id DESC');
$recentSummary=true; if($summary===false ||isset($_GET['totalforce'])){
foreach($types as $tmp){
if($tmp==$types[1]){
continue;
}
$recentSummary=($summary[0][$tmp.'-min-time'] > 0) && $recentSummary;
}
if($summary===false ||isset($_GET['totalforce']) || ! $recentSummary){
//stats are not in db, generate new, also redraw graph //stats are not in db, generate new, also redraw graph
$forceRedraw=true; $forceRedraw=true;
$db->delete('summary',$date_array);//avoid multiple (outdated) entries $db->delete('summary',$date_array);//avoid multiple (outdated) entries
@ -219,14 +212,13 @@ function generateChart($today,$mode,$hours=0,$dateInput){
//only redraw, if new data was added, indicated by 'newData' token left by update.php //only redraw, if new data was added, indicated by 'newData' token left by update.php
$newData=false; $newData=false;
if(file_exists('newData')){ if(file_exists('newData')){
@unlink('newData'); unlink('newData');
$newData=true; $newData=true;
} }
$file_exists=false; $file_exists=false;
$svg=false; $svg=false;
if(isset($_GET['lib'])){ if(isset($_GET['lib'])){
$svg=true; $svg=true;
$clima = $_GET['lib'] === "clima";
if(file_exists("charts/".$chartname.".svg")){ if(file_exists("charts/".$chartname.".svg")){
$file_exists=true; $file_exists=true;
} }
@ -240,22 +232,30 @@ function generateChart($today,$mode,$hours=0,$dateInput){
#if(date("d.m.Y")==$date || !$file_exists || isset($_GET['force']) || $forceRedraw){ #if(date("d.m.Y")==$date || !$file_exists || isset($_GET['force']) || $forceRedraw){
#if((date("d.m.Y")==$date &&$force) || !file_exists($chartname) || $force){ #if((date("d.m.Y")==$date &&$force) || !file_exists($chartname) || $force){
#if(true){#always redraw #if(true){#always redraw
if(date("I",$selectionStart)==1 ){
//summertime
//if($mode!=3){
$selectionStart+=3600;
//}
}
if($svg){ if($svg){
if($clima && $mode == 1){ if ($_GET['lib']=="old") {
include('lib/climaDiagram.php');
$cd = new ClimaDiagram();
$cd->setLocation('Bischberg','Deutschland','50`, 50`', 'north');
$cd->setMode('day');
$values=prepareData($datas[1],$div,$selectionStart,$selectionEnd,$chartdistance);
foreach($values as $i=>$value){
if(!($i == 0 || $i == 1)){
$day_values[]=$value;
}
}
$cd->setTemperatureData($day_values);
file_put_contents("charts/".$chartname.".svg", $cd->getGraph());
}else{
include('ownlib.php'); include('ownlib.php');
} else {
include 'lib/climaDiagram.php';
$values=prepareData($datas[1],$div,$selectionStart,$selectionEnd,$chartdistance);
unset($values[0]);
// echo "<!--".sizeof($values);
// print_r($values);
// echo "-->";
$diagram=new ClimaDiagram();
$diagram->setLocation('Ort','Land','100','50`, 50`' ,'north');
// $temp=array(25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8);
// $rain=array(1,5,17,48,100,155,425,320,280,76,8,4);
$diagram->setMode('day');
$diagram->setRainData(array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
$diagram->setTemperatureData($values);
file_put_contents("charts/".$chartname.".svg", $diagram->getGraph());
} }
}else{ }else{
chdir('pchart'); chdir('pchart');
@ -264,24 +264,16 @@ function generateChart($today,$mode,$hours=0,$dateInput){
include("class/pImage.class.php"); include("class/pImage.class.php");
$myData=new pData(); $myData=new pData();
if(date("I",$selectionStart)==1 ){
//summertime
//if($mode!=3){
$selectionStart+=3600;
//}
}
$labels=getLabels($datas[0],$selectionStart,$selectionEnd,$chartdistance); $labels=getLabels($datas[0],$selectionStart,$selectionEnd,$chartdistance);
if($mode==3){ if($mode==3){
$selectionStart+=60*60*24; $selectionStart+=60*60*24;
$selectionEnd+=60*60*24; $div=1;
$div=0;
} }
foreach($datas as $key=>$dataset){ foreach($datas as $key=>$dataset){
#file_put_contents('data'.$type.($key+1),var_export($dataset,true));
$values=prepareData($dataset,$div,$selectionStart,$selectionEnd,$chartdistance); $values=prepareData($dataset,$div,$selectionStart,$selectionEnd,$chartdistance);
//TODO: replace $type.($key+1) with actual name //TODO: replace $type.($key+1) with actual name
$myData->addPoints($values,$type.($key+1)); $myData->addPoints($values,$type.($key+1));
#file_put_contents('val'.$type.($key+1),var_export($values,true)); #file_put_contents('val1',var_export($values,true));
} }
$myData->addPoints($labels,"Labels"); $myData->addPoints($labels,"Labels");

View File

@ -1,2 +0,0 @@
#pre-commit
git log -n 1 --format=format:"%h" HEAD > PREV_VERSION

View File

@ -54,10 +54,9 @@ function validFile($filename){
function logStats($datas,$type,$alt=false,$outlineAlt=0,$mode=1){ function logStats($datas,$type,$alt=false,$outlineAlt=0,$mode=1){
$output=""; $output="";
$left=10; $left=80;
$max=getMax($type); $max=getMax($type);
for($num=0;$num<=$max;$num++){ for($num=0;$num<=$max;$num++){
$printValues=true;
if($num>0){ if($num>0){
$left+=300; $left+=300;
} }
@ -70,23 +69,18 @@ function logStats($datas,$type,$alt=false,$outlineAlt=0,$mode=1){
}else{ }else{
$stat=$alt[$num]; $stat=$alt[$num];
$timePoints=$outlineAlt[$num]; $timePoints=$outlineAlt[$num];
$printValues = $stat['min'][1]!=0;
} }
$output.="<div style='position:absolute;left:".$left."px;'>\n"; $output.="<div style='position:absolute;left:".$left."px;'>\n";
$output.=$type.($num+1)."<br>\n"; $output.=$type.($num+1)."<br>\n";
if($printValues){ $output.="minimum: ".$stat['min'][0]." @ ".ttdls((int) $stat['min'][1],$mode)."<br>\n";
$output.="minimum: ".$stat['min'][0]." @ ".ttdls((int) $stat['min'][1],$mode)."<br>\n"; $output.="maximum: ".$stat['max'][0]." @ ".ttdls((int) $stat['max'][1],$mode)."<br>\n";
$output.="maximum: ".$stat['max'][0]." @ ".ttdls((int) $stat['max'][1],$mode)."<br>\n"; $output.="average: ".$stat['avg']." @ ".ttdls2($stat['min'][1],$mode)."<br>\n";
$output.="average: ".$stat['avg']." @ ".ttdls2($stat['min'][1],$mode)."<br>\n"; $output.="Logpoints: ".$stat['size']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".ttdls3((int) $stat['min'][1],$mode);
$output.="Logpoints: ".$stat['size']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".ttdls3((int) $stat['min'][1],$mode); $output.="<br><br><br>";
$output.="<br><br><br>"; if($mode==1){
if($mode==1){ foreach($timePoints as $point){
foreach($timePoints as $point){ $output.=date("H:i:s",(int) $point[1])." - ".$point[0]/$div.$unit."<br>\n";
$output.=date("H:i:s",(int) $point[1])." - ".$point[0]/$div.$unit."<br>\n";
}
} }
}else{
$output.="Keine Daten</div>";
} }
$output.="</div>\n"; $output.="</div>\n";
} }
@ -251,11 +245,7 @@ function prepareData($data,$div,$start=0,$end=0,$chartdistance=60){
$values=array(); $values=array();
$rawdata=outlinedLogPoints($data,$chartdistance,$start,$end); $rawdata=outlinedLogPoints($data,$chartdistance,$start,$end);
foreach($rawdata as $set){ foreach($rawdata as $set){
if($div==0){ $values[]=round($set[0]/$div,1);
$values[]=$set[0];
}else{
$values[]=round($set[0]/$div,1);
}
} }
return $values; return $values;
} }
@ -318,13 +308,9 @@ function drawChart($myData,$target,$date,$type){
$myPicture->Render($target); $myPicture->Render($target);
} }
function calendarDay($day,$year,$month,$selection, $future){ function calendarDay($day,$year,$month,$selection){
$baselink="&amp;year=".$year."&amp;month=".$month."&amp;day=".$day."'"; $baselink="&amp;year=".$year."&amp;month=".$month."&amp;day=".$day."'";
if($future){ return tempLink($baselink,$day,($selection=="temp")).humiLink($baselink,($selection=="humi")).ambiLink($baselink,($selection=="ambi")).baroLink($baselink,($selection=="baro"));
return $day." (H A B)";
}else{
return tempLink($baselink,$day,($selection=="temp")).humiLink($baselink,($selection=="humi")).ambiLink($baselink,($selection=="ambi")).baroLink($baselink,($selection=="baro"));
}
} }
function tempLink($baselink,$day,$selected=false){ function tempLink($baselink,$day,$selected=false){
$link="<a href='?type=temp".$baselink; $link="<a href='?type=temp".$baselink;
@ -355,8 +341,6 @@ function baroLink($baselink,$selected=false){
return $link." >B</a>)"; return $link." >B</a>)";
} }
function calendarNav($month,$year){ function calendarNav($month,$year){
global $start_year_of_recordings;
$prevMonth=$prevYear=$nextMonth=$nextYear=0; $prevMonth=$prevYear=$nextMonth=$nextYear=0;
if($month==12){ if($month==12){
$prevMonth=$month-1; $prevMonth=$month-1;
@ -374,27 +358,7 @@ function calendarNav($month,$year){
$nextMonth=$month+1; $nextMonth=$month+1;
$nextYear=$year; $nextYear=$year;
} }
$show['prev']=$prevYear >= $start_year_of_recordings; return "<div id='calendarNav'>\n\t<a href='?mode=month&amp;year=".$prevYear."&amp;month=".$prevMonth."'>&lt;&lt;</a>&nbsp; <a href='?mode=month&amp;year=".$year."&amp;month=".$month."'>".$month."</a> &nbsp; <a href='?mode=month&amp;year=".$nextYear."&amp;month=".$nextMonth."'>&gt;&gt;</a>\n</div>\n";
$show['next']=! isFuture(array(date("j"),date("n"),date("Y")), 0, $nextMonth, $nextYear);
$links="<div id='calendarNav'>\n\t";
if ($show['prev']){
$links.="<a href='?mode=month&amp;year=".$prevYear."&amp;month=".$prevMonth."'>&lt;&lt; (".monthToName($prevMonth).")</a>";
}else{
$links.=monthToName($prevMonth);
}
$links.="&nbsp; <a href='?mode=month&amp;year=".$year."&amp;month=".$month."'>".monthToName($month)."</a> &nbsp; ";
if ($show['next']){
$links.="<a href='?mode=month&amp;year=".$nextYear."&amp;month=".$nextMonth."'>&gt;&gt; (".monthToName($nextMonth).")</a>";
}else{
$links.=monthToName($nextMonth);
}
$links.="\n</div>\n";
return $links;
}
function monthToName($month){
$dateObj = DateTime::createFromFormat('!m', $month);
$monthName = $dateObj->format('F');
return $monthName;
} }
function prependZero($number){ function prependZero($number){
return ($number<10)? "0".$number : $number; return ($number<10)? "0".$number : $number;
@ -423,8 +387,7 @@ function drawCalendar($date,$type){
}else{ }else{
$calendar.="\t\t<td>"; $calendar.="\t\t<td>";
} }
$future=isFuture($today, $day, $month, $year); $calendar.=calendarDay($day,$year,$month,($day==$selectedDay)? $type : false);
$calendar.=calendarDay($day,$year,$month,($day==$selectedDay)? $type : false, $future);
$day++; $day++;
}else{ }else{
$calendar.="\t\t<td> &nbsp;"; $calendar.="\t\t<td> &nbsp;";
@ -437,34 +400,6 @@ function drawCalendar($date,$type){
Letzte: <a href='?mode=last&amp;num=24&amp;type=temp'>24h</a> <a href='?mode=last&amp;num=48&amp;type=temp'>48h</a> <a href='?mode=last&amp;num=96&amp;type=temp'>96h</a> &nbsp;&nbsp;&nbsp;<a href='?'>Temperatur Heute</a></div>"; Letzte: <a href='?mode=last&amp;num=24&amp;type=temp'>24h</a> <a href='?mode=last&amp;num=48&amp;type=temp'>48h</a> <a href='?mode=last&amp;num=96&amp;type=temp'>96h</a> &nbsp;&nbsp;&nbsp;<a href='?'>Temperatur Heute</a></div>";
return $calendar; return $calendar;
} }
function isFuture($today, $day, $month, $year){
$dateObj = DateTime::createFromFormat('!m', $month-1);
$numDays = $dateObj->format("t");
# check year
if ($today[2] < $year){
return true;
}
if ($today[2] == $year){
# check month
if ($today[1] < $month){
# last day of month => enable next month
if($today[0] == $numDays){
return $day != 0 && $day != 1;
}
return true;
}
if($today[1] == $month){
# enable next day anyways
if($today[0]+1 == $day){
return false;
}
# check day
return $today[0] < $day;
}
}
# base case
return false;
}
function typeToSensorCount($type){ function typeToSensorCount($type){
switch($type){ switch($type){
@ -482,3 +417,4 @@ function fileToLastSet($file){
$temp=explode(";",$last); $temp=explode(";",$last);
return $temp[0]; return $temp[0];
} }

View File

@ -3,7 +3,6 @@
header("Cache-Control: no-cache, must-revalidate"); header("Cache-Control: no-cache, must-revalidate");
$start=microtime(true); $start=microtime(true);
date_default_timezone_set("Europe/Berlin"); date_default_timezone_set("Europe/Berlin");
include('config.php');
include('lib/DBLib.php'); include('lib/DBLib.php');
include('draw.php'); include('draw.php');
include('function.php'); include('function.php');
@ -51,10 +50,8 @@ if(isset($_GET['mode']) && $_GET['mode']=='last'){
}else if($type!='none' && ($type=="temp" || $type=="ambi" || $type=="humi" || $type=="baro")){ }else if($type!='none' && ($type=="temp" || $type=="ambi" || $type=="humi" || $type=="baro")){
//mode: day //mode: day
$mode=1; $mode=1;
}else if (isset($_GET['mode']) && $_GET['mode']=='predict'){
$mode=4;
}else{ }else{
$html.="Keine weiteren Angaben: Heutige Temperatur wird angezeigt"; $html.="No/invalid type, default to temperature/today";
$mode=1; $mode=1;
$type="temp"; $type="temp";
} }
@ -65,21 +62,8 @@ if($mode==1){
$date=array($_GET['year'],$_GET['month'],1); $date=array($_GET['year'],$_GET['month'],1);
}else{ }else{
$date=array($_GET['year'],$_GET['month'],$_GET['day']); $date=array($_GET['year'],$_GET['month'],$_GET['day']);
$future=false; if(($_GET['day']>$today[0])&&($_GET['month']>=$today[1])&&($_GET['year']>=$today[2])){
#TODO: replace logic? $error="future";
if($_GET['year']>$today[2]){
$future=true;
}else{
if($_GET['month']>$today[1] && $_GET['year']==$today[2]){
$future=true;
}else{
if($_GET['day']>$today[0] && $_GET['month']==$today[1]){
$future=true;
}
}
}
if($future){
$error="Gewähltes Datum liegt in der Zukunft.";
$mode=0; $mode=0;
} }
} }
@ -87,15 +71,14 @@ if($mode==1){
$date=array(date("Y"),date("n"),date("j")); $date=array(date("Y"),date("n"),date("j"));
} }
} }
$db=new DBLib($database['host'],$database['user'],$database['password'],$database['database']);
if(!$error===false){ if(!$error===false){
$html.=$error; $html.=$error;
}else if($mode != 4){
$html.=generateChart($today,$mode,$num,$date);
}else{ }else{
include('predict.php'); $html.=generateChart($today,$mode,$num,$date);
} }
$runtime=microtime(true)-$start; $runtime=microtime(true)-$start;
$html.="<div style='position:fixed;bottom:20px;right:50px;' >Runtime: ".$runtime." s</div>"; $html.="<div style='position:fixed;bottom:20px;right:50px;' >Runtime: ".$runtime." s</div>";
$html.=$calendar."</body>"; $html.=$calendar."</body>";
echo $html; echo $html;

View File

@ -11,7 +11,6 @@
#08.08.12 OOP, proper Link handling #v4 #08.08.12 OOP, proper Link handling #v4
#25.08.12 construct;toString;set/getPrefix;noExecute added, LinkHandling fixed #v5 #25.08.12 construct;toString;set/getPrefix;noExecute added, LinkHandling fixed #v5
#04.09.12 various improvments #v5.2 #04.09.12 various improvments #v5.2
#04.02.14 port to mysqli #v6.1
class DBLib{ class DBLib{
@ -19,20 +18,15 @@ class DBLib{
private $devmode=false; private $devmode=false;
private $dbprefix=""; private $dbprefix="";
private $connected=false; private $connected=false;
const version=6.1; const version=5.2;
private $dbinfo=null; private $dbinfo=null;
private $execute=true; private $execute=true;
public function __construct($host="",$user="",$pass="",$database=""){ public function __construct($host="",$user="",$pass="",$database=""){
if(($host!="" || $user!="" || $pass!="" || $database!="")){ if(($host!="" || $user!="" || $pass!="" || $database!="")){
$this->connect($host,$user,$pass,$database); $this->connect($host,$user,$pass,$database);
}else{
$this->dbLink=new mysqli();
} }
} }
public function __destruct(){
$this->close();
}
public function connect($host,$user,$pass,$database){ public function connect($host,$user,$pass,$database){
if(!$this->checkExecute('connect')){ if(!$this->checkExecute('connect')){
@ -40,8 +34,8 @@ class DBLib{
$this->dbinfo=array('user'=>'noExecute','host'=>'noExecute','dbbase'=>'noExecute'); $this->dbinfo=array('user'=>'noExecute','host'=>'noExecute','dbbase'=>'noExecute');
return true; return true;
} }
$this->dbLink=new mysqli($host, $user, $pass, $database); $this->dbLink=@mysql_connect($host, $user, $pass);
if ($this->dbLink->connect_errno != 0) { if ($this->dbLink===false || !@mysql_select_db($database)) {
$this->echoDev('Connection failed!'); $this->echoDev('Connection failed!');
$this->connected=false; $this->connected=false;
}else{ }else{
@ -52,13 +46,11 @@ class DBLib{
} }
public function close(){ public function close(){
if ($this->dbLink instanceof mysqli) { $this->connected=false;
$this->connected=$this->dbLink->close();
$this->dbLink=null;
}
if(!$this->checkExecute('close')){ if(!$this->checkExecute('close')){
return false; return false;
} }
mysql_close($this->dbLink);
} }
public function update($table, $values, $identifier=array(), $increment=false,$escapeIdentifier=true) { public function update($table, $values, $identifier=array(), $increment=false,$escapeIdentifier=true) {
@ -83,7 +75,12 @@ class DBLib{
if(!$this->checkExecute($sql)){ if(!$this->checkExecute($sql)){
return false; return false;
} }
return $this->executeSQL($sql); $result=mysql_query($sql,$this->dbLink);
if(mysql_errno()){
return false;
}else{
return true;
}
} }
public function insert($table, $values) { public function insert($table, $values) {
@ -104,7 +101,12 @@ class DBLib{
if(!$this->checkExecute($sql)){ if(!$this->checkExecute($sql)){
return false; return false;
} }
return $this->executeSQL($sql); $result = mysql_query($sql,$this->dbLink);
if (mysql_errno()) {
return false;
} else {
return true;
}
} }
public function delete($table,$identifier,$extra="",$escapeIdentifier=true){ public function delete($table,$identifier,$extra="",$escapeIdentifier=true){
if(empty($table) || !$this->connected){ if(empty($table) || !$this->connected){
@ -117,7 +119,12 @@ class DBLib{
if(!$this->checkExecute($sql)){ if(!$this->checkExecute($sql)){
return false; return false;
} }
return $this->executeSQL($sql); $result=mysql_query($sql,$this->dbLink);
if(mysql_errno()){
return false;
}else{
return true;
}
} }
public function select($table, $values, $identifier=array(), $extra="",$escapeIdentifier=true) { public function select($table, $values, $identifier=array(), $extra="",$escapeIdentifier=true) {
@ -135,9 +142,9 @@ class DBLib{
if(!$this->checkExecute($sql)){ if(!$this->checkExecute($sql)){
return false; return false;
} }
$result = $this->dbLink->query($sql); $result = mysql_query($sql,$this->dbLink);
if ($this->dbLink->errno == 0) { if (!mysql_errno()) {
while($out=$result->fetch_assoc()){ while($out=mysql_fetch_assoc($result)){
$output[]=$out; $output[]=$out;
} }
if(sizeof($output)==0){ if(sizeof($output)==0){
@ -145,16 +152,6 @@ class DBLib{
} }
return($output); return($output);
} else { } else {
$this->echoDev("query failed: ".$this->dbLink->error);
return false;
}
}
private function executeSQL($sql){
$this->dbLink->query($sql);
if ($this->dbLink->errno == 0) {
return true;
}else{
return false; return false;
} }
} }
@ -169,7 +166,7 @@ class DBLib{
public function dbEscape($string) { public function dbEscape($string) {
if($this->connected && $this->execute){ if($this->connected && $this->execute){
return($this->dbLink->escape_string($string)); return(mysql_real_escape_string($string,$this->dbLink));
}else{ }else{
return $string; return $string;
} }

View File

@ -1,71 +0,0 @@
<?php
class Grouplens{
public function r($p,$i,$data){
return $this->average($p,$p) + $this->c($p,$i,$data);
}
public function wrapR($subject, $item, $data){
return $this->r($data[$subject], $item, $data);
}
private function sim($a, $b){
$averageA=$this->average($a,$b);
$averageB=$this->average($b,$a);
$div=0.0;
$sumA=0;
$sumB=0;
foreach($a as $i=>$value){
if(!empty($value) && !empty($b[$i])){
$div+=($value - $averageA)*($b[$i] - $averageB);
$sumA+=pow(($value-$averageA), 2);
$sumB+=pow(($b[$i]-$averageB), 2);
}
}
return ($div / (sqrt($sumA) * sqrt($sumB)));
}
private function c($p,$i,$data){
$divident=$divisor=0.0;
foreach($data as $q){
if (empty($q[$i]) || $p===$q){
continue;
}
$simPQ=$this->sim($p,$q);
$averageQ=$this->average($q,$p);
$divisor+=abs($simPQ);
$divident+=(($q[$i]-$averageQ)*$simPQ);
}
return ($divident / $divisor);
}
private function average($set, $controlSet){
$average=0.0;
$count=0;
foreach($set as $i=>$value){
if (!empty($value) && !empty($controlSet[$i])){
$average+=$value;
$count+=1;
}
}
return ($average / $count);
}
}
#$ratings=array(
# "alice"=>array(5, 1, 0, 3, 2),
# "bob"=>array(3, 1, 5, 4, 2),
# "carol"=>array(4, 0, 5, 0, 3),
# "chuck"=>array(1, 4, 0, 0, 2),
# "dave"=>array(0, 4, 3, 0, 1),
# "eve"=>array(5, 4, 5, 4, 3),
# "fran"=>array(4, 0, 0, 0,2),
# "gordon"=>array(3, 4, 0, 5, 1),
# "isaac"=>array(5, 0, 4, 3, 0),
# "ivan"=>array(3, 1, 1, 0, 1)
#);
#echo sim($ratings['alice'],$ratings['ivan']);
#echo "<br>";
#echo "<br>";
#echo wrapR('alice', 2, $ratings);
#

View File

@ -11,14 +11,14 @@ class ClimaDiagram{
private $languages=array('de'); private $languages=array('de');
private $language='de'; private $language='de';
private $temperatureData=array(); private $temperatureData;
private $rainData=array(); private $rainData;
private $locationName=""; private $locationName;
private $locationCountry=""; private $locationCountry;
private $locationHeight=""; private $locationHeight;
private $locationCoordinates=""; private $locationCoordinates;
private $hemisphere='north'; private $hemisphere='north';
private $result=""; private $result;
private function drawBase(){ private function drawBase(){
foreach ($this->modes as $mode => $prop) { foreach ($this->modes as $mode => $prop) {
@ -240,15 +240,15 @@ class ClimaDiagram{
## TESTING ## ## TESTING ##
################ ################
#$test=new ClimaDiagram(); // $test=new ClimaDiagram();
#$test->setLocation('Ort','Land','100','50`, 50`' ,'north'); // $test->setLocation('Ort','Land','100','50`, 50`' ,'north');
#// $temp=array(25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8); // // $temp=array(25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8);
#// $rain=array(1,5,17,48,100,155,425,320,280,76,8,4); // // $rain=array(1,5,17,48,100,155,425,320,280,76,8,4);
#$temp=array(25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8,25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8); // $temp=array(25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8,25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8);
#$rain=array(1,5,17,48,100,155,425,320,280,76,8,4,1,5,17,48,100,155,425,320,280,76,8,4); // $rain=array(1,5,17,48,100,155,425,320,280,76,8,4,1,5,17,48,100,155,425,320,280,76,8,4);
#$test->setMode('day'); // $test->setMode('day');
#// $test->setMode('month'); // // $test->setMode('month');
#$test->setRainData($rain); // $test->setRainData($rain);
#$test->setTemperatureData($temp); // $test->setTemperatureData($temp);
#echo $test->getGraph(); // echo $test->getGraph();
?> ?>

View File

@ -1,54 +0,0 @@
<?php
include('lib/Grouplens.php');
$start=microtime(true);
echo "<title>[BETA] prediction</title>";
$date=array(date("Y"),date("n"),date("j"));
$diffuse=0;
$selectionStart=mktime(0,0,0,$date[1],$date[2],$date[0]);
$selectionEnd=$selectionStart+(60*60*(24+date("I",$selectionStart)));
$rangeSelector=array('time',$selectionStart-$diffuse,$selectionEnd+$diffuse);
$data= $db->selectRange('temp2','*',$rangeSelector);
foreach($data as $record){
$tupel=$record;
}
$data=null;
$month=date('n', $tupel['time']);
$year=date('Y', $tupel['time']);
$day=date('j', $tupel['time']);
#$div=getdiv('temp');
$div=1;
for($i=1; $i<=$day;$i++){
$selectionStart=mktime(0,0,0,$month,$i,$year);
$selectionEnd=$selectionStart+(60*60*(24+date("I",$selectionStart)));
$rangeSelector=array('time',$selectionStart-$diffuse,$selectionEnd+$diffuse);
$data= $db->selectRange('temp2','*',$rangeSelector);
$sumary[]=prepareData($data,$div,$selectionStart,$selectionEnd);
}
$gl=new Grouplens();
$div=getdiv('temp');
echo "prediction for ".date("d.m.Y");
echo "<table border='border-collapse'>\n";
echo "<tr><th>hour</th> <th>prediction</th> <th>difference</th><th>actual measurement</th></tr>\n";
for ($i=0;$i<25;$i++){
$r=$gl->wrapR($day-1,$i,$sumary);
$r=$r/$div;
$r=round($r,2);
$a=$sumary[$day-1][$i+1]/$div;
$a=round($a,2);
echo "<tr><td>".$i."</td><td>".$r."</td><td>".round($r-$a,2)."</td><td>".$a."</td></tr>\n";
}
echo "</table>\n";
$runtime=microtime(true)-$start;
echo "<div style='position:fixed;bottom:20px;right:50px;' >Runtime: ".$runtime." s</div>";
$db->close();
die();

1
recent
View File

@ -1 +0,0 @@
Temperatur: 22.81 C<br>Luftfeuchtigkeit: 0 %<br>Helligkeit: 0.01 Lux<br>Luftdruck: 0mbar

View File

@ -1,18 +1,17 @@
<?php <?php
#v1.3 #v1.3
include('config.php');
include('lib/DBLib.php'); include('lib/DBLib.php');
include('function.php'); include('function.php');
$db=new DBLib(); $db=new DBLib();
$db=new DBLib($database['host'],$database['user'],$database['password'],$database['database']); $db->connect('localhost','temp','temppw','temp');#lokal
$dir=scandir('data'); $dir=scandir('data');
$temp=$humi=$ambi=$baro=0; $temp=$humi=$ambi=$baro=0;
foreach($dir as $file){ foreach($dir as $file){
if(validFile($file)){ if(validFile($file)){
file_put_contents('newData',""); file_put_contents('newData',"");
echo "parsing file: ".$file."\n"; #echo "parsing file: ".$file."\n";
importLogfiletoDatabase('data/'.$file); importLogfiletoDatabase('data/'.$file);
//recent records on frontpage: //recent records on frontpage:
if($file[0].$file[1].$file[2].$file[3].$file[4] == "temp2"){ if($file[0].$file[1].$file[2].$file[3].$file[4] == "temp2"){
@ -27,7 +26,7 @@ foreach($dir as $file){
/// ///
unlink('data/'.$file); unlink('data/'.$file);
}else{ }else{
echo "invalidFile: ".$file." \n"; #echo "invalidFile: ".$file." \n";
} }
} }
$db->close(); $db->close();