Changeset 346:78e378a97bdf


Ignore:
Timestamp:
12/08/12 15:22:06 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

It is now possible to log faults so that the last one is updated instead of writing a new one (#143)

Location:
src/mlx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/checks.py

    r344 r346  
    12921292                           FaultChecker._appendDuring(flight, message),
    12931293                           FaultChecker._getLinearScore(50, 80, 10, 15,
    1294                                                         state.groundSpeed))
     1294                                                        state.groundSpeed),
     1295                           updatePrevious = True)
    12951296
    12961297    def isCondition(self, flight, aircraft, oldState, state):
  • src/mlx/flight.py

    r304 r346  
    269269            return False
    270270
    271     def handleFault(self, faultID, timestamp, what, score):
     271    def handleFault(self, faultID, timestamp, what, score,
     272                    updatePrevious = False):
    272273        """Handle the given fault.
    273274
     
    276277        the score is greater than last time. This ID can be, e.g. the checker
    277278        the report comes from."""
    278         self.logger.fault(faultID, timestamp, what, score)
     279        self.logger.fault(faultID, timestamp, what, score,
     280                          updatePrevious = updatePrevious)
    279281        self._gui.setRating(self.logger.getRating())
    280282
  • src/mlx/logger.py

    r345 r346  
    9696            return self._faultScore
    9797
    98         def copy(self, text = None):
     98        def copy(self, timestamp = None, clearTimestamp = False, text = None,
     99                 faultScore = None):
    99100            """Create a copy of this entry with the given values changed."""
    100             return Logger.Entry(self._timestamp,
     101            assert faultScore is None or self._faultID is not None
     102
     103            return Logger.Entry(None if clearTimestamp
     104                                else self._timestamp if timestamp is None
     105                                else timestamp,
     106
    101107                                self._text if text is None else text,
     108
    102109                                showTimestamp = self._showTimestamp,
     110
    103111                                faultID = self._faultID,
    104                                 faultScore = self._faultScore,
     112
     113                                faultScore =
     114                                self._faultScore if faultScore is None
     115                                else faultScore,
     116
    105117                                id = self._id)
    106118
     
    151163
    152164            return len(entries)>0
     165
     166        def getLatestEntry(self):
     167            """Get the entry with the highest score."""
     168            return self._entries[0]
    153169
    154170    # FIXME: shall we use const.stage2string() instead?
     
    231247            sendMessage(messageType, "Flight stage: " + s, 3)
    232248
    233     def fault(self, faultID, timestamp, what, score):
     249    def fault(self, faultID, timestamp, what, score,
     250              updatePrevious = False):
    234251        """Report a fault.
    235252
     
    239256        the report comes from.
    240257
     258        If updatePrevious is True, and an instance of the given fault is
     259        already in the log, only that instance will be updated with the new
     260        timestamp and score. If there are several instances, the latest one
     261        (with the highest score) will be updated. If updatePrevious is True,
     262        and the new score is not greater than the latest one, the ID of the
     263        latest one is returned.
     264
    241265        Returns an ID of the fault, or -1 if it was not logged."""
    242         if faultID in self._faults:
    243             if score<=self._faults[faultID].score:
    244                 return -1
     266        fault = self._faults[faultID] if faultID in self._faults else None
     267
     268        if fault is not None and score<=fault.score:
     269            return fault.getLatestEntry().id if updatePrevious else -1
    245270
    246271        text = "%s (NO GO)" % (what) if score==Logger.NO_GO_SCORE \
    247272               else "%s (%.1f)" % (what, score)
    248273
    249         id = self._addEntry(Logger.Entry(timestamp, text, faultID = faultID,
    250                                          faultScore = score))
     274        if updatePrevious and fault is not None:
     275            latestEntry = fault.getLatestEntry()
     276            id = latestEntry.id
     277            newEntry = latestEntry.copy(timestamp = timestamp,
     278                                        text = text,
     279                                        faultScore = score)
     280            self._updateEntry(id, newEntry)
     281        else:
     282            id = self._addEntry(Logger.Entry(timestamp, text, faultID = faultID,
     283                                             faultScore = score))
    251284
    252285        (messageType, duration) = (const.MESSAGETYPE_NOGO, 10) \
Note: See TracChangeset for help on using the changeset viewer.