def getCoordinates(): coordinates = read_pickle('processed_data/completeSeverity1.pickle') for i in range(2, 4): print(i) filename = 'processed_data/completeSeverity{}.pickle'.format(i) tempDict = read_pickle(filename) print(type(coordinates), type(tempDict)) coordinates = z = {**coordinates, **tempDict} print(type(coordinates)) return coordinates
def add_coordinates(filename): results = read_pickle(filename) limit = 0 for i in results: print('num=', limit) address = results[i]['address'] coordinates = results[i]['location'] if len(coordinates) < 1: try: location = geolocator.geocode(address) if location is not None: print(location.latitude, location.longitude) results[i]['location'] = [ location.latitude, location.longitude ] else: results[i]['location'] = [0, 0] except: results[i]['location'] = [0, 0] pass time.sleep(0.5) #if limit > 49: # break limit += 1 return results
def add_fake_coordinates(filename): results = read_pickle(filename) limit = 0 for i in results: results[i]['lat'] = 42.2932 + limit * .001 results[i]['lon'] = -71.2637 limit += 1 return results
def generate_severityDictionary(severityLevel, color): filename = 'processed_data/completeSeverity{}.pickle'.format(severityLevel) colorname = 'processed_data/severity{}_violation_percentage.pickle'.format( severityLevel) results = read_pickle(filename) rating = getRatings() data = dict(lat=[], lon=[], color=[], name=[], rating=[]) limit = 0 for name in results: data['lat'].append(results[name]['location'][0]) data['lon'].append(results[name]['location'][1]) data['color'].append(color) data['name'].append(name) data['rating'].append(rating[name]) limit += 1 return data
def generate_mainDictionary(filename): results = read_pickle(filename) coordinates = getCoordinates() rating = getRatings() data = dict(lat=[], lon=[], color=[], name=[], rating=[]) limit = 0 for name in results: red, green, blue = results[name]['color'][0], results[name]['color'][ 1], results[name]['color'][2] data['lat'].append(coordinates[name]['location'][0]) data['lon'].append(coordinates[name]['location'][1]) data['color'].append(RGB(red, green, blue)) data['name'].append(name) data['rating'].append(rating[name]) limit += 1 return data
def get_food_type(api_key, search_limit, filename): """Return the food type for each restaurant and store it in a dictionary.""" data = read_pickle(filename) for restaurant in data: yelp_foodtype = get_restaurant_food_type(restaurant, data[restaurant]['address']) #print(yelp_foodtype) if yelp_foodtype == None: data[restaurant]['foodtype'] = 'None' else: if yelp_foodtype['categories'] == []: data[restaurant]['foodtype'] = 'None' else: data[restaurant]['foodtype'] = yelp_foodtype['categories'][0][ 'title'] print(data[restaurant]['foodtype']) #print(data[restaurant]['foodtype']) return data
def generate_foodtypeDictionary(filename, foodtype, color): results = read_pickle(filename) coordinates = getCoordinates() rating = getRatings() data = dict(lat=[], lon=[], color=[], name=[], rating=[], foodtype=[]) limit = 0 for name in results: if results[name]['foodtype'] == foodtype: try: data['lat'].append(coordinates[name]['location'][0]) data['lon'].append(coordinates[name]['location'][1]) except: data['lat'].append(0) data['lon'].append(0) data['color'].append(color) data['name'].append(name) data['rating'].append(rating[name]) data['foodtype'].append(foodtype) limit += 1 return data
def getRatings(): ratings = read_pickle('processed_data/rating.pickle') return ratings