Skip to content

Instantly share code, notes, and snippets.

@stevepaulo
Created October 23, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevepaulo/bc2dce7a4ae6549750761006918aa00f to your computer and use it in GitHub Desktop.
Save stevepaulo/bc2dce7a4ae6549750761006918aa00f to your computer and use it in GitHub Desktop.
Chadwick Bureau Register tasks for STOMPER Projections
namespace :chadwick do
desc "Download latest Chadwick Bureau Register"
task download: :environment do
sh "wget https://github.com/chadwickbureau/register/blob/master/data/people.csv?raw=true -O ./data/people.csv"
end
desc "Prepare Chadwick CSV for use in STOMPER"
task prep_csv: :environment do
input = "data/people.csv"
output = "data/chadwick.csv"
CSV.open(output, "w") do |writer|
writer << ["first_name", "last_name", "mlb_key", "birthdate"]
CSV.foreach(input, headers: true) do |row|
next unless
row["key_mlbam"].present? &&
(row["pro_played_last"] == "2020" || row["pro_played_last"] == "2019" || row["pro_played_last"] == "2018") &&
(row["birth_month"].present? && row["birth_day"].present? && row["birth_year"].present?)
writer << [row["name_first"], row["name_last"], row["key_mlbam"], "#{row["birth_month"]}/#{row["birth_day"]}/#{row["birth_year"]}"]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment