- File:
-
- 1 edited
-
src/webapp/webservice/inc/GnuBoat/ServiceData.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/inc/GnuBoat/ServiceData.php
r1ba85cf r0662b2d 29 29 $this->_configRound = array 30 30 ( 31 "latitude" => 5,32 "longitude" => 5,31 "latitude" => 4, 32 "longitude" => 4, 33 33 "speedthroughwater" => 1, 34 34 "speedoverground" => 1, 35 "courseoverground" => 1, 35 36 "waterdepth" => 1, 36 37 "watertemperature" => 1, … … 48 49 $result["track"] = array(); 49 50 50 if(!file_exists($dbFile)){ 51 echo json_encode(""); 52 if($debug > 0) 53 echo "Database file ". $dbFile ." does not exist!"; 54 error_log("Database file ". $dbFile ." does not exist"); 55 exit; 56 } 51 if(!file_exists($dbFile)) 52 return $this->error("Database file ". $dbFile ." does not exist"); 53 57 54 // Fetch entries of the last 30s with maximum (available) resolution of 2s 58 55 $this->addRrdData($dbFile, "2", "240", $result, $lastValid); 59 if($lastValid ){60 $result["lastvalid"] = $lastValid ;56 if($lastValid !== false){ 57 $result["lastvalid"] = $lastValid->toArray(); 61 58 } 62 59 // Fetch entries of the last 1h with maximum (available) resolution of 10s … … 65 62 $this->addRrdData($dbFile, "60", "86400", $result, $lastTime); 66 63 67 if($debug > 0){ 68 echo json_encode($result, JSON_PRETTY_PRINT) ."\n"; 69 } 70 else{ 71 header('Content-Type: application/json'); 72 echo json_encode($result) ."\n"; 73 } 64 return $this->output($result); 74 65 } 75 66 … … 82 73 $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", $startTime, "--end", $endTime)); 83 74 // $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period, "--align-start")); 84 if($data === false){ 85 echo json_encode($result); 86 $message = "Failure reading rrd database ". $dbFile .": ". rrd_error(); 87 if($debug > 0) 88 echo $message; 89 else 90 error_log($message); 91 return; 92 } 75 if($data === false) 76 return $this->error("Failure reading rrd database ". $dbFile .": ". rrd_error(), $result); 93 77 94 78 if($debug > 2){ 95 echo "<pre>";96 79 var_dump($data); 97 echo "</pre>";98 80 } 99 81 … … 102 84 // transform them into json format 103 85 $i = 0; 104 $lastValid = -1;86 $lastValid = false; 105 87 $keys = array_keys($data); 106 88 $keyTimeframes = $keys[0]; 107 89 $itemCount = count($keys); 108 if($itemCount < 0 ){ 109 error_log("No keys in fetched rrd data from ". $dbFile); 110 echo json_encode(""); 111 exit; 112 } 90 if($itemCount < 0 ) 91 return $this->error("No keys in fetched rrd data from ". $dbFile); 92 113 93 $timeframesCount = count($data[$keyTimeframes]); 114 if($debug > 0){115 e cho "<p>Variables: ". $itemCount ."; Timeframes: ". $timeframesCount ."</p>\n";94 if($debug > 1){ 95 error_log("Variables: ". $itemCount ."; Timeframes: ". $timeframesCount); 116 96 } 117 97 foreach($data[$keys[0]] as $timeframe => $value){ 118 $allValid = true; 119 $gpsFix = false; 120 $tmp = array(); 98 $tmp = new TrackItem($timeframe); 121 99 foreach($keys as $key){ 122 if($key == "gpsfix"){ 123 switch($data[$key][$timeframe]){ 124 case 2: 125 $tmp[$key] = "2D"; 126 $gpsFix = true; 127 break; 128 case 3: 129 $tmp[$key] = "3D"; 130 $gpsFix = true; 131 break; 132 default: 133 $tmp[$key] = "-"; 134 } 135 } 136 else{ 137 $tmp[$key] = $data[$key][$timeframe]; 138 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 139 $allValid = false; 140 if($debug > 1){ 141 echo "Invalid value ". $key ." (". $tmp[$key] .") at time ". $timeframe ."<br/>"; 142 } 143 } 144 elseif(array_key_exists($key, $this->_configRound) && is_integer($this->_configRound[$key])) 145 $tmp[$key] = round($tmp[$key], $this->_configRound[$key]); 146 } 100 $value = $data[$key][$timeframe]; 101 if(array_key_exists($key, $this->_configRound) && is_integer($this->_configRound[$key])) 102 $value = round($value, $this->_configRound[$key]); 103 if(!$tmp->setProperty($key, $value) && $debug > 1) 104 error_log("Coult not set property ". $key ." to value ". $value ." at ". $timeframe); 147 105 } 148 106 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 149 if($ allValid){107 if($tmp->isValid()){ 150 108 $lastValid = $tmp; 151 if($ gpsFix){109 if($tmp->gpsFixed()){ 152 110 if(!array_key_exists($timeframe, $result["track"])){ 153 $result["track"][$timeframe] = $tmp ;111 $result["track"][$timeframe] = $tmp->toArray(); 154 112 } 155 113 }
Note:
See TracChangeset
for help on using the changeset viewer.
