Ignore:
Timestamp:
04/17/12 18:00:09 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added the collection of some further statistics and the finish page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/flight.py

    r86 r89  
    44
    55import const
     6import util
    67
    78import threading
     
    3940        self.aircraft = None
    4041        self.simulator = None
     42
     43        self.blockTimeStart = None
     44        self.flightTimeStart = None
     45        self.flightTimeEnd = None
     46        self.blockTimeEnd = None
     47
     48        self._lastDistanceTime = None
     49        self._previousLatitude = None
     50        self._previousLongitude = None
     51        self.flownDistance = 0.0
     52
     53        self.startFuel = None
     54        self.endFuel = None
    4155
    4256        self._endCondition = threading.Condition()
     
    8094        return self._gui.vref
    8195
     96    def handleState(self, oldState, currentState):
     97        """Handle a new state information."""
     98        self._updateFlownDistance(currentState)
     99       
     100        self.endFuel = sum(currentState.fuel)
     101        if self.startFuel is None:
     102            self.startFuel = self.endFuel
     103
    82104    def setStage(self, timestamp, stage):
    83105        """Set the flight stage.
     
    88110            self._gui.setStage(stage)
    89111            self.logger.stage(timestamp, stage)
    90             if stage==const.STAGE_END:
     112            if stage==const.STAGE_PUSHANDTAXI:
     113                self.blockTimeStart = timestamp
     114            elif stage==const.STAGE_TAKEOFF:
     115                self.flightTimeStart = timestamp
     116            elif stage==const.STAGE_TAXIAFTERLAND:
     117                self.flightTimeEnd = timestamp
     118            elif stage==const.STAGE_PARKING:
     119                self.blockTimeEnd = timestamp
     120            elif stage==const.STAGE_END:
    91121                with self._endCondition:
    92122                    self._endCondition.notify()
     
    133163                self._endCondition.wait(1)
    134164
     165    def _updateFlownDistance(self, currentState):
     166        """Update the flown distance."""
     167        if not currentState.onTheGround:
     168            updateData = False
     169            if self._lastDistanceTime is None or \
     170               self._previousLatitude is None or \
     171               self._previousLongitude is None:
     172                updateData = True
     173            elif currentState.timestamp >= (self._lastDistanceTime + 30.0):
     174                updateData = True
     175                self.flownDistance += self._getDistance(currentState)
     176
     177            if updateData:
     178                self._previousLatitude = currentState.latitude
     179                self._previousLongitude = currentState.longitude
     180                self._lastDistanceTime = currentState.timestamp
     181        else:
     182            if self._lastDistanceTime is not None and \
     183               self._previousLatitude is not None and \
     184               self._previousLongitude is not None:
     185                self.flownDistance += self._getDistance(currentState)
     186               
     187            self._lastDistanceTime = None
     188
     189    def _getDistance(self, currentState):
     190        """Get the distance between the previous and the current state."""
     191        return util.getDistCourse(self._previousLatitude, self._previousLongitude,
     192                                  currentState.latitude, currentState.longitude)[0]
     193
    135194#---------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.