Compare commits

..

5 Commits

Author SHA1 Message Date
agp8x fadffc6346 improved handling of missing values 2015-09-25 00:20:07 +02:00
agp8x f5e186ceae fixed mixed days in month-view 2015-09-02 11:57:52 +02:00
agp8x bb0bfa4818 month-view: fixed missing last day 2015-09-02 11:45:14 +02:00
agp8x 718552a90e fixed version-dump 2015-09-02 11:14:52 +02:00
agp8x 57336de413 added version-dump-pre-commit 2015-09-02 11:13:36 +02:00
7 changed files with 20 additions and 180 deletions

1
PREV_VERSION Normal file
View File

@ -0,0 +1 @@
bb0bfa4

View File

@ -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,16 +57,13 @@ function generateChart($today,$mode,$hours=0,$dateInput){
$datas[]=$db->selectRange($type.$i,'*',$rangeSelector);
if($datas[$i-1]===false){
$html.='No values ('.$type.$i.')';
/* TODO: think about*/
if($type!="ambi"){
return;
}
$datas[$i-1]=array(0,0);
}
}
}else{
$where=array('year'=>$year,'month'=>$month);
$db->toggleDevmode();
$summary=$db->select('summary','*',$where);
//$db->toggleDevmode();
$summary=$db->select('summary','*',$where,"ORDER BY day");
if($summary===false){
$html.="No values (".$type.")";
return;
@ -87,7 +84,9 @@ 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;
@ -274,13 +273,15 @@ function generateChart($today,$mode,$hours=0,$dateInput){
$labels=getLabels($datas[0],$selectionStart,$selectionEnd,$chartdistance);
if($mode==3){
$selectionStart+=60*60*24;
$div=1;
$selectionEnd+=60*60*24;
$div=0;
}
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('val1',var_export($values,true));
#file_put_contents('val'.$type.($key+1),var_export($values,true));
}
$myData->addPoints($labels,"Labels");

2
dump-version.sh Executable file
View File

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

View File

@ -251,7 +251,11 @@ function prepareData($data,$div,$start=0,$end=0,$chartdistance=60){
$values=array();
$rawdata=outlinedLogPoints($data,$chartdistance,$start,$end);
foreach($rawdata as $set){
$values[]=round($set[0]/$div,1);
if($div==0){
$values[]=$set[0];
}else{
$values[]=round($set[0]/$div,1);
}
}
return $values;
}

View File

@ -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
View File

@ -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

View File

@ -7,17 +7,11 @@ $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)){
markerFile();
file_put_contents('newData',"");
echo "parsing file: ".$file."\n";
importLogfiletoDatabase('data/'.$file);
//recent records on frontpage: