Created
February 23, 2015 22:52
-
-
Save nblackburn87/91cb03a9b879a878d38c to your computer and use it in GitHub Desktop.
Quick Code for Ada Eval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
csv_text = File.read('farmers-markets.csv') | |
csv = CSV.parse(csv_text, headers: true) | |
final_csv = csv.map { |row| row.to_hash } | |
def veggies_not_meat(final_csv) | |
count = 0 | |
final_csv.each do |row| | |
if row['Vegetables'] == "Y" && row['Meat'] == "N" | |
unless row['County'] && row['County'][0] == "P" | |
count += 1 | |
end | |
end | |
end | |
print "Markets with Veggies and not Meat: #{count}" "\n" | |
end | |
def public_land_max(final_csv) | |
count = 0 | |
final_csv.each do |row| | |
if row['Location'] == "Local government building grounds" || row['Location'] == "Closed-off public street" || row['Location'] == "Federal/State government building grounds" || row['Location'] == "Other" | |
unless row['County'] && row['County'][0] == "P" | |
count += 1 | |
end | |
end | |
end | |
print "Max number of markets on public land: #{count}" "\n" | |
end | |
def public_land_min(final_csv) | |
count = 0 | |
final_csv.each do |row| | |
if row['Location'] == "Closed-off public street" | |
unless row['County'] && row['County'][0] == "P" | |
count += 1 | |
end | |
end | |
end | |
print "Min number of markets on public land: #{count}" "\n" | |
end | |
def lat_long_search(final_csv) | |
count = 0 | |
final_csv.each do |row| | |
if row['Latitude'].to_f >= 40.7737 && row['Latitude'].to_f <= 47.608858 | |
if row['Longitude'].to_f >= -122.333392 && row['Longitude'].to_f <= -73.9501 | |
unless row['County'] && row['County'][0] == "P" | |
count += 1 | |
end | |
end | |
end | |
end | |
print "Number of markets located inside given lat/long #{count}" "\n" | |
end | |
veggies_not_meat(final_csv) | |
public_land_min(final_csv) | |
public_land_max(final_csv) | |
lat_long_search(final_csv) | |
http://application.adadevelopersacademy.org/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment