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