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
##Overview
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>
-force : redraw chart<br>
-totalforce : rewrite database-entry +redraw chart<br>
-lib (+force) : use custom svg-lib<br>
-short : linked (png only)<br>
-abs : absolut values instead of rounded<br>
-lib[=old] (+force) : use custom svg-lib<br>
-short : linked<br>
-mode=last + num=[x] : display last x hours

View File

@ -11,13 +11,13 @@ function generateChart($today,$mode,$hours=0,$dateInput){
global $day;
global $month;
global $year;
global $db;
$diffuse=0; # 10min -+ start/end time
$types=array('ambi1','ambi2','humi1','temp1','temp2','baro1');
$dummy=array(array(),array());
$db=new DBLib('localhost','temp','temppw','temp');
$stats="";
$selectionStart=$selectionEnd=0;
$chartname="";
@ -44,7 +44,7 @@ function generateChart($today,$mode,$hours=0,$dateInput){
}elseif($mode==3){
$selectionStart=mktime(0,0,0,$dateInput[1],1,$dateInput[0]);
$days=date("t",$selectionStart);
$selectionEnd=$selectionStart+(($days)*24*60*60);
$selectionEnd=$selectionStart+($days*24*60*60);
$chartname="month_".$type."_".$month.".".$year;
$chartdistance=60*24;
}else{
@ -57,13 +57,15 @@ function generateChart($today,$mode,$hours=0,$dateInput){
$datas[]=$db->selectRange($type.$i,'*',$rangeSelector);
if($datas[$i-1]===false){
$html.='No values ('.$type.$i.')';
$datas[$i-1]=array(0,0);
if($type!="ambi"){
return;
}
}
}
}else{
$where=array('year'=>$year,'month'=>$month);
//$db->toggleDevmode();
$summary=$db->select('summary','*',$where,"ORDER BY day");
$db->toggleDevmode();
$summary=$db->select('summary','*',$where);
if($summary===false){
$html.="No values (".$type.")";
return;
@ -84,9 +86,7 @@ function generateChart($today,$mode,$hours=0,$dateInput){
$data_tmp=array();
$data_tmp1=array();
$data_tmp2=array();
#var_dump(sizeof($summary));
foreach($summary as $daysum){
#var_dump($daysum);
$mintmp= (str_replace($unit,'',$daysum[$name.'-min']));
if($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);
$summary=$db->select('summary','*',$date_array,'ORDER BY id DESC');
$recentSummary=true;
foreach($types as $tmp){
if($tmp==$types[1]){
continue;
}
$recentSummary=($summary[0][$tmp.'-min-time'] > 0) && $recentSummary;
}
if($summary===false ||isset($_GET['totalforce']) || ! $recentSummary){
if($summary===false ||isset($_GET['totalforce'])){
//stats are not in db, generate new, also redraw graph
$forceRedraw=true;
$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
$newData=false;
if(file_exists('newData')){
@unlink('newData');
unlink('newData');
$newData=true;
}
$file_exists=false;
$svg=false;
if(isset($_GET['lib'])){
$svg=true;
$clima = $_GET['lib'] === "clima";
if(file_exists("charts/".$chartname.".svg")){
$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 &&$force) || !file_exists($chartname) || $force){
#if(true){#always redraw
if(date("I",$selectionStart)==1 ){
//summertime
//if($mode!=3){
$selectionStart+=3600;
//}
}
if($svg){
if($clima && $mode == 1){
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{
if ($_GET['lib']=="old") {
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{
chdir('pchart');
@ -264,24 +264,16 @@ function generateChart($today,$mode,$hours=0,$dateInput){
include("class/pImage.class.php");
$myData=new pData();
if(date("I",$selectionStart)==1 ){
//summertime
//if($mode!=3){
$selectionStart+=3600;
//}
}
$labels=getLabels($datas[0],$selectionStart,$selectionEnd,$chartdistance);
if($mode==3){
$selectionStart+=60*60*24;
$selectionEnd+=60*60*24;
$div=0;
$div=1;
}
foreach($datas as $key=>$dataset){
#file_put_contents('data'.$type.($key+1),var_export($dataset,true));
$values=prepareData($dataset,$div,$selectionStart,$selectionEnd,$chartdistance);
//TODO: replace $type.($key+1) with actual name
$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");

View File

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

View File

@ -30,7 +30,7 @@ function importLogfileToDatabase($fileImport){
foreach($file as $line){
$line=explode(";",$line);
if($emptyDB){
$db->insert($logtype[0],array('time'=>$line[1],'value'=>$line[0]));
}else{
@ -39,7 +39,7 @@ function importLogfileToDatabase($fileImport){
}
}
}
}
function validFile($filename){
$humi=(strpos($filename,'humi')===false);
@ -54,10 +54,9 @@ function validFile($filename){
function logStats($datas,$type,$alt=false,$outlineAlt=0,$mode=1){
$output="";
$left=10;
$left=80;
$max=getMax($type);
for($num=0;$num<=$max;$num++){
$printValues=true;
if($num>0){
$left+=300;
}
@ -70,23 +69,18 @@ function logStats($datas,$type,$alt=false,$outlineAlt=0,$mode=1){
}else{
$stat=$alt[$num];
$timePoints=$outlineAlt[$num];
$printValues = $stat['min'][1]!=0;
}
$output.="<div style='position:absolute;left:".$left."px;'>\n";
$output.=$type.($num+1)."<br>\n";
if($printValues){
$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.="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.="<br><br><br>";
if($mode==1){
foreach($timePoints as $point){
$output.=date("H:i:s",(int) $point[1])." - ".$point[0]/$div.$unit."<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.="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.="<br><br><br>";
if($mode==1){
foreach($timePoints as $point){
$output.=date("H:i:s",(int) $point[1])." - ".$point[0]/$div.$unit."<br>\n";
}
}else{
$output.="Keine Daten</div>";
}
$output.="</div>\n";
}
@ -214,7 +208,7 @@ function getDay(){
global $year;
return array($month,$day,$year);
}
function getNearest($data,$time,$last=-1){
function getNearest($data,$time,$last=-1){
if(!is_array($data)){
return array(0,$time);
}
@ -251,11 +245,7 @@ function prepareData($data,$div,$start=0,$end=0,$chartdistance=60){
$values=array();
$rawdata=outlinedLogPoints($data,$chartdistance,$start,$end);
foreach($rawdata as $set){
if($div==0){
$values[]=$set[0];
}else{
$values[]=round($set[0]/$div,1);
}
$values[]=round($set[0]/$div,1);
}
return $values;
}
@ -289,9 +279,9 @@ function drawChart($myData,$target,$date,$type){
$width=1200;
$height=600;
$fontsize=12;
$myData->setSerieDescription("Labels","Stunde");
$myData->setAbscissa("Labels");
$myData->setAbscissa("Labels");
$myPicture = new pImage($width,$height,$myData);
#$myPicture->Antialias = FALSE;#antialiasing off
$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
@ -301,7 +291,7 @@ function drawChart($myData,$target,$date,$type){
$myPicture->drawGradientArea(0,0,$width,$height,DIRECTION_VERTICAL,$Settings);
$myPicture->drawGradientArea(0,0,$width,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));
$myPicture->drawRectangle(0,0,$width-1,$height-1,array("R"=>0,"G"=>0,"B"=>0));#border
/* Write the chart title */
/* Write the chart title */
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>$fontsize,"R"=>255,"G"=>255,"B"=>255));
$myPicture->drawText(10,16,"Durchschnittliche ".typeToFullName($type)." @ ".$date,array("FontSize"=>11,"Align"=>TEXT_ALIGN_BOTTOMLEFT));
$myPicture->drawText($width-200,16,"erzeugt @ ".date("H:i:s d.m.Y"),array("FontSize"=>11,"Align"=>TEXT_ALIGN_BOTTOMLEFT));
@ -318,13 +308,9 @@ function drawChart($myData,$target,$date,$type){
$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."'";
if($future){
return $day." (H A B)";
}else{
return tempLink($baselink,$day,($selection=="temp")).humiLink($baselink,($selection=="humi")).ambiLink($baselink,($selection=="ambi")).baroLink($baselink,($selection=="baro"));
}
return tempLink($baselink,$day,($selection=="temp")).humiLink($baselink,($selection=="humi")).ambiLink($baselink,($selection=="ambi")).baroLink($baselink,($selection=="baro"));
}
function tempLink($baselink,$day,$selected=false){
$link="<a href='?type=temp".$baselink;
@ -355,8 +341,6 @@ function baroLink($baselink,$selected=false){
return $link." >B</a>)";
}
function calendarNav($month,$year){
global $start_year_of_recordings;
$prevMonth=$prevYear=$nextMonth=$nextYear=0;
if($month==12){
$prevMonth=$month-1;
@ -374,27 +358,7 @@ function calendarNav($month,$year){
$nextMonth=$month+1;
$nextYear=$year;
}
$show['prev']=$prevYear >= $start_year_of_recordings;
$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;
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";
}
function prependZero($number){
return ($number<10)? "0".$number : $number;
@ -408,7 +372,7 @@ function drawCalendar($date,$type){
$today=array('match'=>($month==date("n") && $year==date("Y")),date("j"),date("n"),date("Y"));
$first=mktime(0,0,0,$month,1,$year);
$firstDay=date("w",$first);
$calendar="<div id='calendar'><br/>\n".calendarNav($month,$year);
$day=1;
#$day=0;
@ -423,8 +387,7 @@ function drawCalendar($date,$type){
}else{
$calendar.="\t\t<td>";
}
$future=isFuture($today, $day, $month, $year);
$calendar.=calendarDay($day,$year,$month,($day==$selectedDay)? $type : false, $future);
$calendar.=calendarDay($day,$year,$month,($day==$selectedDay)? $type : false);
$day++;
}else{
$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>";
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){
switch($type){
@ -482,3 +417,4 @@ function fileToLastSet($file){
$temp=explode(";",$last);
return $temp[0];
}

View File

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

View File

@ -11,7 +11,6 @@
#08.08.12 OOP, proper Link handling #v4
#25.08.12 construct;toString;set/getPrefix;noExecute added, LinkHandling fixed #v5
#04.09.12 various improvments #v5.2
#04.02.14 port to mysqli #v6.1
class DBLib{
@ -19,20 +18,15 @@ class DBLib{
private $devmode=false;
private $dbprefix="";
private $connected=false;
const version=6.1;
const version=5.2;
private $dbinfo=null;
private $execute=true;
public function __construct($host="",$user="",$pass="",$database=""){
if(($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){
if(!$this->checkExecute('connect')){
@ -40,8 +34,8 @@ class DBLib{
$this->dbinfo=array('user'=>'noExecute','host'=>'noExecute','dbbase'=>'noExecute');
return true;
}
$this->dbLink=new mysqli($host, $user, $pass, $database);
if ($this->dbLink->connect_errno != 0) {
$this->dbLink=@mysql_connect($host, $user, $pass);
if ($this->dbLink===false || !@mysql_select_db($database)) {
$this->echoDev('Connection failed!');
$this->connected=false;
}else{
@ -52,13 +46,11 @@ class DBLib{
}
public function close(){
if ($this->dbLink instanceof mysqli) {
$this->connected=$this->dbLink->close();
$this->dbLink=null;
}
$this->connected=false;
if(!$this->checkExecute('close')){
return false;
}
mysql_close($this->dbLink);
}
public function update($table, $values, $identifier=array(), $increment=false,$escapeIdentifier=true) {
@ -83,7 +75,12 @@ class DBLib{
if(!$this->checkExecute($sql)){
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) {
@ -104,7 +101,12 @@ class DBLib{
if(!$this->checkExecute($sql)){
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){
if(empty($table) || !$this->connected){
@ -117,7 +119,12 @@ class DBLib{
if(!$this->checkExecute($sql)){
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) {
@ -135,9 +142,9 @@ class DBLib{
if(!$this->checkExecute($sql)){
return false;
}
$result = $this->dbLink->query($sql);
if ($this->dbLink->errno == 0) {
while($out=$result->fetch_assoc()){
$result = mysql_query($sql,$this->dbLink);
if (!mysql_errno()) {
while($out=mysql_fetch_assoc($result)){
$output[]=$out;
}
if(sizeof($output)==0){
@ -145,16 +152,6 @@ class DBLib{
}
return($output);
} 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;
}
}
@ -169,7 +166,7 @@ class DBLib{
public function dbEscape($string) {
if($this->connected && $this->execute){
return($this->dbLink->escape_string($string));
return(mysql_real_escape_string($string,$this->dbLink));
}else{
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 $language='de';
private $temperatureData=array();
private $rainData=array();
private $locationName="";
private $locationCountry="";
private $locationHeight="";
private $locationCoordinates="";
private $temperatureData;
private $rainData;
private $locationName;
private $locationCountry;
private $locationHeight;
private $locationCoordinates;
private $hemisphere='north';
private $result="";
private $result;
private function drawBase(){
foreach ($this->modes as $mode => $prop) {
@ -240,15 +240,15 @@ class ClimaDiagram{
## TESTING ##
################
#$test=new ClimaDiagram();
#$test->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);
#$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);
#$test->setMode('day');
#// $test->setMode('month');
#$test->setRainData($rain);
#$test->setTemperatureData($temp);
#echo $test->getGraph();
?>
// $test=new ClimaDiagram();
// $test->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);
// $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);
// $test->setMode('day');
// // $test->setMode('month');
// $test->setRainData($rain);
// $test->setTemperatureData($temp);
// 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
#v1.3
include('config.php');
include('lib/DBLib.php');
include('function.php');
$db=new DBLib();
$db=new DBLib($database['host'],$database['user'],$database['password'],$database['database']);
$db->connect('localhost','temp','temppw','temp');#lokal
$dir=scandir('data');
$temp=$humi=$ambi=$baro=0;
foreach($dir as $file){
if(validFile($file)){
file_put_contents('newData',"");
echo "parsing file: ".$file."\n";
#echo "parsing file: ".$file."\n";
importLogfiletoDatabase('data/'.$file);
//recent records on frontpage:
if($file[0].$file[1].$file[2].$file[3].$file[4] == "temp2"){
@ -27,7 +26,7 @@ foreach($dir as $file){
///
unlink('data/'.$file);
}else{
echo "invalidFile: ".$file." \n";
#echo "invalidFile: ".$file." \n";
}
}
$db->close();