Compare commits
5 Commits
highcharts
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
fadffc6346 | |
|
|
f5e186ceae | |
|
|
bb0bfa4818 | |
|
|
718552a90e | |
|
|
57336de413 |
|
|
@ -0,0 +1 @@
|
||||||
|
bb0bfa4
|
||||||
19
draw.php
19
draw.php
|
|
@ -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,16 +57,13 @@ 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.')';
|
||||||
/* TODO: think about*/
|
$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);
|
$summary=$db->select('summary','*',$where,"ORDER BY day");
|
||||||
if($summary===false){
|
if($summary===false){
|
||||||
$html.="No values (".$type.")";
|
$html.="No values (".$type.")";
|
||||||
return;
|
return;
|
||||||
|
|
@ -87,7 +84,9 @@ 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;
|
||||||
|
|
@ -274,13 +273,15 @@ function generateChart($today,$mode,$hours=0,$dateInput){
|
||||||
$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;
|
||||||
$div=1;
|
$selectionEnd+=60*60*24;
|
||||||
|
$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('val1',var_export($values,true));
|
#file_put_contents('val'.$type.($key+1),var_export($values,true));
|
||||||
}
|
}
|
||||||
|
|
||||||
$myData->addPoints($labels,"Labels");
|
$myData->addPoints($labels,"Labels");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
#pre-commit
|
||||||
|
git log -n 1 --format=format:"%h" HEAD > PREV_VERSION
|
||||||
|
|
@ -251,8 +251,12 @@ 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[]=$set[0];
|
||||||
|
}else{
|
||||||
$values[]=round($set[0]/$div,1);
|
$values[]=round($set[0]/$div,1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
function getLabels($data,$start,$end,$chartdistance=60){
|
function getLabels($data,$start,$end,$chartdistance=60){
|
||||||
|
|
|
||||||
162
highcharts.php
162
highcharts.php
|
|
@ -1,162 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: agp8x
|
|
||||||
* Date: 07.05.15
|
|
||||||
* Time: 18:36
|
|
||||||
*/
|
|
||||||
|
|
||||||
$start = microtime(true);
|
|
||||||
|
|
||||||
include "config.php";
|
|
||||||
include "lib/DBLib.php";
|
|
||||||
|
|
||||||
function average($list)
|
|
||||||
{
|
|
||||||
if (!$list) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$i = 0;
|
|
||||||
$sum = 0;
|
|
||||||
foreach ($list as $value) {
|
|
||||||
$i++;
|
|
||||||
$sum += $value['value'] / 100;
|
|
||||||
}
|
|
||||||
if ($i > 0) {
|
|
||||||
return round($sum / $i, 1);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$db = new DBLib($database['host'], $database['user'], $database['password'], $database['database']);
|
|
||||||
|
|
||||||
$sensors = ["temp1" => "Innen", "temp2" => "Aussen"];
|
|
||||||
$show_days = true;
|
|
||||||
$series = array();
|
|
||||||
$days = [];
|
|
||||||
foreach ($sensors as $sensor => $name) {
|
|
||||||
$date = new DateTime("2015-04-01T00:00:00+02:00", new DateTimeZone("Europe/Berlin"));
|
|
||||||
$date2 = clone $date;
|
|
||||||
$day_summaries = array();
|
|
||||||
for ($i = 0; $i < $date->format("t"); $i++) {
|
|
||||||
$start = $date->format("U");
|
|
||||||
$date->add(new DateInterval("P1D"));
|
|
||||||
$end = $date->format("U");
|
|
||||||
$entries = $db->selectRange($sensor, "*", array("time", $start, $end));
|
|
||||||
$day_summaries[] = average($entries);
|
|
||||||
if ($show_days) {
|
|
||||||
$hours = [];
|
|
||||||
for ($j = 0; $j < 24; $j++) {
|
|
||||||
$start = $date2->format("U");
|
|
||||||
$date2->add(new DateInterval("PT1H"));
|
|
||||||
$end = $date2->format("U");
|
|
||||||
$entries = $db->selectRange($sensor, "*", array("time", $start, $end));
|
|
||||||
$hours[] = average($entries);
|
|
||||||
}
|
|
||||||
$days[] = ["name" => $date->format("d.m.Y") . " (" . $name . ")", "data" => $hours];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$series[] = array("name" => $name, "data" => $day_summaries);
|
|
||||||
}
|
|
||||||
|
|
||||||
$json = json_encode($series, JSON_NUMERIC_CHECK /*| JSON_PRETTY_PRINT*/);
|
|
||||||
$json2 = json_encode($days, JSON_NUMERIC_CHECK /*| JSON_PRETTY_PRINT*/);
|
|
||||||
$runtime = "Runtime: " . ((microtime(true) - $start) / 1000 / 1000);
|
|
||||||
$runtime .= " s";
|
|
||||||
?>
|
|
||||||
|
|
||||||
<!DOCTYPE HTML>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
||||||
<title>Highcharts Example</title>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
|
|
||||||
<style type="text/css">
|
|
||||||
${demo.css}
|
|
||||||
</style>
|
|
||||||
<script type="text/javascript">
|
|
||||||
$(function () {
|
|
||||||
$('#container').highcharts({
|
|
||||||
title: {
|
|
||||||
text: 'Monthly Average Temperature',
|
|
||||||
x: -20 //center
|
|
||||||
},
|
|
||||||
subtitle: {
|
|
||||||
text: 'April 2014\<br\>Source: agp8x.org',
|
|
||||||
x: -20
|
|
||||||
},
|
|
||||||
xAxis: {
|
|
||||||
categories: []
|
|
||||||
},
|
|
||||||
yAxis: {
|
|
||||||
title: {
|
|
||||||
text: 'Temperature (°C)'
|
|
||||||
},
|
|
||||||
plotLines: [{
|
|
||||||
value: 0,
|
|
||||||
width: 1,
|
|
||||||
color: '#808080'
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
valueSuffix: '°C'
|
|
||||||
},
|
|
||||||
legend: {
|
|
||||||
layout: 'vertical',
|
|
||||||
align: 'right',
|
|
||||||
verticalAlign: 'middle',
|
|
||||||
borderWidth: 0
|
|
||||||
},
|
|
||||||
series: <?= $json ?>
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function () {
|
|
||||||
$('#container2').highcharts({
|
|
||||||
title: {
|
|
||||||
text: 'Daily Average Temperature',
|
|
||||||
x: -20 //center
|
|
||||||
},
|
|
||||||
subtitle: {
|
|
||||||
text: 'April 2014\<br\>Source: agp8x.org',
|
|
||||||
x: -20
|
|
||||||
},
|
|
||||||
xAxis: {
|
|
||||||
categories: []
|
|
||||||
},
|
|
||||||
yAxis: {
|
|
||||||
title: {
|
|
||||||
text: 'Temperature (°C)'
|
|
||||||
},
|
|
||||||
plotLines: [{
|
|
||||||
value: 0,
|
|
||||||
width: 1,
|
|
||||||
color: '#808080'
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
valueSuffix: '°C'
|
|
||||||
},
|
|
||||||
legend: {
|
|
||||||
layout: 'vertical',
|
|
||||||
align: 'right',
|
|
||||||
verticalAlign: 'middle',
|
|
||||||
borderWidth: 0
|
|
||||||
},
|
|
||||||
series: <?= $json2 ?>
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script src="http://code.highcharts.com/highcharts.js"></script>
|
|
||||||
<script src="http://code.highcharts.com/modules/exporting.js"></script>
|
|
||||||
|
|
||||||
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
|
|
||||||
<div id="container2" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
|
|
||||||
|
|
||||||
<div style='position:fixed;bottom:20px;right:50px;'><?= ($runtime) ?></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
2
recent
2
recent
|
|
@ -1 +1 @@
|
||||||
Temperatur: 10.37 C<br>Luftfeuchtigkeit: 70.2 %<br>Helligkeit: 0.01 Lux<br>Luftdruck: 981.66mbar
|
Temperatur: 22.81 C<br>Luftfeuchtigkeit: 0 %<br>Helligkeit: 0.01 Lux<br>Luftdruck: 0mbar
|
||||||
|
|
@ -7,17 +7,11 @@ $db=new DBLib();
|
||||||
|
|
||||||
$db=new DBLib($database['host'],$database['user'],$database['password'],$database['database']);
|
$db=new DBLib($database['host'],$database['user'],$database['password'],$database['database']);
|
||||||
|
|
||||||
function markerFile($file="newData"){
|
|
||||||
if (! file_exists($file)){
|
|
||||||
file_put_contents($file,"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$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)){
|
||||||
markerFile();
|
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:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue