def show_map(self): """Output the map that was chosen for the features that were selected, output text to inidicate where the final interactable html map is saved for the user.""" vars_dict = mapping_funcs.VARS_DICT subgroups_dict = mapping_funcs.R_SUBGROUPS_DICT incident_dict = mapping_funcs.R_INCIDENT_DICT county_dict = mapping_funcs.R_COUNTY_DICT year = self.selection0.get() county = county_dict[self.selection1.get()] county_name = mapping_funcs.COUNTY_DICT[county] grp_feature = vars_dict[self.selection2.get()] subgrp_feature = subgroups_dict[self.selection2.get()][ self.selection3.get()] my_map = mapping.Maps() data = mapping_funcs.read_dataframe(year) dataframe = data[data.COUNTY == county] group_df = dataframe.groupby(grp_feature) subgrp_df = group_df.apply(lambda g: g[g['weather'] == subgrp_feature]) grp_dict = mapping_funcs.GRP_DICT group = grp_dict[grp_feature] if self.selection4.get() == 'Basic road-map': my_map.basic_map(county_name, county, group, dataframe, subgrp_df) if subgrp_df.shape[0] == 0: my_text = f'No data for the provided {group} selection, an empty map was generated into the "outputs" folder' else: my_text = 'Basic map for {}, under {} conditions saved in "outputs" folder'.format( self.selection3.get(), self.selection2.get()) tk.Label(ROOT, text=my_text).pack() if self.selection4.get() == 'Cluster map': my_map.plot_folium_filtered_clusters(county_name, county, group, dataframe, subgrp_df) if subgrp_df.shape[0] == 0: my_text = f'No data for the provided {group} selection, an empty map was generated into the "outputs" folder' else: my_text = 'Cluster map for {}, under {} conditions saved in "outputs" folder'.format( self.selection3.get(), self.selection2.get()) tk.Label(ROOT, text=my_text).pack() if self.selection4.get() == 'Layers by year map': my_map.plot_folium_filtered_layers(group, county_name, county, grp_feature, subgrp_feature) my_text = 'Layer map for {}, under {} conditions saved in "outputs" folder'.format( self.selection3.get(), self.selection2.get()) tk.Label(ROOT, text=my_text).pack() if self.selection4.get() == 'Cluster & Layer map': my_map.plot_folium_filtered_clusters_layers( county_name, county, group, grp_feature, subgrp_feature) my_text = 'Cluster & layer map for {}, under {} conditions saved in "outputs" folder'.format( self.selection3.get(), self.selection2.get()) tk.Label(ROOT, text=my_text).pack()
def test_clean_dataframe(self): """Test that the dataframe has been wrangled correctly.""" year = '2013' data = mapping_funcs.read_dataframe(year) num_columns = 22 self.assertEqual(len(data.columns), num_columns, "Dataframe not wrangled correctly")
def test_layer_cluster_map(self): """Use this test to assess how much time the big map takes to generate. However, this will vary depending on how much data belongs to the test_grp_feature and test_subgrp_feature. Run from the top-most level of the WAcrashviz package.""" vars_dict = mapping_funcs.VARS_DICT subgroups_dict = mapping_funcs.R_SUBGROUPS_DICT incident_dict = mapping_funcs.R_INCIDENT_DICT county_dict = mapping_funcs.R_COUNTY_DICT test_year = '2013' test_county = county_dict['Adams'] test_county_name = mapping_funcs.COUNTY_DICT[test_county] test_grp_feature = vars_dict['Weather'] test_subgrp_feature = subgroups_dict['Weather']['Raining'] test_df = mapping_funcs.read_dataframe(test_year) test_dataframe = test_df[test_df.COUNTY == test_county] test_group_df = test_dataframe.groupby(test_grp_feature) test_subgrp_df = test_group_df.apply( lambda g: g[g['weather'] == test_subgrp_feature]) test_grp_dict = mapping_funcs.GRP_DICT test_group = test_grp_dict[test_grp_feature] testmap = mapping.Maps() map_sink = TEST_OUTPUT + f'{test_group}_layer_cluster_map_test.html' t_zero = time.time() testmap.plot_folium_filtered_clusters_layers(test_county_name, test_county, test_group, test_grp_feature, test_subgrp_feature, map_sink) t_one = time.time() total = t_one - t_zero time_to_generate = 'layered cluster generation time is ' + str(total) save_tsv = TEST_OUTPUT + 'generation_times.tsv' with open(save_tsv, 'a+') as output: output.write(time_to_generate)