Changeset 829:0c8f22f0667a
- Timestamp:
- 12/30/16 15:37:51 (8 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/pirep.py
r778 r829 1 1 2 2 from util import utf2unicode 3 from flight import Flight 3 4 4 5 import const 5 6 import cPickle as pickle 7 import calendar 6 8 import datetime 7 9 import time … … 36 38 """Format the given timestamp for RPC.""" 37 39 return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t)) 40 41 @staticmethod 42 def parseTimestampFromRPC(s): 43 """Format the given timestamp for RPC.""" 44 dt = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") 45 return calendar.timegm(dt.utctimetuple()) 46 47 @staticmethod 48 def decodeFlightTypeText(s): 49 """Decode the given flight type text.""" 50 for (flighType, text) in PIREP._flightTypes.iteritems(): 51 if s==text: 52 return flighType 53 return const.FLIGHTYPE_SCHEDULED 54 55 @staticmethod 56 def parseLogFromRPC(log): 57 """Parse the given log coming from the RPC.""" 58 index = 0 59 entries = [] 60 61 inTimeStr = False 62 inEntry = False 63 64 timestr = "" 65 entry = "" 66 67 while index<len(log): 68 c = log[index] 69 index += 1 70 71 if c==']': 72 if inEntry: 73 entries.append((timestr, entry)) 74 timestr = "" 75 entry = "" 76 77 inTimeStr = False 78 inEntry = False 79 elif not inTimeStr and not inEntry: 80 if c=='[': 81 if timestr: 82 inEntry = True 83 else: 84 inTimeStr = True 85 elif inTimeStr: 86 timestr += c 87 elif inEntry: 88 entry += c 89 90 return entries 38 91 39 92 @staticmethod … … 61 114 def __init__(self, flight): 62 115 """Initialize the PIREP from the given flight.""" 116 if flight is None: 117 return 118 63 119 self.bookedFlight = flight.bookedFlight 64 120 … … 102 158 self.logLines = logger.lines 103 159 self.faultLineIndexes = logger.faultLineIndexes 160 161 def setupFromPIREPData(self, pirepData, bookedFlight): 162 163 self.bookedFlight = bookedFlight 164 165 self.numCrew = int(pirepData["numCrew"]) 166 self.numPassengers = int(pirepData["numPassengers"]) 167 self.bagWeight = int(pirepData["bagWeight"]) 168 self.cargoWeight = int(pirepData["cargoWeight"]) 169 self.mailWeight = int(pirepData["mailWeight"]) 170 171 self.filedCruiseAltitude = int(pirepData["filedCruiseLevel"][2:])*100 172 cruiseLevel = pirepData["cruiseLevel"] 173 if cruiseLevel: 174 self.cruiseAltitude = int(cruiseLevel[2:])*100 175 else: 176 self.cruiseAltitude = self.filedCruiseAltitude 177 self.route = pirepData["route"] 178 179 self.departureMETAR = pirepData["departureMETAR"] 180 self.arrivalMETAR = pirepData["arrivalMETAR"] 181 182 self.departureRunway = pirepData["departureRunway"] 183 self.sid = pirepData["sid"] 184 185 star = pirepData["star"].split(",") 186 self.star = star[0] 187 self.star.strip() 188 189 if len(star)>1: 190 self.transition = star[1] 191 self.transition.strip() 192 else: 193 self.transition = "" 194 self.approachType = pirepData["approachType"] 195 self.arrivalRunway = pirepData["arrivalRunway"] 196 197 self.flightType = PIREP.decodeFlightTypeText(pirepData["flightType"]) 198 self.online = int(pirepData["online"])!=0 199 200 self.comments = pirepData["comments"] 201 self.flightDefects = pirepData["flightDefects"] 202 self.delayCodes = pirepData["timeComment"] 203 if self.delayCodes=="UTC": 204 self.delayCodes = "" 205 206 flightDate = pirepData["flightDate"] + " " 207 208 self.blockTimeStart = \ 209 PIREP.parseTimestampFromRPC(flightDate + pirepData["blockTimeStart"]) 210 self.flightTimeStart = \ 211 PIREP.parseTimestampFromRPC(flightDate + pirepData["flightTimeStart"]) 212 self.flightTimeEnd = \ 213 PIREP.parseTimestampFromRPC(flightDate + pirepData["flightTimeEnd"]) 214 self.blockTimeEnd = \ 215 PIREP.parseTimestampFromRPC(flightDate + pirepData["blockTimeEnd"]) 216 self.flownDistance = float(pirepData["flownDistance"]) 217 self.fuelUsed = float(pirepData["fuelUsed"]) 218 219 # logger = flight.logger 220 self.rating = float(pirepData["rating"]) 221 222 log = pirepData["log"] 223 224 self.logLines = PIREP.parseLogFromRPC(log)[1:] 225 if self.logLines and \ 226 (self.logLines[0][0]=="LOGGER NG LOG" or 227 self.logLines[0][0]=="MAVA LOGGER X"): 228 self.logLines = self.logLines[1:] 229 numLogLines = len(self.logLines) 230 231 lastFaultLineIndex = 0 232 self.faultLineIndexes = [] 233 for ratingText in pirepData["ratingText"].splitlines()[:-1]: 234 faultLines = PIREP.parseLogFromRPC(ratingText) 235 for (timeStr, entry) in faultLines: 236 for i in range(lastFaultLineIndex, numLogLines-1): 237 if timeStr>=self.logLines[i][0] and \ 238 timeStr<self.logLines[i+1][0]: 239 self.logLines = self.logLines[:i+1] + \ 240 [(timeStr, entry)] + self.logLines[i+1:] 241 self.faultLineIndexes.append(i+1) 242 lastFaultLineIndex = i+1 243 numLogLines += 1 244 break 104 245 105 246 @property -
src/mlx/rpc.py
r824 r829 340 340 self._server.setCheckFlightPassed(sessionID, type)) 341 341 342 def getPIREP(self, flightID): 343 """Get the PIREP data for the flight with the given ID.""" 344 value = self._performCall(lambda sessionID: 345 self._server.getPIREP(sessionID, flightID)) 346 return value 347 342 348 def reflyFlights(self, flightIDs): 343 349 """Mark the flights with the given IDs for reflying.""" -
src/mlx/web.py
r824 r829 7 7 8 8 from common import MAVA_BASE_URL 9 from pirep import PIREP 9 10 10 11 import threading … … 257 258 self.aircraftTypeName = \ 258 259 BookedFlight.TYPE2TYPECODE[self.aircraftType] 260 261 def setupFromPIREPData(self, pirepData): 262 """Setup the booked flight from the given PIREP data.""" 263 bookedFlightData = pirepData["bookedFlight"] 264 265 self.callsign = bookedFlightData["callsign"] 266 267 date = bookedFlightData["date"] 268 269 departureTime = bookedFlightData["departureTime"] 270 self.departureTime = BookedFlight.getDateTime(date, departureTime) 271 272 arrivalTime = bookedFlightData["arrivalTime"] 273 self.arrivalTime = BookedFlight.getDateTime(date, arrivalTime) 274 if self.arrivalTime<self.departureTime: 275 self.arrivalTime += datetime.timedelta(days = 1) 276 277 self.departureICAO = bookedFlightData["departureICAO"] 278 self.arrivalICAO = bookedFlightData["arrivalICAO"] 279 280 self.aircraftType = \ 281 self._decodeAircraftType(bookedFlightData["aircraftType"]) 282 self.tailNumber = bookedFlightData["tailNumber"] 283 self.numPassengers = int(bookedFlightData["numPassengers"]) 284 self.numCrew = int(bookedFlightData["numCrew"]) 285 self.bagWeight = int(bookedFlightData["bagWeight"]) 286 self.cargoWeight = int(bookedFlightData["cargoWeight"]) 287 self.mailWeight = int(bookedFlightData["mailWeight"]) 288 self.route = bookedFlightData["route"] 259 289 260 290 def writeIntoFile(self, f): … … 1242 1272 #------------------------------------------------------------------------------ 1243 1273 1274 class GetPIREP(RPCRequest): 1275 """A request to retrieve the PIREP of a certain flight.""" 1276 def __init__(self, client, callback, flightID): 1277 """Construct the request.""" 1278 super(GetPIREP, self).__init__(client, callback) 1279 self._flightID = flightID 1280 1281 def run(self): 1282 """Perform the update.""" 1283 result = Result() 1284 1285 pirepData = self._client.getPIREP(self._flightID) 1286 print "pirepData:", pirepData 1287 1288 bookedFlight = BookedFlight() 1289 bookedFlight.setupFromPIREPData(pirepData) 1290 1291 result.pirep = PIREP(None) 1292 result.pirep.setupFromPIREPData(pirepData, bookedFlight) 1293 1294 return result 1295 1296 #------------------------------------------------------------------------------ 1297 1244 1298 class ReflyFlights(RPCRequest): 1245 1299 """A request to mark certain flights for reflying.""" … … 1351 1405 callback, aircraftType)) 1352 1406 1407 def getPIREP(self, callback, flightID): 1408 """Query the PIREP for the given flight.""" 1409 self._addRequest(GetPIREP(self._rpcClient, callback, flightID)) 1410 1353 1411 def reflyFlights(self, callback, flightIDs): 1354 1412 """Mark the flights with the given IDs for reflying."""
Note:
See TracChangeset
for help on using the changeset viewer.