Compare commits
3 Commits
master
...
highcharts
| Author | SHA1 | Date |
|---|---|---|
|
|
3286e8b2fb | |
|
|
db8125640b | |
|
|
c20a864700 |
|
|
@ -0,0 +1,162 @@
|
|||
<?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: 13.43 C<br>Luftfeuchtigkeit: 89.5 %<br>Helligkeit: 0.01 Lux<br>Luftdruck: 982.473mbar
|
||||
Temperatur: 10.37 C<br>Luftfeuchtigkeit: 70.2 %<br>Helligkeit: 0.01 Lux<br>Luftdruck: 981.66mbar
|
||||
|
|
@ -7,11 +7,17 @@ $db=new DBLib();
|
|||
|
||||
$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');
|
||||
$temp=$humi=$ambi=$baro=0;
|
||||
foreach($dir as $file){
|
||||
if(validFile($file)){
|
||||
file_put_contents('newData',"");
|
||||
markerFile();
|
||||
echo "parsing file: ".$file."\n";
|
||||
importLogfiletoDatabase('data/'.$file);
|
||||
//recent records on frontpage:
|
||||
|
|
|
|||
Loading…
Reference in New Issue