Ignore:
Timestamp:
01/02/16 12:27:19 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Prepared the ACARS and PIREP objects for serialization (re #283).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/pirep.py

    r437 r743  
    44import const
    55import cPickle as pickle
     6import datetime
     7import time
    68
    79#------------------------------------------------------------------------------
     
    1921class PIREP(object):
    2022    """A pilot's report of a flight."""
     23    _flightTypes = { const.FLIGHTTYPE_SCHEDULED : "SCHEDULED",
     24                     const.FLIGHTTYPE_OLDTIMER : "OT",
     25                     const.FLIGHTTYPE_VIP : "VIP",
     26                     const.FLIGHTTYPE_CHARTER : "CHARTER" }
     27
    2128    @staticmethod
    2229    def _formatLine(timeStr, line):
     
    2431        some other things."""
    2532        return "[" + timeStr + "]-[" + line + "]"
     33
     34    @staticmethod
     35    def formatTimestampForRPC(t):
     36        """Format the given timestamp for RPC."""
     37        return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t))
    2638
    2739    @staticmethod
     
    91103        self.faultLineIndexes = logger.faultLineIndexes
    92104
     105    @property
     106    def flightTypeText(self):
     107        """Get the text representation of the flight type."""
     108        return PIREP._flightTypes[self.flightType]
     109
     110    @property
     111    def blockTimeStartText(self):
     112        """Get the beginning of the block time in string format."""
     113        return PIREP.formatTimestampForRPC(self.blockTimeStart)
     114
     115    @property
     116    def flightTimeStartText(self):
     117        """Get the beginning of the flight time in string format."""
     118        return PIREP.formatTimestampForRPC(self.flightTimeStart)
     119
     120    @property
     121    def flightTimeEndText(self):
     122        """Get the end of the flight time in string format."""
     123        return PIREP.formatTimestampForRPC(self.flightTimeEnd)
     124
     125    @property
     126    def blockTimeEndText(self):
     127        """Get the end of the block time in string format."""
     128        return PIREP.formatTimestampForRPC(self.blockTimeEnd)
     129
    93130    def getACARSText(self):
    94131        """Get the ACARS text.
     
    152189            print u"Failed saving PIREP to %s: %s" % (path, error)
    153190            return error
     191
     192    def _serialize(self):
     193        """Serialize the PIREP for JSON-RPC."""
     194        attrs = {}
     195        attrs["log"] = self.getACARSText()
     196        attrs["numPassengers"] = self.numPassengers
     197        attrs["numCrew"] = self.numCrew
     198        attrs["cargoWeight"] = self.cargoWeight
     199        attrs["bagWeight"] = self.bagWeight
     200        attrs["mailWeight"] = self.mailWeight
     201        attrs["flightType"] = self.flightTypeText
     202        attrs["online"] = 1 if self.online else 0
     203        attrs["blockTimeStart"] = self.blockTimeStartText
     204        attrs["blockTimeEnd"] = self.blockTimeEndText
     205        attrs["flightTimeStart"] = self.flightTimeStartText
     206        attrs["flightTimeEnd"] = self.flightTimeEndText
     207        attrs["timeComment"] = self.getTimeComment()
     208        attrs["fuelUsed"] = self.fuelUsed
     209        attrs["departureRunway"] = self.departureRunway
     210        attrs["arrivalRunway"] = self.arrivalRunway
     211        attrs["departureMETAR"] = self.departureMETAR
     212        attrs["arrivalMETAR"] = self.arrivalMETAR
     213        attrs["filedCruiseLevel"] = self.filedCruiseAltitude / 100.0
     214        attrs["cruiseLevel"] = self.cruiseAltitude / 100.0
     215        attrs["sid"] = self.sid
     216        attrs["route"] = self.route
     217        attrs["star"] = self.star
     218        attrs["approachType"] = self.approachType
     219        attrs["comments"] = self.comments
     220        attrs["flightDefects"] = self.flightDefects
     221        attrs["ratingText"] = self.getRatingText()
     222        attrs["rating"] = max(0.0, self.rating)
     223        attrs["flownDistance"] = self.flownDistance
     224        # FIXME: it should be stored in the PIREP when it is sent later
     225        attrs["flightDate"] = datetime.date.today().strftime("%Y-%m-%d")
     226
     227        return ([], attrs)
Note: See TracChangeset for help on using the changeset viewer.