www/getco2pressurelog.php

Sat, 25 Sep 2021 10:42:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 25 Sep 2021 10:42:54 +0200
changeset 778
e64fd38c469c
parent 600
c136dd22f662
permissions
-rw-r--r--

If during styles import the CATEGORY_NUMBER is empty, insert 0 in the database instead.

507
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require_once('config.php');
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 if (isset($_GET["code"]))
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 $code = $_GET["code"] . ' ' . $_GET["name"];
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 else
600
c136dd22f662 Handle non excisting logfiles.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
8 $code = "CB0080 Op stoom";
507
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 $filename = 'log/co2pressure/' . $code . '.log';
600
c136dd22f662 Handle non excisting logfiles.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
11 if (! file_exists($filename)) {
c136dd22f662 Handle non excisting logfiles.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
12 header("Content-type: application/json");
c136dd22f662 Handle non excisting logfiles.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
13 echo '{}';
c136dd22f662 Handle non excisting logfiles.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
14 exit;
c136dd22f662 Handle non excisting logfiles.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
15 }
c136dd22f662 Handle non excisting logfiles.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
16
c136dd22f662 Handle non excisting logfiles.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
17
507
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 /*
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * From Stackoverflow, the fastest way to count the lines in a file.
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 */
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 $file = new \SplFileObject($filename, 'r');
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 $file->seek(PHP_INT_MAX);
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 define ('MAX_INTERVALS', 10);
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 $GRAPH_INTERVAL = array ( 0, 1, 5, 15, 30, 60, 120, 240, 480, 720 );
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 $GRAPH_DATALINES = array ( 0, 800, 3200, 12000, 24000, 48000, 96000, 192000, 384000, 768000 );
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 for ($graphstep = 1; $graphstep <= MAX_INTERVALS; $graphstep++) {
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 if ($file->key() < $GRAPH_DATALINES[$graphstep])
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 break;
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 }
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 if ($graphstep > MAX_INTERVALS)
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 $graphstep = MAX_INTERVALS;
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 /*
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 * 2014-11-15 18:39:12,TEMPERATURE,PRESSURE,UUID
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 * | | | |
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 * datetime + | | |
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 * temperature ------------+ | |
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 * pressure --------------------------+ |
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 * unit uuid --------------------------------+
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 */
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 $handle = @fopen($filename, "r");
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 if ($handle) {
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 $lines = 0;
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 while (($buffer = fgets($handle, 4096)) !== false) {
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 $buffer = preg_replace( "/\r|\n/", "", $buffer);
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 $row = explode(",", $buffer);
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 $hr = intval(substr($buffer, 11, 2));
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 if ((($graphstep == 1)) ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 (($graphstep == 2) && ((substr($buffer, 15, 1) == '0') || (substr($buffer, 15, 1) == '5'))) ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 (($graphstep == 3) && ((substr($buffer, 14, 2) == '00') || (substr($buffer, 14, 2) == '15') ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 (substr($buffer, 14, 2) == '30') || (substr($buffer, 14, 2) == '45'))) ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 (($graphstep == 4) && ((substr($buffer, 14, 2) == '00') || (substr($buffer, 14, 2) == '30'))) ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 (($graphstep == 5) && (substr($buffer, 14, 2) == '00')) ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 (($graphstep == 6) && (substr($buffer, 14, 2) == '00') && (($hr % 2) == 0)) ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 (($graphstep == 7) && (substr($buffer, 14, 2) == '00') && (($hr % 4) == 0)) ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 (($graphstep == 8) && (substr($buffer, 14, 2) == '00') && (($hr % 8) == 0)) ||
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 (($graphstep == 9) && (substr($buffer, 14, 2) == '00') && (($hr % 12) == 0))) {
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 $lines++;
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 $logs[] = array(
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 'date' => $row[0],
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 'temperature' => $row[1],
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 'pressure' => $row[2]
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 );
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 }
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 }
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 if (!feof($handle)) {
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 echo "Error: unexpected fgets() fail\n";
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 }
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 fclose($handle);
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 }
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 header("Content-type: application/json");
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 echo json_encode($logs);

mercurial