<html>
<?php
## Put todays date into a variable for later use...
$date= date("d-m-Y");
## Tell PHP the location of our datafile for the current date...
## file_get_contents() retrieves the contents and places it into a
## variable as a string.
$txt_file= file_get_contents('temp_log_' .$date. '.txt');
## Do a little error checking and display a message if the text
## file is missing...
if(!$txt_file) {
echo "<br>ERROR - There is no information for this date.";
## If the file is present lets get going...
} else {
## Retrieve each row from the file. The explode() function
## in this instance is using each new line ("\n") as a delimiter
## and assigning the entire file to a variable ($rows)...
$rows= explode("\n", $txt_file);
## As the explode() function will treat the last line as a new
## record, we need to remove the last record (which is a blank line).
## array_pop() does this for us automatically...
array_pop($rows);
## Setup two blank arrays for our data. One for the time and one
## for the temperatures...
$temp=array();
$time=array();
## Now we use a foreach statement to parse each row so that we can
## process them and sort our data. We assign each row to a
## variable ($data)...
foreach($rows as $row => $data)
{
## Break down the individual record using (,) as delimiter.
$total= explode(",", $data);
## Extract the time from the record and make it loo pretty...
$t= explode(":", $total[1]);
$time[]= "$t[0]:$t[1]"; # <--- OVDEEEEEEEEEEEEE
## Extract the temperature data from the record...
## floor() rounds the number down to the nearest integer.
## We then multiply this by 100 and divide the rounded down
## figure by 100. This gives our temperature in a huma
## readable fashion with the correct decimal places...
$temp[]= floor($total[2] * 100) / 100; # <--- OVDEEEEEEEEEEEEE
## Notice that within this foreach statement I have
## used the two variables $temp & $time with [] appended
## to the end. Doing this saves our new, re-fashioned
## readings back to the variable turning it into an array of
## all the data...
## then we end the foreach statement...
}
## Now we use the implode function to accumulate each row
## that we have processed and save it back to an array.
## We use (,) as our delimiter again...
$tempa= implode(",", $temp);
$timea= implode(",", $time);
## We have two, human-readable, arrays of data that we can
## now pass to our graph...
}
?>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Todays Temperature Chart',
x: -20 //center
},
subtitle: {
text: 'Source: My Raspberry Pi',
x: -20
},
xAxis: {
categories: [<?php echo $timea; ?>]
},
yAxis: {
title: {
text: 'Temperature'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: ''
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
name: 'Celcius',
data: [<?php echo $tempa; ?>]
}]
});
});
</script>
</head>
<body>
<script src="charts/js/highcharts.js"></script>
<script src="charts/js/modules/exporting.js"></script>
<div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
</body>
</html>
a iz txt fajla vuce ove podatke
21-02-2016 05:30:01,18.687
21-02-2016 06:00:02,18.437
21-02-2016 06:30:01,18.125
21-02-2016 07:00:01,17.875
21-02-2016 07:30:01,17.687
21-02-2016 08:00:01,17.375
21-02-2016 08:30:02,17.5
21-02-2016 09:00:01,16.562
21-02-2016 09:30:02,14.812
21-02-2016 10:00:01,15.062
21-02-2016 10:30:01,17.0
21-02-2016 11:00:01,18.625
21-02-2016 11:30:01,19.5
21-02-2016 12:00:01,19.625
21-02-2016 12:30:01,19.812
21-02-2016 13:00:01,20.687
21-02-2016 13:30:01,20.687
21-02-2016 14:00:01,20.812
21-02-2016 14:30:02,20.5
21-02-2016 15:00:01,20.5
21-02-2016 15:30:01,20.562
21-02-2016 16:00:01,20.5
21-02-2016 16:30:01,20.25
21-02-2016 17:00:01,20.562
21-02-2016 17:30:02,19.937
21-02-2016 18:00:01,19.875
21-02-2016 18:30:01,19.812
21-02-2016 19:00:01,19.812
21-02-2016 19:30:02,20.125
21-02-2016 20:00:01,20.125
21-02-2016 20:30:01,19.875
21-02-2016 21:00:01,19.937