www/getfermentlog.php

changeset 601
112c278be803
parent 296
69fadd1aded2
child 836
409f8c497429
equal deleted inserted replaced
600:c136dd22f662 601:112c278be803
6 $code = $_GET["code"] . ' ' . $_GET["name"]; 6 $code = $_GET["code"] . ' ' . $_GET["name"];
7 else 7 else
8 $code = "TB0015 Winterbier-2"; 8 $code = "TB0015 Winterbier-2";
9 9
10 $filename = 'log/fermentation/' . $code . '.log'; 10 $filename = 'log/fermentation/' . $code . '.log';
11 if (! file_exists($filename)) {
12 header("Content-type: application/json");
13 echo '{}';
14 exit;
15 }
16
17
11 /* 18 /*
12 * From Stackoverflow, the fastest way to count the lines in a file. 19 * From Stackoverflow, the fastest way to count the lines in a file.
13 */ 20 */
14 $file = new \SplFileObject($filename, 'r'); 21 $file = new \SplFileObject($filename, 'r');
15 $file->seek(PHP_INT_MAX); 22 $file->seek(PHP_INT_MAX);
16 // $file->key() = lines in the file.
17 23
18 define ('MAX_INTERVALS', 10); 24 define ('MAX_INTERVALS', 10);
19 $GRAPH_INTERVAL = array ( 0, 1, 5, 15, 30, 60, 120, 240, 480, 720 ); 25 $GRAPH_INTERVAL = array ( 0, 1, 5, 15, 30, 60, 120, 240, 480, 720 );
20 $GRAPH_DATALINES = array ( 0, 800, 3200, 12000, 24000, 48000, 96000, 192000, 384000, 768000 ); 26 $GRAPH_DATALINES = array ( 0, 800, 3200, 12000, 24000, 48000, 96000, 192000, 384000, 768000 );
21 27
24 if ($file->key() < $GRAPH_DATALINES[$graphstep]) 30 if ($file->key() < $GRAPH_DATALINES[$graphstep])
25 break; 31 break;
26 } 32 }
27 if ($graphstep > MAX_INTERVALS) 33 if ($graphstep > MAX_INTERVALS)
28 $graphstep = MAX_INTERVALS; 34 $graphstep = MAX_INTERVALS;
29
30 //echo $code . '.log lines=' . $file->key() . ' interval=' . $GRAPH_INTERVAL[$graphstep] . ' graphstep=' . $graphstep . PHP_EOL;
31 35
32 /* 36 /*
33 * 2014-11-15 18:39,BEER,PRIMARY,20.312,19.750,-1.500,20.5,18.6,18.8,35,12345,0,67890,Whatsup 37 * 2014-11-15 18:39,BEER,PRIMARY,20.312,19.750,-1.500,20.5,18.6,18.8,35,12345,0,67890,Whatsup
34 * | | | | | | | | | | | | | | 38 * | | | | | | | | | | | | | |
35 * datetime + | | | | | | | | | | | | | 39 * datetime + | | | | | | | | | | | | |
113 } 117 }
114 fclose($handle); 118 fclose($handle);
115 } 119 }
116 header("Content-type: application/json"); 120 header("Content-type: application/json");
117 echo json_encode($logs); 121 echo json_encode($logs);
118 //echo $lines . ' lines' . PHP_EOL;

mercurial