Exemple #1
0
    def test_get_malfunctions_no_malfunctions(self, low_battery_mocker,
                                              no_data_mocker):
        low_battery_mocker.return_value = False
        no_data_mocker.return_value = False

        detector = MalfunctionDetector()
        assert detector.get_malfunctions(channel_data=[]) == []
Exemple #2
0
    def test_has_low_battery(self):
        create_malfunction_global_vars()
        detector = MalfunctionDetector()

        assert detector._has_low_battery(self.sample_channel_data) == False

        # Set a voltage below the cutoff.
        self.sample_channel_data[-1]['battery_voltage'] = str(
            get_float_global_var_value('LOW_BATTERY_CUTOFF') - 0.1)
        assert detector._has_low_battery(self.sample_channel_data) == True
Exemple #3
0
    def test_get_malfunctions_all_malfunctioning(self, low_frequency_mocker,
                                                 outliers_mocker,
                                                 low_battery_mocker):
        low_battery_mocker.return_value = True
        low_frequency_mocker.return_value = True
        outliers_mocker.return_value = True

        detector = MalfunctionDetector()
        assert detector.get_malfunctions(channel_data=['data']) == [
            'low_battery_voltage', 'low_reporting_frequency',
            'reporting_outliers'
        ]
def _get_channel_malfunctions(channel_data, channel_type):
    """
    Use channel_data to get a list of malfunctions that may be occuring with a channel.

    Returns: a list of potential malfunctions. Potential malfunctions include:
        - "low_battery_voltage": Channel data indicates that the device is running low on battery
        - "low_reporting_frequency": The device is not reporting data fast enough or at all.
        - "reporting_outliers": The sensor is reporting readings that are outside a reasonable range.
        - "no_data": The channel_data list was empty.
    """
    malfunction_detector = MalfunctionDetector()
    if channel_type == AIRQO_CHANNEL_TYPE:
        malfunction_detector = AirqoMalfunctionDetector()
    elif channel_type == SOIL_CHANNEL_TYPE:
        malfunction_detector = SoilMalfunctionDetector()

    return malfunction_detector.get_malfunctions(channel_data)
Exemple #5
0
 def test_has_no_data(self):
     detector = MalfunctionDetector()
     assert detector._has_no_data([])
     assert not detector._has_no_data(['imdata'])
Exemple #6
0
    def test_get_malfunctions_all_malfunctioning_no_data(self, no_data_mocker):
        no_data_mocker.return_value = True

        detector = MalfunctionDetector()
        assert detector.get_malfunctions(channel_data=[]) == ['no_data']
Exemple #7
0
 def test_has_low_reporting_frequency(self):
     detector = MalfunctionDetector()
     assert not detector._has_low_reporting_frequency([])
Exemple #8
0
 def test_sensor_is_reporting_outliers(self):
     detector = MalfunctionDetector()
     assert not detector._sensor_is_reporting_outliers([])