Changes in src/webapp/webservice/index.php [acea570:33c6557]
- File:
-
- 1 edited
-
src/webapp/webservice/index.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/index.php
racea570 r33c6557 1 1 <?php 2 2 /* 3 Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.3 Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 4 4 5 5 This program is free software: you can redistribute it and/or modify … … 16 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 17 */ 18 19 xdebug_start_trace();20 18 21 19 require_once(__DIR__ ."/inc/Config.php"); … … 38 36 ); 39 37 40 function addRrdData($interval, $period, &$result, &$last Time){38 function addRrdData($interval, $period, &$result, &$lastValid){ 41 39 global $dbFile; 42 40 global $debug; 43 41 global $configRound; 42 $lastValid = false; 44 43 45 $data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period)); 44 $endTime = floor(time() / $interval) * $interval; 45 $startTime = $endTime - $period; 46 $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", $startTime, "--end", $endTime)); 47 // $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period, "--align-start")); 46 48 if($data === false){ 47 49 echo json_encode($result); … … 51 53 else 52 54 error_log($message); 55 return; 53 56 } 54 57 … … 65 68 $lastTime = -1; 66 69 $keys = array_keys($data); 67 $keyTimeframes = $keys[0]; 68 $itemCount = count($keys); 69 if($itemCount < 0 ){ 70 if(count($keys) < 0 ){ 70 71 error_log("No keys in fetched rrd data from ". $dbFile); 71 72 echo json_encode(""); 72 73 exit; 73 74 } 74 $timeframesCount = count($data[$keyTimeframes]);75 75 if($debug > 0){ 76 echo "<p>Variables: ". $itemCount ."; Timeframes: ". $timeframesCount."</p>\n";76 echo "<p>Variables: ". count($keys) ."; Timeframes: ". count($data[$keys[0]]) ."</p>\n"; 77 77 } 78 $keysTimeframes = array_keys($data[$keyTimeframes]); 79 for($i = 0; $i < $timeframesCount; $i++){ 80 $time = $keysTimeframes[$i]; 78 foreach($data[$keys[0]] as $timeframe => $value){ 81 79 $allValid = true; 80 $gpsFix = false; 82 81 $tmp = array(); 83 82 foreach($keys as $key){ 84 83 if($key == "gpsfix"){ 85 switch($data[$key][$time ]){86 case 1:84 switch($data[$key][$timeframe]){ 85 case 2: 87 86 $tmp[$key] = "2D"; 87 $gpsFix = true; 88 88 break; 89 case 2:89 case 3: 90 90 $tmp[$key] = "3D"; 91 $gpsFix = true; 91 92 break; 92 93 default: … … 95 96 } 96 97 else{ 97 $tmp[$key] = $data[$key][$time ];98 $tmp[$key] = $data[$key][$timeframe]; 98 99 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 99 100 $allValid = false; … … 108 109 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 109 110 if($allValid){ 110 if(!array_key_exists($time, $result["track"])){ 111 $result["track"][$time] = $tmp; 112 } 113 $lastTime = $time; 111 $lastValid = $tmp; 112 if($gpsFix){ 113 if(!array_key_exists($timeframe, $result["track"])){ 114 $result["track"][$timeframe] = $tmp; 115 } 116 } 114 117 } 115 118 else{ … … 121 124 } 122 125 } 123 124 126 ksort($result["track"]); 125 127 } … … 165 167 exit; 166 168 } 167 // Fetch entries of the last 30 seconds168 addRrdData(" 5s", "30s", $result, $lastTime);169 if($last Time > -1){170 $result["lastvalid"] = $ result["track"][$lastTime];169 // Fetch entries of the last 30s with maximum (available) resolution of 2s 170 addRrdData("2", "240", $result, $lastValid); 171 if($lastValid){ 172 $result["lastvalid"] = $lastValid; 171 173 } 172 addRrdData("15s", "5minutes", $result, $lastTime); 173 addRrdData("30s", "12h", $result, $lastTime); 174 // Fetch entries of the last 1h with maximum (available) resolution of 10s 175 addRrdData("10", "36000", $result, $lastTime); 176 // Fetch entries of the last 24h with maximum (available) resolution of 60s 177 addRrdData("60", "86400", $result, $lastTime); 174 178 } 175 179 176 180 if($debug > 0){ 177 echo json_encode($result, JSON_PRETTY_PRINT) ;181 echo json_encode($result, JSON_PRETTY_PRINT) ."\n"; 178 182 } 179 183 else{ 180 echo json_encode($result) ;184 echo json_encode($result) ."\n"; 181 185 } 182 186 183 xdebug_stop_trace();184 185 187 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
