Changeset 33c6557 for src/webapp/webservice
- Timestamp:
- Apr 27, 2017, 11:40:46 AM (10 years ago)
- Branches:
- 0.5, app-cordova, debian/bullseye, debian/jessie, master
- Children:
- c0782d9
- Parents:
- 368c2b8
- File:
-
- 1 edited
-
src/webapp/webservice/index.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/index.php
r368c2b8 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 … … 36 36 ); 37 37 38 function addRrdData($interval, $period, &$result, &$last Time){38 function addRrdData($interval, $period, &$result, &$lastValid){ 39 39 global $dbFile; 40 40 global $debug; 41 41 global $configRound; 42 $lastValid = false; 42 43 43 $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")); 44 48 if($data === false){ 45 49 echo json_encode($result); … … 49 53 else 50 54 error_log($message); 55 return; 51 56 } 52 57 … … 71 76 echo "<p>Variables: ". count($keys) ."; Timeframes: ". count($data[$keys[0]]) ."</p>\n"; 72 77 } 73 for($i = 0; $i < count($data[$keys[0]]); $i++){ 74 $time = array_keys($data[$keys[0]])[$i]; 78 foreach($data[$keys[0]] as $timeframe => $value){ 75 79 $allValid = true; 80 $gpsFix = false; 76 81 $tmp = array(); 77 82 foreach($keys as $key){ 78 83 if($key == "gpsfix"){ 79 switch($data[$key][$time ]){80 case 1:84 switch($data[$key][$timeframe]){ 85 case 2: 81 86 $tmp[$key] = "2D"; 87 $gpsFix = true; 82 88 break; 83 case 2:89 case 3: 84 90 $tmp[$key] = "3D"; 91 $gpsFix = true; 85 92 break; 86 93 default: … … 89 96 } 90 97 else{ 91 $tmp[$key] = $data[$key][$time ];98 $tmp[$key] = $data[$key][$timeframe]; 92 99 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 93 100 $allValid = false; … … 102 109 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 103 110 if($allValid){ 104 if(!array_key_exists($time, $result["track"])){ 105 $result["track"][$time] = $tmp; 106 } 107 $lastTime = $time; 111 $lastValid = $tmp; 112 if($gpsFix){ 113 if(!array_key_exists($timeframe, $result["track"])){ 114 $result["track"][$timeframe] = $tmp; 115 } 116 } 108 117 } 109 118 else{ … … 115 124 } 116 125 } 117 118 126 ksort($result["track"]); 119 127 } … … 159 167 exit; 160 168 } 161 // Fetch entries of the last 30 seconds162 addRrdData(" 5s", "30s", $result, $lastTime);163 if($last Time > -1){164 $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; 165 173 } 166 addRrdData("15s", "5minutes", $result, $lastTime); 167 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); 168 178 } 169 179 170 180 if($debug > 0){ 171 echo json_encode($result, JSON_PRETTY_PRINT) ;181 echo json_encode($result, JSON_PRETTY_PRINT) ."\n"; 172 182 } 173 183 else{ 174 echo json_encode($result) ;184 echo json_encode($result) ."\n"; 175 185 } 176 186
Note:
See TracChangeset
for help on using the changeset viewer.
