<commit_before>require 'faker'
require 'httparty'
require 'json'
require 'csv'
require 'awesome_print'

# # ------------------ Original Hard-coded seeds --------------------

	# addresses = ["5001 POWERS FERRY RD Atlanta, GA 30327", "427 COCHRAN DR ATLANTA, GA 30327", "950 Davis Dr NW Atlanta, GA"]

	# lat_lngs = []
	# addresses.each do |address|
	# 	temp = []
	# 	url = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address.gsub(/\s+/, "")}"
	# 	response = HTTParty.get(url).to_json
	# 	response = JSON.parse(response)
	# 	temp << response["results"][0]["geometry"]["location"]["lat"] << response["results"][0]["geometry"]["location"]["lng"]
	# 	lat_lngs << temp
	# end

	# --- Potentially can expand on the below later to store hometoschool in the DB ---

	# addresses_shortened.each do |address|
	# 	hs_url = "https://maps.googleapis.com/maps/api/directions/json?origin=#{}&destination=#{}&key=<KEY>"
	# 	hs_response = HTTParty.get(hs_url).to_json
	# 	hs_response = JSON.parse(hs_response)
	# end

	# --- Seeds with 10 data points ---

	# ten_surnames = %w[<NAME> <NAME> <NAME> Washington Jefferson]

	# ten_usernames = %w[anders chest123 warren345 jones123 johnson999 carson567 reed12 hamilton333 washington888 jefferson444]

	# --- Seeds with 3 data points ---

	# three_surnames = %w[<NAME>]

	# three_usernames = %w[anders chest123 warren345]

	# lats = [33.8907, 33.8865, 33.8843]
	# longs = [-84.4113, -84.4172, -84.4067]
	# [-84.4113, 33.8907], [-84.4172, 33.8865], [-84.4067, 33.8843]

	# three_phones = []
	# three_emails = []
	# 3.times do
	# 	three_phones << Faker::PhoneNumber.cell_phone
	# 	three_emails << Faker::Internet.email
	# end

	# for i in 0..2
	# 	Family.create(last_name: three_surnames[i], username: three_usernames[i], password: "<PASSWORD>", lat: lat_lngs[i][0], address: addresses[i], lng: lat_lngs[i][1], phone: three_phones[i], email: three_emails[i])
	# end

# ------------------------ Google Maps Version ----------------------

	# def addressToCoordsGoogleMaps(address)
	# 	coords = []
	# 	url = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address.gsub(/\s+/, "")}"
	# 	response = HTTParty.get(url).to_json
	# 	response = JSON.parse(response)
	# 	coords << response["results"][0]["geometry"]["location"]["lat"] << response["results"][0]["geometry"]["location"]["lng"]
	# 	return coords
	# 	# return [33, -84]
	# end

	# def addressGetLngGoogleMaps(address)
	# 	url = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address.gsub(/\s+/, "")}"
	# 	response = HTTParty.get(url).to_json
	# 	response = JSON.parse(response)
	# 	lng = response["results"][0]["geometry"]["location"]["lng"]
	# 	return lng
	# end
	# def addressGetLatGoogleMaps(address)
	# 	url = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address.gsub(/\s+/, "")}"
	# 	response = HTTParty.get(url).to_json
	# 	response = JSON.parse(response)
	# 	lat = response["results"][0]["geometry"]["location"]["lat"]
	# 	p lat
	# end

# def addressToMapboxFormat(address)
# 	return address.gsub(/\s+/, "+")
# end

# def addressToCoordinates(address)
# 	response = JSON.parse(HTTParty.get("http://api.tiles.mapbox.com/v4/geocode/mapbox.places/#{address}.json?access_token=<KEY>"))
# 	if response["features"] != []
# 		return response["features"][0]["geometry"]["coordinates"]
# 	else
# 		return "error"
# 	end
# end

# file = File.join(Rails.root, 'lib', 'assets', 'AIS.csv')

# # ---------- For use with "test2.csv" ------------

# CSV.foreach(file, :headers => true) do |row|
#   fullAddress = row[3] + " " + row[4] + " " + row[5] + " " + row[6]
#   addressFormatted = addressToMapboxFormat(fullAddress)
#   coordinates = addressToCoordinates(addressFormatted)
#   if coordinates != "error"
#   	Family.create(last_name: row[1], username: row[1].downcase + "123", password: "<PASSWORD>", address: fullAddress, lat: coordinates[1], lng: coordinates[0], phone: Faker::PhoneNumber.cell_phone, email: Faker::Internet.email)
#   else
#   	p "Error with #{row[1]} family."
#   end
# end

# ------------- Add home-school time/distance to DB ---------------

Family.where("id > ?", 9).each do |family|
	home_coords = []
	home_coords << family.lng << family.lat
	school_coords = [-84.378611, 33.833333]

	hs_url = "https://maps.googleapis.com/maps/api/directions/json?origin=#{home_coords[1]},#{home_coords[0]}&destination=#{school_coords[1]},#{school_coords[0]}&key=<KEY>"
	hs_response = HTTParty.get(hs_url).to_json
	hs_response = JSON.parse(hs_response)

	family.hs_time = hs_response["routes"][0]["legs"][0]["duration"]["value"]
	family.hs_distance = hs_response["routes"][0]["legs"][0]["distance"]["value"].meters_to_miles
	family.save
end

# -----------------------------------------------------------------

# ---- Hack to separate address into line_1 and line_2 ------------<commit_msg>change to seedfile<commit_after>require 'faker'
require 'httparty'
require 'json'
require 'csv'
require 'awesome_print'

# # ------------------ Original Hard-coded seeds --------------------

	# addresses = ["5001 POWERS FERRY RD Atlanta, GA 30327", "427 COCHRAN DR ATLANTA, GA 30327", "950 Davis Dr NW Atlanta, GA"]

	# lat_lngs = []
	# addresses.each do |address|
	# 	temp = []
	# 	url = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address.gsub(/\s+/, "")}"
	# 	response = HTTParty.get(url).to_json
	# 	response = JSON.parse(response)
	# 	temp << response["results"][0]["geometry"]["location"]["lat"] << response["results"][0]["geometry"]["location"]["lng"]
	# 	lat_lngs << temp
	# end

	# --- Potentially can expand on the below later to store hometoschool in the DB ---

	# addresses_shortened.each do |address|
	# 	hs_url = "https://maps.googleapis.com/maps/api/directions/json?origin=#{}&destination=#{}&key=<KEY>"
	# 	hs_response = HTTParty.get(hs_url).to_json
	# 	hs_response = JSON.parse(hs_response)
	# end

	# --- Seeds with 10 data points ---

	# ten_surnames = %w[<NAME> <NAME>erson]

	# ten_usernames = %w[anders chest123 warren345 jones123 johnson999 carson567 reed12 hamilton333 washington888 jefferson444]

	# --- Seeds with 3 data points ---

	# three_surnames = %w[<NAME>]

	# three_usernames = %w[anders chest123 warren345]

	# lats = [33.8907, 33.8865, 33.8843]
	# longs = [-84.4113, -84.4172, -84.4067]
	# [-84.4113, 33.8907], [-84.4172, 33.8865], [-84.4067, 33.8843]

	# three_phones = []
	# three_emails = []
	# 3.times do
	# 	three_phones << Faker::PhoneNumber.cell_phone
	# 	three_emails << Faker::Internet.email
	# end

	# for i in 0..2
	# 	Family.create(last_name: three_surnames[i], username: three_usernames[i], password: "<PASSWORD>", lat: lat_lngs[i][0], address: addresses[i], lng: lat_lngs[i][1], phone: three_phones[i], email: three_emails[i])
	# end

# ------------------------ Google Maps Version ----------------------

	# def addressToCoordsGoogleMaps(address)
	# 	coords = []
	# 	url = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address.gsub(/\s+/, "")}"
	# 	response = HTTParty.get(url).to_json
	# 	response = JSON.parse(response)
	# 	coords << response["results"][0]["geometry"]["location"]["lat"] << response["results"][0]["geometry"]["location"]["lng"]
	# 	return coords
	# 	# return [33, -84]
	# end

	# def addressGetLngGoogleMaps(address)
	# 	url = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address.gsub(/\s+/, "")}"
	# 	response = HTTParty.get(url).to_json
	# 	response = JSON.parse(response)
	# 	lng = response["results"][0]["geometry"]["location"]["lng"]
	# 	return lng
	# end
	# def addressGetLatGoogleMaps(address)
	# 	url = "https://maps.googleapis.com/maps/api/geocode/json?address=#{address.gsub(/\s+/, "")}"
	# 	response = HTTParty.get(url).to_json
	# 	response = JSON.parse(response)
	# 	lat = response["results"][0]["geometry"]["location"]["lat"]
	# 	p lat
	# end

def addressToMapboxFormat(address)
	return address.gsub(/\s+/, "+")
end

def addressToCoordinates(address)
	response = JSON.parse(HTTParty.get("http://api.tiles.mapbox.com/v4/geocode/mapbox.places/#{address}.json?access_token=<KEY>"))
	if response["features"] != []
		return response["features"][0]["geometry"]["coordinates"]
	else
		return "error"
	end
end

file = File.join(Rails.root, 'lib', 'assets', 'AIS.csv')

# ---------- For use with "test2.csv" ------------

CSV.foreach(file, :headers => true) do |row|
  fullAddress = row[3] + " " + row[4] + " " + row[5] + " " + row[6]
  addressFormatted = addressToMapboxFormat(fullAddress)
  coordinates = addressToCoordinates(addressFormatted)
  if coordinates != "error"
  	Family.create(last_name: row[1], username: row[1].downcase + "123", password: "<PASSWORD>", address: fullAddress, lat: coordinates[1], lng: coordinates[0], phone: Faker::PhoneNumber.cell_phone, email: Faker::Internet.email)
  else
  	p "Error with #{row[1]} family."
  end
end

# ------------- Add home-school time/distance to DB ---------------

Family.each do |family|
	home_coords = []
	home_coords << family.lng << family.lat
	school_coords = [-84.378611, 33.833333]

	hs_url = "https://maps.googleapis.com/maps/api/directions/json?origin=#{home_coords[1]},#{home_coords[0]}&destination=#{school_coords[1]},#{school_coords[0]}&key=<KEY>"
	hs_response = HTTParty.get(hs_url).to_json
	hs_response = JSON.parse(hs_response)

	family.hs_time = hs_response["routes"][0]["legs"][0]["duration"]["value"]
	family.hs_distance = hs_response["routes"][0]["legs"][0]["distance"]["value"].meters_to_miles
	family.save
end

# -----------------------------------------------------------------

# ---- Hack to separate address into line_1 and line_2 ------------
{'fraction_non_alphanumeric': 0.22483046426708397, 'fraction_numerical': 0.03828899321857068, 'mean_word_length': 3.7667826951765293, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 23, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4456615', 'n_tokens_mistral': 3779, 'n_tokens_neox': 3582, 'n_words': 602}