www/getco2pressurelog.php

changeset 600
c136dd22f662
parent 507
17f244137a9b
child 838
ce5f39b66a51
equal deleted inserted replaced
599:1460c92927b2 600:c136dd22f662
3 require_once('config.php'); 3 require_once('config.php');
4 4
5 if (isset($_GET["code"])) 5 if (isset($_GET["code"]))
6 $code = $_GET["code"] . ' ' . $_GET["name"]; 6 $code = $_GET["code"] . ' ' . $_GET["name"];
7 else 7 else
8 $code = "TB0015 Winterbier-2"; 8 $code = "CB0080 Op stoom";
9 9
10 $filename = 'log/co2pressure/' . $code . '.log'; 10 $filename = 'log/co2pressure/' . $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
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 35
30 //echo $code . '.log lines=' . $file->key() . ' interval=' . $GRAPH_INTERVAL[$graphstep] . ' graphstep=' . $graphstep . PHP_EOL;
31 36
32 /* 37 /*
33 * 2014-11-15 18:39:12,TEMPERATURE,PRESSURE,UUID 38 * 2014-11-15 18:39:12,TEMPERATURE,PRESSURE,UUID
34 * | | | | 39 * | | | |
35 * datetime + | | | 40 * datetime + | | |
56 (($graphstep == 5) && (substr($buffer, 14, 2) == '00')) || 61 (($graphstep == 5) && (substr($buffer, 14, 2) == '00')) ||
57 (($graphstep == 6) && (substr($buffer, 14, 2) == '00') && (($hr % 2) == 0)) || 62 (($graphstep == 6) && (substr($buffer, 14, 2) == '00') && (($hr % 2) == 0)) ||
58 (($graphstep == 7) && (substr($buffer, 14, 2) == '00') && (($hr % 4) == 0)) || 63 (($graphstep == 7) && (substr($buffer, 14, 2) == '00') && (($hr % 4) == 0)) ||
59 (($graphstep == 8) && (substr($buffer, 14, 2) == '00') && (($hr % 8) == 0)) || 64 (($graphstep == 8) && (substr($buffer, 14, 2) == '00') && (($hr % 8) == 0)) ||
60 (($graphstep == 9) && (substr($buffer, 14, 2) == '00') && (($hr % 12) == 0))) { 65 (($graphstep == 9) && (substr($buffer, 14, 2) == '00') && (($hr % 12) == 0))) {
61 // echo $hr . ' ' . $row[1] . ' ' . $buffer;
62 $lines++; 66 $lines++;
63
64 // $heat_used = $cool_used = 0;
65 // if ($row[10] && ($row[10] != "NA") && ($heater_l > 0)) {
66 // $heat_used = round((intval($row[10]) - $heater_l) * 100 / ($GRAPH_INTERVAL[$graphstep] * 60));
67 // }
68 // if ($row[12] && ($row[12] != "NA") && ($cooler_l > 0)) {
69 // $cool_used = round((intval($row[12]) - $cooler_l) * 100 / ($GRAPH_INTERVAL[$graphstep] * 60));
70 // }
71
72
73 // echo $GRAPH_INTERVAL[$graphstep] . ' ' . $heat_used . ' ' . $cool_used . PHP_EOL;
74
75 // if (($heat_used <= 100) && ($cool_used <= 100)) {
76 $logs[] = array( 67 $logs[] = array(
77 'date' => $row[0], 68 'date' => $row[0],
78 'temperature' => $row[1], 69 'temperature' => $row[1],
79 'pressure' => $row[2] 70 'pressure' => $row[2]
80 ); 71 );
81 // }
82
83 // if ($row[10] && ($row[10] != "NA"))
84 // $heater_l = intval($row[10]);
85 // if ($row[12] && ($row[12] != "NA"))
86 // $cooler_l = intval($row[12]);
87 } 72 }
88
89 } 73 }
90 if (!feof($handle)) { 74 if (!feof($handle)) {
91 echo "Error: unexpected fgets() fail\n"; 75 echo "Error: unexpected fgets() fail\n";
92 } 76 }
93 fclose($handle); 77 fclose($handle);
94 } 78 }
95 header("Content-type: application/json"); 79 header("Content-type: application/json");
96 echo json_encode($logs); 80 echo json_encode($logs);
97 //echo $lines . ' lines' . PHP_EOL;

mercurial