def get_lower_bins(lower_left, lower_right, NUM_BINS): lower_bins = [] dist = helpers.find_distance(lower_left, lower_right) bin_width = dist / NUM_BINS slope = helpers.find_slope(lower_left, lower_right) x = lower_left[0] for binno in range(NUM_BINS): bin_y = lower_left[1] + (slope * x) lower_bins.append( (x, bin_y) ) x += bin_width return lower_bins
def search(): """Buyer can search parameters for storage""" # Render template if (request.method == "GET"): return render_template("search.html") if (request.method == "POST"): # Get inputs street = request.form.get("street") city = request.form.get("city") state = request.form.get("state") zip = request.form.get("zip") miles = request.form.get("miles") space = request.form.get("space") start = request.form.get("start") end = request.form.get("end") # Return apology if missing entries if not city: return apology("You must enter your city.") if not state: return apology("You must enter your state.") if not zip: return apology("You must enter your zip code.") if not miles: return apology("You must enter the range.") if not space: return apology("You must enter the number of boxes.") if not start: return apology("You must enter the start date.") if not end: return apology("You must enter the end date.") # format the user's location loc_1 = street + ', ' + city + ', ' + state + ', ' + zip # find their prefered range in meters (1609.34 is the conversion rate) meters = 1609.34 * float(miles) # make a list of the of all listings listings = db.execute('SELECT * FROM listings') # make a list of of viable listings viable_listings = [] # find which listings are within physical range for listing in listings: # format the location loc_2 = listing['street'] + ', ' + listing[ 'city'] + ', ' + listing['state'] + ', ' + listing['zip'] # find the distances distance_dict = find_distance(loc_1, loc_2) distance_text = distance_dict['text'] # str in metric units distance_value = distance_dict['value'] # int in meters # check if the listing is viable, if so add it to list if (distance_value <= meters) and (int(space) <= int( listing['space'])) and (check_dates( start, end, listing['start'], listing['end'])): # add distance to the listing listing['distance'] = distance_text # add listing to list of viable listings viable_listings.append(listing) # order the list of viable listings by price final_listings = sorted(viable_listings, key=lambda k: k['price']) # add names to the list final listings for listing in final_listings: listing['username'] = db.execute( 'SELECT username FROM users WHERE user_id=:user_id', user_id=listing['user_id'])[0]['username'] # redirect to search results return render_template("search_results.html", final_listings=final_listings, loc_1=loc_1)
def unique(good_points, point, width): for p in good_points: if helpers.find_distance(point, p) < width: return False return True