Ver código fonte

add the function to request the configuration

Sven Czarnian 3 anos atrás
pai
commit
f7b8f26e48
1 arquivos alterados com 53 adições e 2 exclusões
  1. 53 2
      aman/com/WebUI.py

+ 53 - 2
aman/com/WebUI.py

@@ -9,6 +9,8 @@ from requests.adapters import HTTPAdapter
 from requests.packages.urllib3.util.retry import Retry
 from requests.structures import CaseInsensitiveDict
 
+from aman.config.AirportSequencing import AirportSequencing
+from aman.config.RunwaySequencing import RunwaySequencing
 from aman.config.Server import Server
 
 class InboundEncoder(JSONEncoder):
@@ -43,8 +45,57 @@ class WebUI:
         session.mount('https://', adapter)
         return session
 
-    def requestConfiguration(self, airport):
-        return
+    def requestConfiguration(self, airport, navData):
+        if airport not in navData.Runways:
+            return None
+
+        # prepare the HTTP header and session
+        headers = CaseInsensitiveDict()
+        headers['Accept'] = 'application/json'
+        headers['Content-Type'] = 'application/json'
+        session = WebUI.createSession()
+
+        url = self.Config.WebUiUrl + self.Config.WebUiConfigurationReceiver
+        data = json.dumps({ 'airport': airport }, ensure_ascii=True)
+
+        try:
+            response = session.get(url, headers=headers, data=data, timeout=2)
+            if 200 != response.status_code:
+                return None
+        except requests.exceptions.ConnectTimeout:
+            return None
+
+        config = json.loads(response.json())
+
+        # WebUI sent the wrong airport
+        if config['airport'] != airport or 0 == len(config['activeRunways']):
+            return None
+
+        airportConfig = AirportSequencing(airport)
+        airportConfig.UseMustShallMay = config['useMustShallMay']
+
+        # build the sequencing information per runway
+        for activeRunway in config['activeRunways']:
+            gngRunway = None
+            for runway in navData.Runways[airport]:
+                if runway.Name == activeRunway['runway']:
+                    gngRunway = runway
+                    break
+
+            # could not find the runway
+            if None == gngRunway:
+                return None
+
+            runway = RunwaySequencing(gngRunway)
+            runway.Spacing = int(activeRunway['spacing'])
+            airportConfig.activateRunway(runway)
+
+        # resolve the dependencies
+        for dependency in config['dependentRunways']:
+            if 2 == len(dependency):
+                airportConfig.addDependency(dependency[0], dependency[1])
+
+        return airportConfig
 
     def sendSequence(self, airport, inbounds):
         # prepare the HTTP header and session