First Commit
This commit is contained in:
207
html/sternwarte/HWeather/HWett.php
Executable file
207
html/sternwarte/HWeather/HWett.php
Executable file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
define ('DBASE',"wview_dbase");
|
||||
|
||||
date_default_timezone_set("Europe/Berlin");
|
||||
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
|
||||
|
||||
$dbh = new PDO('sqlite:'.DBASE);
|
||||
$dbh->exec("set names 'utf8'");
|
||||
|
||||
function holWert($t,$wert,$minmax)
|
||||
{
|
||||
global $dbh;
|
||||
|
||||
if($minmax==1)
|
||||
{
|
||||
$tag = strftime("%d",$t)+0;
|
||||
// echo "#Tag= $tag";
|
||||
// $query = "select $wert from archive where dateTime>=$t and dateTime<($t+86400)";
|
||||
$query = "select $wert from archive where dateTime>=$t and dateTime<($t+94000)"; // and strftime('%d',datetime(dateTime,'unixepoche','localtime'))==$tag";
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = "select $wert from archive where dateTime=$t";
|
||||
}
|
||||
$sql = $dbh->prepare($query);
|
||||
$sql->execute();
|
||||
$row = $sql->fetch(PDO::FETCH_ASSOC);
|
||||
// echo "#1: $query\n2: ";
|
||||
// print_r($row);
|
||||
// echo "\n#";
|
||||
return ($row[$wert]);
|
||||
}
|
||||
|
||||
|
||||
function getTemp($t)
|
||||
{
|
||||
$r = holwert($t,"outTemp",0);
|
||||
return(round((($r - 32 ) * 5 / 9),1));
|
||||
}
|
||||
|
||||
function getPress($t)
|
||||
{
|
||||
$r = holwert($t,"barometer",0);
|
||||
return(round($r/0.0295299));
|
||||
}
|
||||
|
||||
function getHumi($t)
|
||||
{
|
||||
$r = holwert($t,"outHumidity",0);
|
||||
return($r);
|
||||
}
|
||||
|
||||
function getRain($t,$h,$m)
|
||||
{
|
||||
global $dbh;
|
||||
|
||||
$curtime = (($h*60)+$m)*60;
|
||||
$t -= $curtime; // akt Tag, 0h00 berechnen
|
||||
if($curtime==0)
|
||||
{
|
||||
$curtime=86400;
|
||||
}
|
||||
$query = "select sum(rain) from archive where dateTime>=$t and dateTime<($t+$curtime)";
|
||||
$sql = $dbh->prepare($query);
|
||||
$sql->execute();
|
||||
$row = $sql->fetch(PDO::FETCH_ASSOC);
|
||||
// echo "#1: $query\n2: $r\n3: $row\n#\n";
|
||||
return(round($row["sum(rain)"]*25.4,1));
|
||||
}
|
||||
|
||||
function getWindDir($t)
|
||||
{
|
||||
$r = holwert($t,"windDir",0);
|
||||
return(round($r));
|
||||
}
|
||||
|
||||
function getWindSpeed($t)
|
||||
{
|
||||
$r = holwert($t,"windSpeed",0);
|
||||
return(round($r*1.609344));
|
||||
}
|
||||
|
||||
function getMaxTemp($t)
|
||||
{
|
||||
$r = holWert($t,"max(outTemp)",1);
|
||||
return(round((($r - 32 ) * 5 / 9),1));
|
||||
}
|
||||
|
||||
function getMaxPress($t)
|
||||
{
|
||||
$r = holWert($t,"max(barometer)",1);
|
||||
return(round($r/0.0295299));
|
||||
}
|
||||
|
||||
function getMaxHumi($t)
|
||||
{
|
||||
$r = holWert($t,"max(outHumidity)",1);
|
||||
return($r);
|
||||
}
|
||||
|
||||
function getMaxWindSpeed($t)
|
||||
{
|
||||
$r = holWert($t,"max(windSpeed)",1);
|
||||
return(round($r*1.609344,1));
|
||||
}
|
||||
|
||||
function getMinTemp($t)
|
||||
{
|
||||
$r = holWert($t,"min(outTemp)",1);
|
||||
return(round((($r - 32 ) * 5 / 9),1));
|
||||
}
|
||||
|
||||
function getMinPress($t)
|
||||
{
|
||||
$r = holWert($t,"min(barometer)",1);
|
||||
return(round($r/0.0295299));
|
||||
}
|
||||
|
||||
function getMinHumi($t)
|
||||
{
|
||||
$r = holWert($t,"min(outHumidity)",1);
|
||||
return($r);
|
||||
}
|
||||
|
||||
// echo '# im php call #';
|
||||
|
||||
$YY = 0;
|
||||
$YY = $_POST["Jahr"];
|
||||
$MM = $_POST["Monat"];
|
||||
$DD = $_POST["Tag"];
|
||||
$hh = $_POST["Stunde"];
|
||||
$mm = $_POST["Minute"];
|
||||
$anz = $_POST["Anzahl"];
|
||||
|
||||
|
||||
$utime = mktime($hh,$mm,0,$MM,$DD,$YY);
|
||||
|
||||
// DEBUG-AUsgabe: Achtung, diese IMMER in # ... # einpacken, dann wird sie
|
||||
// von dem auswertenden Javascript ausgeblendet
|
||||
//$tz = date_default_timezone_get();
|
||||
//echo "#$tz\n$YY-$MM-$DD <$hh:$mm> =$anz= +$utime+ \n#";
|
||||
|
||||
$paket = Array (
|
||||
|
||||
"Temp" => 0,
|
||||
"Humi" => 0,
|
||||
"Press" =>0,
|
||||
"Rain" => 0,
|
||||
"WindDir" => 0,
|
||||
"WindSpeed" => 0,
|
||||
"TempMx" => 0,
|
||||
"HumiMx" => 0,
|
||||
"PressMx" => 0,
|
||||
"Time" => 0,
|
||||
);
|
||||
|
||||
$erg = array(array());
|
||||
|
||||
|
||||
function buildMinMaxPaket($ut)
|
||||
{
|
||||
global $paket;
|
||||
$paket["Temp"] = getMinTemp($ut);
|
||||
$paket["Humi"] = getMinHumi($ut);
|
||||
$paket["Press"] = getMinPress($ut);
|
||||
$paket["Rain"] = getRain($ut,0,0);
|
||||
$paket["WindSpeed"] = getMaxWindSpeed($ut);
|
||||
$paket["TempMx"] = getMaxTemp($ut);
|
||||
$paket["HumiMx"] = getMaxHumi($ut);
|
||||
$paket["PressMx"] = getMaxPress($ut);
|
||||
$paket["Time"] = date("Y-m-d H:i",$ut);
|
||||
}
|
||||
|
||||
if ($YY!="")
|
||||
{
|
||||
if($anz==0)
|
||||
{
|
||||
if (($hh != 0) || ($mm != 0))
|
||||
{
|
||||
$paket["Temp"] = getTemp($utime);
|
||||
$paket["Humi"] = getHumi($utime);
|
||||
$paket["Press"] = getPress($utime);
|
||||
$paket["Rain"] = getRain($utime,$hh,$mm);
|
||||
$paket["WindDir"] = getWindDir($utime);
|
||||
$paket["WindSpeed"] = getWindSpeed($utime);
|
||||
$paket["Time"] = date("Y-m-d H:i",$utime);
|
||||
}
|
||||
else
|
||||
{
|
||||
buildMinMaxPaket($utime);
|
||||
}
|
||||
echo json_encode($paket);
|
||||
}
|
||||
else
|
||||
{
|
||||
for($i=0; $i<$anz; $i++)
|
||||
{
|
||||
buildMinMaxPaket($utime);
|
||||
$erg[$i] = $paket;
|
||||
$DD+=1;
|
||||
$utime = mktime($hh,$mm,0,$MM,$DD,$YY);
|
||||
}
|
||||
echo json_encode($erg);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user