Changeset 12afe34 for src/webapp/webservice/index.php
- Timestamp:
- Apr 27, 2017, 11:49:07 AM (10 years ago)
- Branches:
- debian/bullseye, debian/jessie
- Children:
- f553e71
- Parents:
- 7b68139 (diff), c84f87e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/webapp/webservice/index.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/index.php
r7b68139 r12afe34 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 … … 38 38 ); 39 39 40 function addRrdData($interval, $period, &$result, &$last Time){40 function addRrdData($interval, $period, &$result, &$lastValid){ 41 41 global $dbFile; 42 42 global $debug; 43 43 global $configRound; 44 $lastValid = false; 44 45 45 $data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period)); 46 $endTime = floor(time() / $interval) * $interval; 47 $startTime = $endTime - $period; 48 $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", $startTime, "--end", $endTime)); 49 // $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period, "--align-start")); 46 50 if($data === false){ 47 51 echo json_encode($result); … … 51 55 else 52 56 error_log($message); 57 return; 53 58 } 54 59 … … 76 81 echo "<p>Variables: ". $itemCount ."; Timeframes: ". $timeframesCount ."</p>\n"; 77 82 } 78 $keysTimeframes = array_keys($data[$keyTimeframes]); 79 for($i = 0; $i < $timeframesCount; $i++){ 80 $time = $keysTimeframes[$i]; 83 foreach($data[$keys[0]] as $timeframe => $value){ 81 84 $allValid = true; 85 $gpsFix = false; 82 86 $tmp = array(); 83 87 foreach($keys as $key){ 84 88 if($key == "gpsfix"){ 85 switch($data[$key][$time ]){86 case 1:89 switch($data[$key][$timeframe]){ 90 case 2: 87 91 $tmp[$key] = "2D"; 92 $gpsFix = true; 88 93 break; 89 case 2:94 case 3: 90 95 $tmp[$key] = "3D"; 96 $gpsFix = true; 91 97 break; 92 98 default: … … 95 101 } 96 102 else{ 97 $tmp[$key] = $data[$key][$time ];103 $tmp[$key] = $data[$key][$timeframe]; 98 104 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 99 105 $allValid = false; … … 108 114 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 109 115 if($allValid){ 110 if(!array_key_exists($time, $result["track"])){ 111 $result["track"][$time] = $tmp; 112 } 113 $lastTime = $time; 116 $lastValid = $tmp; 117 if($gpsFix){ 118 if(!array_key_exists($timeframe, $result["track"])){ 119 $result["track"][$timeframe] = $tmp; 120 } 121 } 114 122 } 115 123 else{ … … 121 129 } 122 130 } 123 124 131 ksort($result["track"]); 125 132 } … … 165 172 exit; 166 173 } 167 // Fetch entries of the last 30 seconds168 addRrdData(" 5s", "30s", $result, $lastTime);169 if($last Time > -1){170 $result["lastvalid"] = $ result["track"][$lastTime];174 // Fetch entries of the last 30s with maximum (available) resolution of 2s 175 addRrdData("2", "240", $result, $lastValid); 176 if($lastValid){ 177 $result["lastvalid"] = $lastValid; 171 178 } 172 addRrdData("15s", "5minutes", $result, $lastTime); 173 addRrdData("30s", "12h", $result, $lastTime); 179 // Fetch entries of the last 1h with maximum (available) resolution of 10s 180 addRrdData("10", "36000", $result, $lastTime); 181 // Fetch entries of the last 24h with maximum (available) resolution of 60s 182 addRrdData("60", "86400", $result, $lastTime); 174 183 } 175 184 176 185 if($debug > 0){ 177 echo json_encode($result, JSON_PRETTY_PRINT) ;186 echo json_encode($result, JSON_PRETTY_PRINT) ."\n"; 178 187 } 179 188 else{ 180 echo json_encode($result) ;189 echo json_encode($result) ."\n"; 181 190 } 182 191
Note:
See TracChangeset
for help on using the changeset viewer.
