コード例 #1
0
        def d(stat: DiagnosticStatusWrapper) -> DiagnosticStatusWrapper:
            if self._motor_controller_state is None:
                stat.summary(DiagnosticStatus.STALE, "No more events recorded")
                return stat
            error_status = self._motor_controller_state.error_status[index]
            operational_state = self._motor_controller_state.operational_state[index]

            stat.add("Error status", error_status)
            stat.add("Operational state", operational_state)
            if error_status != "":
                stat.summary(DiagnosticStatus.ERROR, operational_state)
            else:
                stat.summary(DiagnosticStatus.OK, operational_state)

            return stat
コード例 #2
0
    def testFrequencyStatus(self):
        freq_bound = {'min': 10, 'max': 20}

        fs = FrequencyStatus(FrequencyStatusParam(freq_bound, 0.5, 2))

        stat = [DiagnosticStatusWrapper() for i in range(5)]
        fs.tick()
        time.sleep(.02)
        stat[0] = fs.run(stat[0])
        # Should be too fast, 20 ms for 1 tick, lower limit should be 33ms.
        time.sleep(.05)
        fs.tick()
        stat[1] = fs.run(stat[1])
        # Should be good, 70 ms for 2 ticks, lower limit should be 66 ms.
        time.sleep(.3)
        fs.tick()
        stat[2] = fs.run(stat[2])
        # Should be good, 350 ms for 2 ticks, upper limit should be 400 ms.
        time.sleep(.15)
        fs.tick()
        stat[3] = fs.run(stat[3])
        # Should be too slow, 450 ms for 2 ticks, upper limit should be 400 ms.
        fs.clear()
        stat[4] = fs.run(stat[4])
        # Should be good, just cleared it.

        self.assertEqual(b'1', stat[0].level, 'max frequency exceeded but not reported')
        self.assertEqual(b'0', stat[1].level, 'within max frequency but reported error')
        self.assertEqual(b'0', stat[2].level, 'within min frequency but reported error')
        self.assertEqual(b'1', stat[3].level, 'min frequency exceeded but not reported')
        self.assertEqual(b'2', stat[4].level, 'freshly cleared should fail')
        self.assertEqual('', stat[0].name, 'Name should not be set by FrequencyStatus')
        self.assertEqual('FrequencyStatus', fs.getName(), 'Name should be Frequency Status')
コード例 #3
0
    def testTimeStampStatus(self):
        ts = TimeStampStatus()

        stat = [DiagnosticStatusWrapper() for i in range(5)]
        stat[0] = ts.run(stat[0])
        clock = Clock(clock_type=ClockType.STEADY_TIME)
        now = clock.now()
        ts.tick((now.nanoseconds * 1e-9) + 2)
        stat[1] = ts.run(stat[1])
        now = clock.now()
        ts.tick((now.nanoseconds * 1e-9))
        stat[2] = ts.run(stat[2])
        now = clock.now()
        ts.tick((now.nanoseconds * 1e-9) - 4)
        stat[3] = ts.run(stat[3])
        now = clock.now()
        ts.tick((now.nanoseconds * 1e-9) - 6)
        stat[4] = ts.run(stat[4])

        self.assertEqual(b'1', stat[0].level, 'no data should return a warning')
        self.assertEqual(b'2', stat[1].level, 'too far future not reported')
        self.assertEqual(b'0', stat[2].level, 'now not accepted')
        self.assertEqual(b'0', stat[3].level, '4 seconds ago not accepted')
        self.assertEqual(b'2', stat[4].level, 'too far past not reported')
        self.assertEqual('', stat[0].name, 'Name should not be set by TimeStapmStatus')
        self.assertEqual('Timestamp Status', ts.getName(), 'Name should be Timestamp Status')
コード例 #4
0
    def test_merge_summary_lvl_msg(self):
        d = DiagnosticStatusWrapper(level=b'0', message='ok')
        d.mergeSummary(b'1', 'warn')
        self.assertEqual(d.level, b'1')
        self.assertEqual(d.message, 'warn')

        d.mergeSummary(b'2', 'err')
        self.assertEqual(d.level, b'2')
        self.assertEqual(d.message, 'warn; err')
コード例 #5
0
 def test_add(self):
     d = DiagnosticStatusWrapper()
     d.add('key', 'val')
     self.assertEqual(d.values[0].key, 'key')
     self.assertEqual(d.values[0].value, 'val')
コード例 #6
0
 def test_clear_summary(self):
     d = DiagnosticStatusWrapper(level=b'0', message='ok')
     d.clearSummary()
     self.assertEqual(d.level, b'0')
     self.assertEqual(d.message, '')
コード例 #7
0
 def test_summary_dmsg(self):
     d = DiagnosticStatusWrapper(level=b'0', message='ok')
     m = DiagnosticStatus(level=b'1', message='warn')
     d.summary(m)
     self.assertEqual(d.level, b'1')
     self.assertEqual(d.message, 'warn')
コード例 #8
0
 def test_summary_lvl_msg(self):
     d = DiagnosticStatusWrapper()
     d.summary(b'1', 'test')
     self.assertEqual(d.level, b'1')
     self.assertEqual(d.message, 'test')
コード例 #9
0
 def test_init_lvl_msg(self):
     d = DiagnosticStatusWrapper(level=b'1', message='test')
     self.assertEqual(d.level, b'1')
     self.assertEqual(d.message, 'test')
     self.assertEqual(d.values, [])
コード例 #10
0
 def test_init_empty(self):
     d = DiagnosticStatusWrapper()
     self.assertEqual(d.level, b'\x00')
     self.assertEqual(d.message, '')
     self.assertEqual(d.values, [])
コード例 #11
0
    def testDiagnosticStatusWrapper(self):
        stat = DiagnosticStatusWrapper()

        message = 'dummy'
        level = b'1'
        stat.summary(level, message)
        self.assertEqual(message, stat.message, 'DiagnosticStatusWrapper::summary failed\
                         to set message')
        self.assertEqual(level, stat.level, 'DiagnosticStatusWrapper::summary failed to set level')

        stat.add('toto', '%.1f' % 5.0)
        stat.add('baba', '5')
        stat.add('foo', '%05i' % 27)
        stat.add('bool', 'True')
        stat.add('bool2', 'False')
        self.assertEqual('5.0', stat.values[0].value, 'Bad value, adding a value with addf')
        self.assertEqual('5', stat.values[1].value, 'Bad value, adding a string with add')
        self.assertEqual('00027', stat.values[2].value, 'Bad value, adding a string with addf')
        self.assertEqual('toto', stat.values[0].key, 'Bad label, adding a value with add')
        self.assertEqual('baba', stat.values[1].key, 'Bad label, adding a string with add')
        self.assertEqual('foo', stat.values[2].key, 'Bad label, adding a string with addf')

        self.assertEqual('bool', stat.values[3].key, 'Bad label, adding a true bool key with add')
        self.assertEqual('True', stat.values[3].value, 'Bad value, adding a true bool with add')

        self.assertEqual('bool2', stat.values[4].key, 'Bad label, adding a false bool key\
                         with add')
        self.assertEqual('False', stat.values[4].value, 'Bad value, adding a false bool with add')
コード例 #12
0
    def diagnostics(self,
                    stat: DiagnosticStatusWrapper) -> DiagnosticStatusWrapper:
        """Create a diagnostic message to display in the standard stat format."""
        if self._timestamp is None:
            stat.add("Topic error", "No events recorded")
            stat.summary(DiagnosticStatus.STALE, "No temperature recorded")
            return stat

        if (not LOWER_THRESHOLD_VALID_TEMPERATURE_VALUE < self._temperature <
                UPPER_THRESHOLD_VALID_TEMPERATURE_VALUE):
            stat.add("Current temperature", self._temperature)
            stat.summary(
                DiagnosticStatus.WARN,
                "No valid temperature value ({tp}).".format(
                    tp=self._temperature),
            )
            return stat

        stat.add("Default threshold", self._default_threshold)
        stat.add("Warning threshold", self._thresholds_warning)
        stat.add("Non fatal threshold", self._thresholds_non_fatal)
        stat.add("Fatal threshold", self._thresholds_fatal)
        stat.add("Current temperature", self._temperature)

        if self._default_threshold is None:
            stat.summary(DiagnosticStatus.WARN, "No thresholds found")
        elif self._temperature < self._thresholds_warning:
            stat.summary(DiagnosticStatus.OK,
                         "OK ({tp}).".format(tp=self._temperature))
        elif self._temperature < self._thresholds_non_fatal:
            stat.summary(
                DiagnosticStatus.WARN,
                "Temperature almost too high ({tp}).".format(
                    tp=self._temperature),
            )
        else:
            stat.summary(
                DiagnosticStatus.ERROR,
                "Temperature too high ({tp}).".format(tp=self._temperature),
            )

        return stat