Exemplo n.º 1
0
    def test_months(self):
        """Test that the month_plot function is accessing the correct data."""

        test_df = pd.read_csv(mapping_funcs.DATA_DIR + "/2017.csv")
        test_out = mlpredict.month_plot(test_df, TEST_OUTPUT)
        self.assertEqual(len(test_out), 12,
                         "The dataframe counts for month are incorrect.")
Exemplo n.º 2
0
    def test_mlpredict(self):
        """Test that the different functions being called in mlpredict.py produce
        the plots it's supposed to in the location that it's supposed to."""

        year_plot_list = []
        for yr in range(2013, 2018):
            year_plot_list.append(pd.read_csv(mapping_funcs.DATA_DIR + '/{}.csv'.format(yr)).shape[0])
        _ = mlpredict.year_plot(year_plot_list, TEST_OUTPUT)

        df_2017 = pd.read_csv(mapping_funcs.DATA_DIR + "/2017.csv")

        _ = mlpredict.month_plot(df_2017, TEST_OUTPUT)
        _ = mlpredict.weekday_plot(df_2017, TEST_OUTPUT)
        _ = mlpredict.weather_plot(df_2017, TEST_OUTPUT)
        _ = mlpredict.road_plot(df_2017, TEST_OUTPUT)
        _ = mlpredict.light_plot(df_2017, TEST_OUTPUT)
        _ = mlpredict.ml_prediction(df_2017, TEST_OUTPUT)
        self.assertEqual((os.path.isfile(TEST_OUTPUT + '/year_plot.png') and
                              os.path.isfile(TEST_OUTPUT + '/month_plot.png') and
                              os.path.isfile(TEST_OUTPUT + 'weekday_plot.png') and
                              os.path.isfile(TEST_OUTPUT + 'weather_plot.png') and
                              os.path.isfile(TEST_OUTPUT + 'road_plot.png') and
                              os.path.isfile(TEST_OUTPUT + 'light_plot.png') and
                              os.path.isfile(TEST_OUTPUT + 'weather_factor_importance.png')),
                             True,
                             "Missing one or more outputs")
Exemplo n.º 3
0
    def generate_ml(self, year):

        merged_data = pd.read_csv(mapping_funcs.DATA_DIR +
                                  '/{}.csv'.format(year))
        mlpredict.month_plot(merged_data)
        mlpredict.weekday_plot(merged_data)
        mlpredict.weather_plot(merged_data)
        mlpredict.road_plot(merged_data)
        mlpredict.light_plot(merged_data)
        mlpredict.ml_prediction(merged_data)

        year_plot_list = []
        for year in range(2013, 2018):
            year_plot_list.append(
                pd.read_csv(mapping_funcs.DATA_DIR +
                            '/{}.csv'.format(year)).shape[0])
        mlpredict.year_plot(year_plot_list)
        pass
Exemplo n.º 4
0
def generate_ml(year):
    """
    generate statistical analysis plots in the outputs folder
    """

    merged_data = pd.read_csv(mapping_funcs.DATA_DIR + '/{}.csv'.format(year))
    mlpredict.month_plot(merged_data)
    mlpredict.weekday_plot(merged_data)
    mlpredict.weather_plot(merged_data)
    mlpredict.road_plot(merged_data)
    mlpredict.light_plot(merged_data)
    mlpredict.ml_prediction(merged_data)

    year_plot_list = []
    for years in range(2013, 2018):
        year_plot_list.append(
            pd.read_csv(mapping_funcs.DATA_DIR +
                        '/{}.csv'.format(years)).shape[0])
    mlpredict.year_plot(year_plot_list)
Exemplo n.º 5
0
def test_mlpredict():
    year_plot_list = []
    for yr in range(2013, 2018):
        year_plot_list.append(
            pd.read_csv(mapping_funcs.DATA_DIR + '/2013.csv').shape[0])
    mlpredict.year_plot(year_plot_list, TEST_OUTPUT)

    df_2017 = pd.read_csv(mapping_funcs.DATA_DIR + "/2017.csv")

    mlpredict.month_plot(df_2017, TEST_OUTPUT)
    mlpredict.weekday_plot(df_2017, TEST_OUTPUT)
    mlpredict.weather_plot(df_2017, TEST_OUTPUT)
    mlpredict.road_plot(df_2017, TEST_OUTPUT)
    mlpredict.light_plot(df_2017, TEST_OUTPUT)
    mlpredict.ml_prediction(df_2017, TEST_OUTPUT)
    unittest.assertEqual(
        (os.path.isfile(TEST_OUTPUT + '/year_plot.png')
         and os.path.isfile(TEST_OUTPUT + '/month_plot.png')
         and os.path.isfile(TEST_OUTPUT + 'weekday_plot.png')
         and os.path.isfile(TEST_OUTPUT + 'weather_plot.png')
         and os.path.isfile(TEST_OUTPUT + 'road_plot.png')
         and os.path.isfile(TEST_OUTPUT + 'light_plot.png')
         and os.path.isfile(TEST_OUTPUT + 'weather_factor_importance.png')),
        True, "Missing one or more outputs")