def test_datasource_classifier_unpicklable(self):
        wrong_config = config.copy()
        wrong_config[
            'datasource_classifier'] = "test_models/unpicklable_model.txt"

        with self.assertRaises(ex.InvalidConfigValueException):
            mp.load_classifier(wrong_config, self.current_model_type_std[0])
Ejemplo n.º 2
0
 def test_correct_execution_with_right_parameter(self):
     test_config = config.copy()
     test_config['selected_event'] = 'standard'
     enriched_df = pd.DataFrame.from_dict({
         "time": [1.0, 2.0, 3.0],
         "outdoor": [14.2, 4.1, 1.32],
         "inlet": [99.2, 91.2, 192.2],
         "room": [13.2, 61.2, 02.3],
         "freshAirIntake": [13.0, 34.2, 34.0],
         "condenser": [17.0, 17.0, 17.0],
         "evaporator": [17.0, 17.0, 17.0],
         "outlet": [17.0, 17.0, 17.0],
         'evaporator_deriv': [17.0, 17.0, 17.0],
         'evaporator_pct_ch': [17.0, 17.0, 17.0],
         'evaporator_ch_abs': [17.0, 17.0, 17.0],
         'evaporator_diff': [0.0, 0.0, 0.0],
         'condenser_deriv': [17.0, 17.0, 17.0],
         'condenser_pct_ch': [17.0, 17.0, 17.0],
         'condenser_ch_abs': [17.0, 17.0, 17.0],
         'condenser_diff': [0.0, 0.0, 0.0]
     })
     enriched_df["time"] = pd.to_datetime(enriched_df["time"])
     enriched_df = enriched_df.set_index("time")
     when2(read_manager.read_query, ANY, ANY).thenReturn(enriched_df)
     when2(write_manager.write_dataframe, ANY, ANY, ANY)
     self.assertEqual(trainingsdata.mark_data(test_config), 0)
    def test_datasource_classifier_is_wrong(self):
        wrong_config = config.copy()
        wrong_config[
            'datasource_classifier'] = "i_am_not_an_existing_file.yeah"

        with self.assertRaises(ex.InvalidConfigValueException):
            mp.load_classifier(wrong_config, self.current_model_type_std[0])
Ejemplo n.º 4
0
    def test_for_UnpicklingError(self):
        test_config = config.copy()
        test_config[
            'datasource_classifier'] = "test_models/unpicklable_model.txt"

        with self.assertRaises(ex.InvalidConfigValueException):
            mp.persist_classifier(self.model, test_config,
                                  self.current_model_type_std[0])
    def test_model_at_event_is_empty_returns_KNC(self):
        test_config = config.copy()
        test_config[
            'datasource_classifier'] = "test_models/model_test_returns_not_existing_classifier.txt"

        tested_model = mp.load_classifier(test_config,
                                          self.current_model_type_std[0])

        self.assertTrue(isinstance(tested_model, type(self.model)))
 def test_returns_existing_classifier(self):
     classification_config = config.copy()
     classification_config[
         'datasource_classifier'] = "test_models/model_test_returns_existing_classifier.txt"
     self.assertTrue(
         isinstance(
             mp.load_classifier(classification_config,
                                self.current_model_type_std[0]),
             type(self.model)))
    def test_new_classifer_method_is_not_empty(self):
        test_config = config.copy()
        test_config[
            'datasource_classifier'] = "test_models/model_returns_code_0.txt"
        test_config['new_classifier_method'] = "kNN"
        test_model = mp.load_classifier(test_config,
                                        self.current_model_type_std[0])

        self.assertTrue(isinstance(test_model, type(self.model)))
    def test_for_existing_models_in_dictionary(self):
        test_config = config.copy()
        test_config[
            'datasource_classifier'] = "test_models/model_returns_code_0.txt"
        test_config['selected_event'] = "warmwasseraufbereitung"
        mp.persist_classifier(self.model, test_config,
                              self.current_model_type_std[1])

        existing_model = mp.load_classifier(test_config,
                                            self.current_model_type_std[1])
        self.assertTrue(isinstance(existing_model, type(self.model)))
Ejemplo n.º 9
0
    def test_marked_dataframe_has_abtauzyklus_column(self):
        test_config = config.copy()
        test_config['selected_event'] = 'standard'
        enriched_df = pd.DataFrame.from_dict({
            "time": [1.0, 2.0, 3.0],
            "outdoor": [14.2, 4.1, 1.32],
            "inlet": [99.2, 91.2, 192.2],
            "room": [13.2, 61.2, 02.3],
            "freshAirIntake": [13.0, 34.2, 34.0],
            "condenser": [17.0, 17.0, 17.0],
            "evaporator": [17.0, 17.0, 17.0],
            "outlet": [17.0, 17.0, 17.0],
            'evaporator_deriv': [17.0, 17.0, 17.0],
            'evaporator_pct_ch': [17.0, 17.0, 17.0],
            'evaporator_ch_abs': [17.0, 17.0, 17.0],
            'evaporator_diff': [0.0, 0.0, 0.0],
            'condenser_deriv': [17.0, 17.0, 17.0],
            'condenser_pct_ch': [17.0, 17.0, 17.0],
            'condenser_ch_abs': [17.0, 17.0, 17.0],
            'condenser_diff': [0.0, 0.0, 0.0]
        })
        enriched_df["time"] = pd.to_datetime(enriched_df["time"])
        enriched_df = enriched_df.set_index("time")
        marked_df = pd.DataFrame.from_dict({
            "time": [1.0, 2.0, 3.0],
            "outdoor": [14.2, 4.1, 1.32],
            "inlet": [99.2, 91.2, 192.2],
            "room": [13.2, 61.2, 02.3],
            "freshAirIntake": [13.0, 34.2, 34.0],
            "condenser": [17.0, 17.0, 17.0],
            "evaporator": [17.0, 17.0, 17.0],
            "outlet": [17.0, 17.0, 17.0],
            'evaporator_deriv': [17.0, 17.0, 17.0],
            'evaporator_pct_ch': [17.0, 17.0, 17.0],
            'evaporator_ch_abs': [17.0, 17.0, 17.0],
            'evaporator_diff': [17.0, 17.0, 17.0],
            'condenser_deriv': [17.0, 17.0, 17.0],
            'condenser_pct_ch': [17.0, 17.0, 17.0],
            'condenser_ch_abs': [17.0, 17.0, 17.0],
            'condenser_diff': [17.0, 17.0, 17.0],
            'abtauzyklus_marker': [1.0, 0.0, 0.0],
            'abtauzyklus': [True, True, False],
            'warmwasseraufbereitung_marker': [True, True, False],
            'warmwasseraufbereitung': [True, True, False]
        })

        marked_df["time"] = pd.to_datetime(marked_df["time"])
        marked_df = marked_df.set_index("time")
        when2(read_manager.read_query, ANY, ANY).thenReturn(enriched_df)
        df_captor = captor(any(pd.DataFrame))
        when2(write_manager.write_dataframe, ANY, df_captor, ANY)
        trainingsdata.mark_data(test_config)
        df = df_captor.value
        self.assertListEqual(df.columns.tolist(), marked_df.columns.tolist())
    def test_model_for_event_is_not_instance_of_sklearn(self):
        path_to_wrong_dictionary = "test_models/model_returns_code_0_contains_wrong_model_at_abauzyklus.txt"
        classifier_dictionary = mp.load_dictionary(
            "test_models/model_returns_code_0.txt")
        classifier_dictionary['abtauzyklus'] = "Ich bin kein richtiges Model"
        mp.save_dictionary(classifier_dictionary, path_to_wrong_dictionary)

        wrong_config = config.copy()
        wrong_config['datasource_classifier'] = path_to_wrong_dictionary

        test_model = mp.load_classifier(wrong_config,
                                        self.current_model_type_std[0])
        self.assertFalse(isinstance(test_model, type(self.model)))
Ejemplo n.º 11
0
    def test_enriched_dataframe_has_correct_format(self):
        test_config = config.copy()
        test_config['selected_event'] = 'standard'
        example_df = pd.DataFrame.from_dict({
            "time": [1.0, 2.0, 3.0],
            "outdoor": [14.2, 4.1, 1.32],
            "inlet": [99.2, 91.2, 192.2],
            "room": [13.2, 61.2, 02.3],
            "freshAirIntake": [13.0, 34.2, 34.0],
            "condenser": [17.0, 17.0, 17.0],
            "evaporator": [17.0, 17.0, 17.0],
            "outlet": [17.0, 17.0, 17.0]
        })
        example_df["time"] = pd.to_datetime(example_df["time"])
        example_df = example_df.set_index("time")
        enriched_df = pd.DataFrame.from_dict({
            "time": [1.0, 2.0, 3.0],
            "outdoor": [14.2, 4.1, 1.32],
            "inlet": [99.2, 91.2, 192.2],
            "room": [13.2, 61.2, 02.3],
            "freshAirIntake": [13.0, 34.2, 34.0],
            "condenser": [17.0, 17.0, 17.0],
            "evaporator": [17.0, 17.0, 17.0],
            "outlet": [17.0, 17.0, 17.0],
            'evaporator_deriv': [17.0, 17.0, 17.0],
            'evaporator_pct_ch': [17.0, 17.0, 17.0],
            'evaporator_ch_abs': [17.0, 17.0, 17.0],
            'evaporator_diff': [17.0, 17.0, 17.0],
            'condenser_deriv': [17.0, 17.0, 17.0],
            'condenser_pct_ch': [17.0, 17.0, 17.0],
            'condenser_ch_abs': [17.0, 17.0, 17.0],
            'condenser_diff': [17.0, 17.0, 17.0],
            'room_deriv': [17.0, 17.0, 17.0],
            'room_pct_ch': [17.0, 17.0, 17.0],
            'room_ch_abs': [17.0, 17.0, 17.0],
            'room_diff': [17.0, 17.0, 17.0],
            'inlet_deriv': [17.0, 17.0, 17.0],
            'inlet_pct_ch': [17.0, 17.0, 17.0],
            'inlet_ch_abs': [17.0, 17.0, 17.0],
            'inlet_diff': [17.0, 17.0, 17.0]
        })

        enriched_df["time"] = pd.to_datetime(enriched_df["time"])
        enriched_df = enriched_df.set_index("time")
        when2(read_manager.read_query, ANY, ANY).thenReturn(example_df)
        df_captor = captor(any(pd.DataFrame))
        when2(write_manager.write_dataframe, ANY, df_captor, ANY)
        trainingsdata.enrich_data(test_config)
        df = df_captor.value
        self.assertListEqual(df.columns.tolist(), enriched_df.columns.tolist())
    def test_datasource_classifier_none(self):
        wrong_config = config.copy()
        wrong_config["datasource_classifier"] = None

        with self.assertRaises(ex.InvalidConfigValueException):
            mp.load_classifier(wrong_config, self.current_model_type_std[0])