def test_wrong_gmaps_key(self): address = Address(self.valid_address) tmp = address.gmaps address.gmaps = googlemaps.Client(key=self.BROKEN_GMAPS_KEY) with self.assertRaises(addressClass.InvalidGmapsKey): address._get_address_info(address.formatted_address) address.gmaps = tmp
def test_address_init(self): #This part success if address not in Chicago exception is raised with self.assertRaises(ValueError): address = Address(self.invalid_address) #First part success if no exceptions are raised. address = Address(self.valid_address) self.assertAlmostEqual(address.lat, self.valid_lat_lon[0], places=3) self.assertAlmostEqual(address.lon, self.valid_lat_lon[1], places=3) self.assertAlmostEqual
def setUp(self): self.address_wrong = 'asdf' self.address = Address('4334 West Washington Blvd') self.test_db = pd.DataFrame( [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]], columns=['Year', 'Month', 'Arrest', 'District']) self.test_CrimesDataFrame = CrimesDataFrame(self.test_db) self.malformed_addresses_array = [1, 2, 3, 4] self.addresses_array = [self.address, self.address] self.zero_addresses_array = []
def setUp(self): #Useful attributes for testing self.good_address = Address('4334 W Washington Blv') self.data = pd.read_csv('./tests/csv_for_test.csv')
def main(): # Maximum number of addresses for analysis allowed MAX_ADDRESSES = 10 interface_utils.display_welcome_screen() # Load DB of crimes. If Database is not clean, the program will clean it and the user will have the option to save it crimes_database = databases_utils.get_crimes_db() os.system('clear') # Ask for user to choose a range of years and filter the Database accordingly crimes_database = databases_utils.filter_db_by_timeframe(crimes_database) # Ask for user to choose one or more types of crime and filter the Database accordingly crimes_database = databases_utils.filter_db_by_crime(crimes_database) # Create an instance of the CrimesDataFrame class with the filtered Database. This class is in charge of Statistics crimes_database = CrimesDataFrame(crimes_database) # Create lists to save addresses and addresses names of interest user_addresses = [] user_addresses_names = [] # Create interface Options interface_options = ['Add another address','Delete saved address', 'View saved address', 'Comparative analysis','Quit'] option = 'Add another address' # Main loop of the program. It will ask for user input and show maps and analyses until 'Quit' is introduced while 1: if (not user_addresses) or option == 'Add another address': try: # Create an instance of Address class. It will ask user to input an address, validate it through # Google Maps, and calculate/save several attributes of that address. address = Address() except NoInternetAccess: print('No Internet connection found') if interface_utils.yesno_question('Continue?'): address = None # Continue with the normal loop without saving the address else: raise QuitProgram # Create a District Heat Map with maps_builder class and show it. if address: interface_utils.computing_statistics_message() address.summary = address_analysis(crimes_database, address) address_analysis_output(address, crimes_database) # User will have the option to save/discard the address after reviewing the Map and Statistics. if interface_utils.yesno_question('Keep this address for comparative analysis?'): if len(user_addresses) == MAX_ADDRESSES: print 'Maximum number of addresses to save reached, delete one location before adding a new address' else: if address not in user_addresses: user_addresses.append(address) user_addresses_names.append(address.formatted_address) # This option will allow the user to review the Map and Stats of an address that was saved. elif option == 'View saved address': option = interface_utils.get_options_from_user(user_addresses_names + ['Back'], multiple=False) if option != 'Back': address = user_addresses[user_addresses_names.index(option)] interface_utils.computing_statistics_message() address_analysis_output(address, crimes_database) # This option will allow the user to delete one of the saved addresses. elif option == 'Delete saved address': option = interface_utils.get_options_from_user(user_addresses_names + ['Back'], multiple=False) if option != 'Back': user_addresses.pop(user_addresses_names.index(option)) user_addresses_names.pop(user_addresses_names.index(option)) # This option will create a comparative Map and statistics to analyze and compare the saved addresses. elif option == 'Comparative analysis': comparative_analysis_output(crimes_database, user_addresses) # This option is the only way to end the loop and finish the program elif option == 'Quit': raise QuitProgram # If user_addresses is empty start the loop again directly to ask for an address # If there are addresses in user_addresses, offer options on how to continue if user_addresses: option = interface_utils.get_options_from_user(interface_options, multiple=False)
def main(): # Maximum number of addresses for analysis allowed MAX_ADDRESSES = 10 interface_utils.display_welcome_screen() # Load DB of crimes. If Database is not clean, the program will clean it and the user will have the option to save it crimes_database = databases_utils.get_crimes_db() os.system('clear') # Ask for user to choose a range of years and filter the Database accordingly crimes_database = databases_utils.filter_db_by_timeframe(crimes_database) # Ask for user to choose one or more types of crime and filter the Database accordingly crimes_database = databases_utils.filter_db_by_crime(crimes_database) # Create an instance of the CrimesDataFrame class with the filtered Database. This class is in charge of Statistics crimes_database = CrimesDataFrame(crimes_database) # Create lists to save addresses and addresses names of interest user_addresses = [] user_addresses_names = [] # Create interface Options interface_options = [ 'Add another address', 'Delete saved address', 'View saved address', 'Comparative analysis', 'Quit' ] option = 'Add another address' # Main loop of the program. It will ask for user input and show maps and analyses until 'Quit' is introduced while 1: if (not user_addresses) or option == 'Add another address': try: # Create an instance of Address class. It will ask user to input an address, validate it through # Google Maps, and calculate/save several attributes of that address. address = Address() except NoInternetAccess: print('No Internet connection found') if interface_utils.yesno_question('Continue?'): address = None # Continue with the normal loop without saving the address else: raise QuitProgram # Create a District Heat Map with maps_builder class and show it. if address: interface_utils.computing_statistics_message() address.summary = address_analysis(crimes_database, address) address_analysis_output(address, crimes_database) # User will have the option to save/discard the address after reviewing the Map and Statistics. if interface_utils.yesno_question( 'Keep this address for comparative analysis?'): if len(user_addresses) == MAX_ADDRESSES: print 'Maximum number of addresses to save reached, delete one location before adding a new address' else: if address not in user_addresses: user_addresses.append(address) user_addresses_names.append(address.formatted_address) # This option will allow the user to review the Map and Stats of an address that was saved. elif option == 'View saved address': option = interface_utils.get_options_from_user( user_addresses_names + ['Back'], multiple=False) if option != 'Back': address = user_addresses[user_addresses_names.index(option)] interface_utils.computing_statistics_message() address_analysis_output(address, crimes_database) # This option will allow the user to delete one of the saved addresses. elif option == 'Delete saved address': option = interface_utils.get_options_from_user( user_addresses_names + ['Back'], multiple=False) if option != 'Back': user_addresses.pop(user_addresses_names.index(option)) user_addresses_names.pop(user_addresses_names.index(option)) # This option will create a comparative Map and statistics to analyze and compare the saved addresses. elif option == 'Comparative analysis': comparative_analysis_output(crimes_database, user_addresses) # This option is the only way to end the loop and finish the program elif option == 'Quit': raise QuitProgram # If user_addresses is empty start the loop again directly to ask for an address # If there are addresses in user_addresses, offer options on how to continue if user_addresses: option = interface_utils.get_options_from_user(interface_options, multiple=False)
def setUp(self): self.good_address = Address('4334 W Washington Blv') self.data = pd.read_csv('./tests/csv_for_test.csv')