Ignore:
Timestamp:
05/21/17 15:21:55 (7 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

The accepted flights can be queried and viewed (re #307)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/rpc.py

    r853 r854  
    77import hashlib
    88import datetime
     9import calendar
     10import sys
    911
    1012#---------------------------------------------------------------------------------------
     
    3234                    continue
    3335
    34                 value = instruction(value)
     36                try:
     37                    value = instruction(value)
     38                except:
     39                    print >> sys.stderr, "Failed to convert value '%s' of attribute '%s':" % \
     40                        (value, key)
     41                    import traceback
     42                    traceback.print_exc()
    3543            setattr(self, key, value)
    3644
     
    131139#---------------------------------------------------------------------------------------
    132140
     141class AcceptedFlight(RPCObject):
     142    """A flight that has been already accepted."""
     143    # The instructions for the construction
     144    @staticmethod
     145    def parseTimestamp(s):
     146        """Parse the given RPC timestamp."""
     147        dt = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S")
     148        return calendar.timegm(dt.utctimetuple())
     149
     150    _instructions = {
     151        "bookedFlight" : lambda value: BookedFlight(value),
     152        "numPassengers" : int,
     153        "fuelUsed" : int,
     154        "rating" : lambda value: float(value) if value else 0.0
     155        }
     156
     157    def __init__(self, value):
     158        """Construct the booked flight object from the given RPC result
     159        value."""
     160        super(AcceptedFlight, self).__init__(value, AcceptedFlight._instructions)
     161        self.flightTimeStart = \
     162          AcceptedFlight.parseTimestamp(self.flightDate + " " +
     163                                        self.flightTimeStart)
     164        self.flightTimeEnd = \
     165          AcceptedFlight.parseTimestamp(self.flightDate + " " +
     166                                        self.flightTimeEnd)
     167        if self.flightTimeEnd<self.flightTimeStart:
     168            self.flightTimeEnd += 24*60*60
     169
     170#---------------------------------------------------------------------------------------
     171
    133172class Plane(rpccommon.Plane, RPCObject):
    134173    """An airplane in the fleet."""
     
    299338        return (bookedFlights, reportedFlights, rejectedFlights)
    300339
     340    def getAcceptedFlights(self):
     341        """Get the flights that are already accepted."""
     342        value = self._performCall(lambda sessionID:
     343                                  self._server.getAcceptedFlights(sessionID))
     344        flights = []
     345        for flight in value:
     346            flights.append(AcceptedFlight(flight))
     347        return flights
     348
    301349    def getEntryExamStatus(self):
    302350        """Get the status of the exams needed for joining MAVA."""
Note: See TracChangeset for help on using the changeset viewer.