Changeset 743:6bc880ac41eb


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).

Location:
src/mlx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acars.py

    r736 r743  
    4949            return "Landed"
    5050
     51    def _serialize(self):
     52        """Serialize the ACARS object for JSON-RPC."""
     53        bookedFlight = self.bookedFlight
     54        state = self.state
     55
     56        attrs = {}
     57        attrs["longitude"] = state.longitude
     58        attrs["latitude"] = state.latitude
     59        attrs["pilotName"] = self.pilotName
     60        attrs["numPassengers"] = bookedFlight.numPassengers
     61        attrs["blockTime"] = self.getBlockTimeText()
     62        attrs["callsign"] = bookedFlight.callsign
     63        attrs["aircraftTypeName"] = bookedFlight.aircraftTypeName
     64        attrs["departureICAO"] = bookedFlight.departureICAO
     65        attrs["arrivalICAO"] = bookedFlight.arrivalICAO
     66        attrs["altitude"] = state.altitude
     67        attrs["groundSpeed"] = state.groundSpeed
     68        attrs["event"] = self.getEventText()
     69        attrs["tailNumber"] = bookedFlight.tailNumber
     70
     71        return ([], attrs)
    5172
    5273#------------------------------------------------------------------------------
  • 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)
  • src/mlx/web.py

    r742 r743  
    844844class SendPIREP(Request):
    845845    """A request to send a PIREP to the MAVA website."""
    846     _flightTypes = { const.FLIGHTTYPE_SCHEDULED : "SCHEDULED",
    847                      const.FLIGHTTYPE_OLDTIMER : "OT",
    848                      const.FLIGHTTYPE_VIP : "VIP",
    849                      const.FLIGHTTYPE_CHARTER : "CHARTER" }
    850 
    851846    _latin2Encoder = codecs.getencoder("iso-8859-2")
    852847
     
    877872        data["mail"] = str(pirep.mailWeight)
    878873
    879         data["flttype"] = SendPIREP._flightTypes[pirep.flightType]
     874        data["flttype"] = pirep.flightTypeText
    880875        data["onoff"] = "1" if pirep.online else "0"
    881876        data["bt_dep"] = util.getTimestampString(pirep.blockTimeStart)
Note: See TracChangeset for help on using the changeset viewer.