from util import utf2unicode from flight import Flight import const import cPickle as pickle import calendar import datetime import time #------------------------------------------------------------------------------ ## @package mlx.pirep # # The PIREP module. # # This module defines only one class, \ref PIREP. It is used to extract and # store the information needed for a PIREP. The saved PIREPs are pickled # instances of this class. #------------------------------------------------------------------------------ class PIREP(object): """A pilot's report of a flight.""" _flightTypes = { const.FLIGHTTYPE_SCHEDULED : "SCHEDULED", const.FLIGHTTYPE_OLDTIMER : "OT", const.FLIGHTTYPE_VIP : "VIP", const.FLIGHTTYPE_CHARTER : "CHARTER" } @staticmethod def _formatLine(timeStr, line): """Format the given time string and line as needed for the ACARS and some other things.""" return "[" + timeStr + "]-[" + line + "]" @staticmethod def formatTimestampForRPC(t): """Format the given timestamp for RPC.""" return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t)) @staticmethod def parseTimestampFromRPC(s): """Format the given timestamp for RPC.""" dt = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") return calendar.timegm(dt.utctimetuple()) @staticmethod def decodeFlightTypeText(s): """Decode the given flight type text.""" for (flighType, text) in PIREP._flightTypes.iteritems(): if s==text: return flighType return const.FLIGHTYPE_SCHEDULED @staticmethod def parseLogFromRPC(log): """Parse the given log coming from the RPC.""" index = 0 entries = [] inTimeStr = False inEntry = False timestr = "" entry = "" while index1: self.transition = star[1] self.transition.strip() else: self.transition = "" self.approachType = pirepData["approachType"] self.arrivalRunway = pirepData["arrivalRunway"] self.flightType = PIREP.decodeFlightTypeText(pirepData["flightType"]) self.online = int(pirepData["online"])!=0 self.comments = pirepData["comments"] self.flightDefects = pirepData["flightDefects"] self.delayCodes = pirepData["timeComment"] if self.delayCodes=="UTC": self.delayCodes = "" flightDate = pirepData["flightDate"] + " " self.blockTimeStart = \ PIREP.parseTimestampFromRPC(flightDate + pirepData["blockTimeStart"]) self.flightTimeStart = \ PIREP.parseTimestampFromRPC(flightDate + pirepData["flightTimeStart"]) self.flightTimeEnd = \ PIREP.parseTimestampFromRPC(flightDate + pirepData["flightTimeEnd"]) self.blockTimeEnd = \ PIREP.parseTimestampFromRPC(flightDate + pirepData["blockTimeEnd"]) self.flownDistance = float(pirepData["flownDistance"]) self.fuelUsed = float(pirepData["fuelUsed"]) # logger = flight.logger self.rating = float(pirepData["rating"]) log = pirepData["log"] self.logLines = PIREP.parseLogFromRPC(log)[1:] if self.logLines and \ (self.logLines[0][0]=="LOGGER NG LOG" or self.logLines[0][0]=="MAVA LOGGER X"): self.logLines = self.logLines[1:] numLogLines = len(self.logLines) lastFaultLineIndex = 0 self.faultLineIndexes = [] for ratingText in pirepData["ratingText"].splitlines()[:-1]: faultLines = PIREP.parseLogFromRPC(ratingText) for (timeStr, entry) in faultLines: for i in range(lastFaultLineIndex, numLogLines-1): if timeStr>=self.logLines[i][0] and \ timeStr