def test_light(self): """Test that the light_plot function is accessing the correct data.""" test_df = pd.read_csv(mapping_funcs.DATA_DIR + "/2017.csv") test_out = mlpredict.light_plot(test_df, TEST_OUTPUT) self.assertEqual(len(test_out), 8, "The dataframe counts for light are incorrect.")
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")
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
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)
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")