Beispiel #1
0
def calculate_census_block(address):
    '''
    Calculates the census block of a given address
    '''
    coords = cbt.addr_to_coords(ADDRESS_URL, address)
    rv = cbt.visit_pages(URL, coords)
    return coords, rv
Beispiel #2
0
def find_building(building_dict, address, building_type, building_subtype):
    """
    LEGACY CODE -- Not used in final project. Some complications 
    emerged since it was difficult to find a single building using
    the above search. This code is incomplete.

    Given an address, building type, and building subtype,
    the appropriate row from the City of Chicago data is selected.
    """

    coords = coords_to_block.addr_to_coords(coords_to_block.address_url, address)   
    census_block = coords_to_block.visit_pages(coords_to_block.url,coords)

    matches = building_dict[str(census_block)]

    for match in matches:
        print(match)

        for key in match.keys():
            print(key)
            print(key == building_type)
            if key == building_type:
                value = match[key]
                print(value) 
                for key2 in value.keys():
                    if key2 == building_subtype:
                        ans = match[building_type][building_subtype]
                    else:
                        break

    return ans
Beispiel #3
0
def find_nearest(address, address_url, url_list):
    """
    Finds the nearest alternative fuel station based on a
    given address. Returns a list with information on 
    the  alternative fuel station and the distance in km
    between the station and the address.
    """
    shortest_distance = 10000
    fuel_station = ''
    fuel_list = visit_alt_fuel_pages(url_list)

    coords = coords_to_block.addr_to_coords(address_url, address)
    for station in fuel_list:

        check_distance = distance(float(coords[0]),float(coords[1]),float(fuel_list[station][3]),float(fuel_list[station][4]))

        if shortest_distance > check_distance:
            shortest_distance = check_distance
            fuel_station = fuel_list[station]

    return fuel_station + [shortest_distance]        
Beispiel #4
0
def find_nearest(address, address_url, url_list):
    """
    Finds the nearest alternative fuel station based on a
    given address. Returns a list with information on 
    the  alternative fuel station and the distance in km
    between the station and the address.
    """
    shortest_distance = 10000
    fuel_station = ''
    fuel_list = visit_alt_fuel_pages(url_list)

    coords = coords_to_block.addr_to_coords(address_url, address)
    for station in fuel_list:

        check_distance = distance(float(coords[0]), float(coords[1]),
                                  float(fuel_list[station][3]),
                                  float(fuel_list[station][4]))

        if shortest_distance > check_distance:
            shortest_distance = check_distance
            fuel_station = fuel_list[station]

    return fuel_station + [shortest_distance]