- Timestamp:
- Jul 20, 2016, 5:18:34 PM (10 years ago)
- Branches:
- 0.5, app-cordova, debian/bullseye, debian/jessie, master
- Children:
- d7ee6ae
- Parents:
- a250eb4
- Location:
- src/webapp
- Files:
-
- 4 edited
-
webclient/css/main.css (modified) (4 diffs)
-
webclient/javascript/main.js (modified) (2 diffs)
-
webclient/root/index.php (modified) (1 diff)
-
webservice/index.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webclient/css/main.css
ra250eb4 r5519ced 18 18 body { 19 19 margin: 1em; 20 width: 58.3mm; 20 21 } 21 22 … … 35 36 #display { 36 37 background-color: #E6E6E6; 37 width: 58.3mm;38 width: 100%; 38 39 height: 38.2mm; 39 40 font-size: 12pt; … … 94 95 95 96 #map { 96 width: 58.3mm;97 width: 100%; 97 98 height: 76mm; 98 99 border: 1px solid black; … … 133 134 134 135 } 136 137 #shutdown { 138 width: 100%; 139 margin-top: 3em; 140 } 141 142 #shutdown button { 143 background-color: #8C1C00; 144 color: white; 145 font-weight: bold; 146 font-size: 24pt; 147 width: 100%; 148 } -
src/webapp/webclient/javascript/main.js
ra250eb4 r5519ced 102 102 } 103 103 104 function shutdown(){ 105 $.getJSON("../webservice/?request=shutdown", function(data){ 106 var shutdownTime = data["shutdownstart"]; 107 var shutdownDate = new Date(shutdownTime); 108 var currentDate = new Date(); 109 var shutdownHint = "Shutting down in "+ Math.floor((shutdownDate - currentDate)/1000) +"s at "+ shutdownTime.toLocaleString(); 110 if(shutdownTime == -1){ 111 shutdownHint = "Failed to initiate shutdown!"; 112 } 113 $("#shutdownMessage").text(shutdownHint); 114 }); 115 } 116 104 117 $(document).ready(function() { 105 118 displayDataGet(); … … 107 120 108 121 $.getJSON("../webservice/tileserver.php?/map.json", mapSetup); 122 123 $("#shutdownButton").click(shutdown); 109 124 }); -
src/webapp/webclient/root/index.php
ra250eb4 r5519ced 100 100 </div> 101 101 </form> 102 <div id="shutdown"> 103 <p id="shutdownMessage"/> 104 <form> 105 <button type="button" id="shutdownButton">SHUTDOWN</button> 106 </form> 107 </div> 102 108 <?php 103 109 require_once("inc/footer.php"); -
src/webapp/webservice/index.php
ra250eb4 r5519ced 21 21 $dbFile = $config->databaseFile(); 22 22 23 define("REQUEST_DATA", "data"); 24 define("REQUEST_SHUTDOWN", "shutdown"); 25 26 23 27 // configure roundings per value (key) and precision (value) 24 28 $configRound = array … … 36 40 $debug = $_GET["debug"]; 37 41 42 $request = REQUEST_DATA; 43 if(array_key_exists("request", $_GET)){ 44 $request = $_GET["request"]; 45 } 46 38 47 if($debug == 0) 39 48 header('Content-Type: application/json'); 40 49 41 $result["lastvalid"] = array(); 42 $result["track"] = array(); 50 $result = array(); 51 if($request == REQUEST_SHUTDOWN){ 52 $handle = @fopen("/var/spool/gnuboat/gnuboat_shutdown", "w"); 53 if($handle === false){ 54 $message = "Could not create file to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")"; 55 if($debug > 0) 56 echo $message; 57 error_log($message); 58 $result["shutdownstart"] = -1; 59 $shutdownTime = new DateTime('NOW'); 60 $shutdownTime->modify("+60 seconds"); 61 $result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601); 62 } 63 else{ 64 $shutdownTime = new DateTime('NOW'); 65 $shutdownTime>modify("+15 seconds"); 66 fwrite($handle, $shutdownTime->format(DateTime::ISO8601)); 67 $result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601); 68 } 69 } 70 elseif($request == REQUEST_DATA){ 71 $result["lastvalid"] = array(); 72 $result["track"] = array(); 43 73 44 // Fetch entries of the last 12hours 45 $data = rrd_fetch($dbFile, array( "AVERAGE", "--start", "-12h")); 46 if($data === false){ 47 echo json_encode($result); 48 $message = "Could not open rrd database ". $dbFile; 49 if($debug > 0) 50 echo $message; 51 else 52 error_log($message); 53 exit; 54 } 74 if(!file_exists($dbFile)){ 75 echo json_encode(""); 76 if($debug > 0) 77 echo "Database file ". $dbFile ." does not exist!"; 78 error_log("Database file ". $dbFile ." does not exist"); 79 exit; 80 } 81 // Fetch entries of the last 12hours 82 $data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", "5", "--start", "-12h")); 83 if($data === false){ 84 echo json_encode($result); 85 $message = "Could not open rrd database ". $dbFile; 86 if($debug > 0) 87 echo $message; 88 else 89 error_log($message); 90 exit; 91 } 55 92 56 if($debug > 2){57 echo "<pre>";58 var_dump($data);59 echo "</pre>";60 }93 if($debug > 2){ 94 echo "<pre>"; 95 var_dump($data); 96 echo "</pre>"; 97 } 61 98 62 $data = $data["data"];99 $data = $data["data"]; 63 100 64 // transform them into json format 65 $i = 0; 66 $lastTime = -1; 67 $keys = array_keys($data); 68 if(count($keys) < 0 ){ 69 error_log("No keys in fetched rrd data from ". $dbFile); 70 echo json_encode(""); 71 exit; 72 } 73 for($i = 0; $i < count($data[$keys[0]]); $i++){ 74 $time = array_keys($data[$keys[0]])[$i]; 75 $allValid = true; 76 $tmp = array(); 77 foreach($keys as $key){ 78 if($key == "gpsfix"){ 79 switch($data[$key][$time]){ 80 case 1: 81 $tmp[$key] = "2D"; 82 break; 83 case 2: 84 $tmp[$key] = "3D"; 85 break; 86 default: 87 $tmp[$key] = "-"; 101 // transform them into json format 102 $i = 0; 103 $lastTime = -1; 104 $keys = array_keys($data); 105 if(count($keys) < 0 ){ 106 error_log("No keys in fetched rrd data from ". $dbFile); 107 echo json_encode(""); 108 exit; 109 } 110 for($i = 0; $i < count($data[$keys[0]]); $i++){ 111 $time = array_keys($data[$keys[0]])[$i]; 112 $allValid = true; 113 $tmp = array(); 114 foreach($keys as $key){ 115 if($key == "gpsfix"){ 116 switch($data[$key][$time]){ 117 case 1: 118 $tmp[$key] = "2D"; 119 break; 120 case 2: 121 $tmp[$key] = "3D"; 122 break; 123 default: 124 $tmp[$key] = "-"; 125 } 126 } 127 else{ 128 $tmp[$key] = $data[$key][$time]; 129 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 130 $allValid = false; 131 } 132 elseif(array_key_exists($key, $configRound) && is_integer($configRound[$key])) 133 $tmp[$key] = round($tmp[$key], $configRound[$key]); 88 134 } 89 135 } 136 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 137 if($allValid && $tmp["gpsfix"] != "-"){ 138 $result["track"][$time] = $tmp; 139 $lastTime = $time; 140 } 90 141 else{ 91 $tmp[$key] = $data[$key][$time]; 92 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 93 $allValid = false; 142 if($debug > 0){ 143 echo "Failed <pre>"; 144 var_dump($tmp); 145 echo "</pre>\n"; 94 146 } 95 elseif(array_key_exists($key, $configRound) && is_integer($configRound[$key]))96 $tmp[$key] = round($tmp[$key], $configRound[$key]);97 147 } 98 148 } 99 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 100 if($allValid && $tmp["gpsfix"] != "-"){ 101 $result["track"][$time] = $tmp; 102 $lastTime = $time; 149 if($lastTime > -1){ 150 $result["lastvalid"] = $result["track"][$lastTime]; 103 151 } 104 else{105 if($debug > 0){106 echo "Failed <pre>";107 var_dump($tmp);108 echo "</pre>\n";109 }110 }111 }112 if($lastTime > -1){113 $result["lastvalid"] = $result["track"][$lastTime];114 152 } 115 153
Note:
See TracChangeset
for help on using the changeset viewer.
