Ignore:
Timestamp:
02/22/14 09:50:09 (10 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The flight type is also considered when checking the arrival and departure times (re #227)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/flight.py

    r430 r564  
    55import const
    66import util
     7import time
    78
    89import threading
     
    2425    It is also the hub for the other main objects participating in the handling of
    2526    the flight."""
     27
     28    # The difference in minutes from the schedule which is considered a bit big
     29    TIME_WARNING_DIFFERENCE = 5
     30
     31    # The difference in minutes from the schedule which is considered too big
     32    TIME_ERROR_DIFFERENCE = 15
     33
    2634    @staticmethod
    2735    def canLogCruiseAltitude(stage):
     
    3038        return stage in [const.STAGE_CRUISE, const.STAGE_DESCENT,
    3139                         const.STAGE_LANDING]
     40
     41    @staticmethod
     42    def isTimeDifferenceTooMuch(scheduledTime, realTimestamp):
     43        """Determine if the given real time differs to much from the scheduled
     44        time.
     45
     46        Returns a tuple of:
     47        - a boolean indicating if the difference is enough to warrant at least
     48          a warning
     49        - a boolean indicating if the difference is too big, i. e. unacceptable
     50          without explanation."""
     51        realTime = time.gmtime(realTimestamp)
     52
     53        scheduledMinute = scheduledTime.hour * 60 + scheduledTime.minute
     54        realMinute = realTime.tm_hour * 60 + realTime.tm_min
     55
     56        diff1 = scheduledMinute - realMinute
     57        diff2 = -1 * diff1
     58
     59        if diff1 < 0: diff1 += 60*24
     60        else: diff2 += 60*24
     61
     62        diff = min(diff1, diff2)
     63
     64        return (diff>Flight.TIME_WARNING_DIFFERENCE,
     65                diff>Flight.TIME_ERROR_DIFFERENCE)
    3266
    3367    def __init__(self, logger, gui):
     
    283317        """Get the RTO state."""
    284318        return self._rtoState
     319
     320    @property
     321    def blockTimeStartWrong(self):
     322        """Determine if the block time start is wrong compared to the scheduled
     323        departure time.
     324
     325        Returns a tuple of:
     326        - a boolean indicating if the difference warrants a warning
     327        - a boolean indicating if the difference warrants not only a warning,
     328          but an error as well."""
     329        return self.isTimeDifferenceTooMuch(self.bookedFlight.departureTime,
     330                                            self.blockTimeStart)
     331
     332    @property
     333    def blockTimeEndWrong(self):
     334        """Determine if the block time end is wrong compared to the scheduled
     335        arrival time.
     336
     337        Returns a tuple of:
     338        - a boolean indicating if the difference warrants a warning
     339        - a boolean indicating if the difference warrants not only a warning,
     340          but an error as well."""
     341        return self.isTimeDifferenceTooMuch(self.bookedFlight.arrivalTime,
     342                                            self.blockTimeEnd)
    285343
    286344    def handleState(self, oldState, currentState):
Note: See TracChangeset for help on using the changeset viewer.