Ignore:
Timestamp:
05/29/13 17:59:20 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Children:
513:0884206a9344, 514:8c53fc09c941
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Implemented the new derate handling method (re #202)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r447 r512  
    3232#---------------------------------------------------------------------------------------
    3333
     34# Derate type: no derate possible
     35DERATE_NONE = 0
     36
     37# Derate type: Boeing, i.e. a percentage value.
     38# For logging, the percentage value is expected as a string (i.e. whatever the
     39# pilot enters into the text field).
     40DERATE_BOEING = 1
     41
     42# Derate type: EPR, i.e. an EPR value.
     43# For logging, the EPR value is expected as a string (i.e. whatever the pilot
     44# enters into the text field).
     45DERATE_EPR = 2
     46
     47# Derate type: Tupolev, i.e. nominal or takeoff
     48# For logging, one of the DERATE_TUPOLEV_xxx values are expected.
     49DERATE_TUPOLEV = 3
     50
     51# Tupolev derate value: nominal
     52DERATE_TUPOLEV_NOMINAL = 1
     53
     54# Tupolev derate value: takeoff
     55DERATE_TUPOLEV_TAKEOFF = 2
     56
     57# Derate type: BAe-146, i.e. enabled or not
     58# For logging, a boolean is expected.
     59DERATE_B462 = 4
     60
     61#---------------------------------------------------------------------------------------
     62
    3463class SmoothedValue(object):
    3564    """A smoothed value."""
     
    203232
    204233    @property
    205     def derateLabels(self):
    206         """Get the strings related to the derate entry.
    207 
    208         It returns a tuple of two items:
    209         - the label before the entry field,
    210         - the label after the entry field, which can be None.
    211 
    212         If both labels are None, the derate value will not be logged or
    213         queried. This is the default."""
    214         return (None, None)
    215 
    216     @property
    217     def derateTemplate(self):
    218         """Get the template for logging the derate value.
    219 
    220         If it returns None (which is the default), no derate value will be
    221         logged."""
     234    def derateType(self):
     235        """Get the derate type for this aircraft.
     236
     237        This default implementation returns DERATE_NONE."""
     238        return DERATE_NONE
     239
     240    def getDerateLine(self, value):
     241        """Get the log line for the given derate value.
     242
     243        It uses the the derate type and produces the standard message for
     244        each. This children need not override it, although they can."""
     245        dt = self.derateType
     246
     247        if dt==DERATE_BOEING:
     248            return "Derate calculated by the pilot: %s %%" % \
     249              ("-" if value is None else value,)
     250        elif dt==DERATE_EPR:
     251            return "EPR calculated by the pilot: %s" % \
     252              ("-" if value is None else value,)
     253        elif dt==DERATE_TUPOLEV:
     254            return "Thrust setting calculated by the pilot: %s" % \
     255              ("-" if value is None else
     256               "nominal" if value==DERATE_TUPOLEV_NOMINAL else "takeoff",)
     257        elif dt==DERATE_B462:
     258            return "Derate setting: %s" % \
     259              ("-" if value is None else "enabled" if value else "disabled",)
     260        elif dt!=DERATE_NONE:
     261            print "mlx.acft.getDerateLine: invalid derate type: " + dt
     262
    222263        return None
    223264
     
    472513        """Log the derate values either newly or by updating the corresponding
    473514        line."""
    474         derateTemplate = self.derateTemplate
    475         if derateTemplate is None:
     515        dt = self.derateType
     516        if dt==DERATE_NONE:
    476517            return
    477518
    478         derate = self._flight.derate
    479         message = derateTemplate % ("-" if derate is None else derate)
    480         if self._derateLineID is None:
    481             if state is None:
    482                 state = self._aircraftState
    483             self._derateLineID = \
    484                 self.logger.message(state.timestamp, message)
    485         else:
    486             self.logger.updateLine(self._derateLineID, message)
     519        message = self.getDerateLine(self._flight.derate)
     520        if message is not None:
     521            if self._derateLineID is None:
     522                if state is None:
     523                    state = self._aircraftState
     524                self._derateLineID = \
     525                  self.logger.message(state.timestamp, message)
     526            else:
     527                self.logger.updateLine(self._derateLineID, message)
    487528
    488529    def _logTakeoffAntiIce(self, state = None):
     
    607648
    608649    @property
    609     def derateLabels(self):
    610         """Get the derate strings for this type."""
    611         return (xstr("takeoff_derate_boeing"), "%")
    612 
    613     @property
    614     def derateTemplate(self):
    615         """Get the derate template for this aicraft type."""
    616         return "Derate calculated by the pilot: %s %%"
     650    def derateType(self):
     651        """Get the derate type for this type."""
     652        return DERATE_BOEING
    617653
    618654    # def _appendSpeedChecker(self):
     
    741777
    742778    @property
    743     def derateLabels(self):
    744         """Get the derate strings for this type."""
    745         return (xstr("takeoff_derate_boeing"), "%")
    746 
    747     @property
    748     def derateTemplate(self):
    749         """Get the derate template for this aicraft type."""
    750         return "Derate calculated by the pilot: %s %%"
     779    def derateType(self):
     780        """Get the derate type for this type."""
     781        return DERATE_BOEING
    751782
    752783#---------------------------------------------------------------------------------------
     
    819850
    820851    @property
    821     def derateLabels(self):
    822         """Get the derate strings for this type."""
    823         return ("EPR", None)
    824 
    825     @property
    826     def derateTemplate(self):
    827         """Get the derate template for this aicraft type."""
    828         return "EPR calculated by the pilot: %s"
     852    def derateType(self):
     853        """Get the derate type for this type."""
     854        return DERATE_EPR
    829855
    830856#---------------------------------------------------------------------------------------
     
    881907
    882908    @property
    883     def derateLabels(self):
    884         """Get the derate strings for this type."""
    885         return (xstr("takeoff_derate_tupolev"), None)
    886 
    887     @property
    888     def derateTemplate(self):
    889         """Get the derate template for this aicraft type."""
    890         return "Nominal/takeoff power calculated by the pilot: %s"
     909    def derateType(self):
     910        """Get the derate type for this type."""
     911        return DERATE_TUPOLEV
    891912
    892913    @property
     
    939960
    940961    @property
    941     def derateLabels(self):
    942         """Get the derate strings for this type."""
    943         return (xstr("takeoff_derate_tupolev"), None)
    944 
    945     @property
    946     def derateTemplate(self):
    947         """Get the derate template for this aicraft type."""
    948         return "Nominal/takeoff power calculated by the pilot: %s"
     962    def derateType(self):
     963        """Get the derate type for this type."""
     964        return DERATE_TUPOLEV
    949965
    950966    def _appendLightsLoggers(self):
     
    9901006
    9911007    @property
    992     def derateLabels(self):
    993         """Get the derate strings for this type."""
    994         return (xstr("takeoff_derate_tupolev"), None)
    995 
    996     @property
    997     def derateTemplate(self):
    998         """Get the derate template for this aicraft type."""
    999         return "Nominal/takeoff power calculated by the pilot: %s"
     1008    def derateType(self):
     1009        """Get the derate type for this type."""
     1010        return DERATE_TUPOLEV
    10001011
    10011012    def _appendLightsLoggers(self):
     
    10381049
    10391050    @property
    1040     def derateLabels(self):
    1041         """Get the derate strings for this type."""
    1042         return (xstr("takeoff_derate_b462"), None)
    1043 
    1044     @property
    1045     def derateTemplate(self):
    1046         """Get the derate template for this aicraft type."""
    1047         return "Derate enabled: %s"
     1051    def derateType(self):
     1052        """Get the derate type for this type."""
     1053        return DERATE_B462
    10481054
    10491055#---------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.