Created
October 23, 2020 20:06
-
-
Save stevepaulo/bc2dce7a4ae6549750761006918aa00f to your computer and use it in GitHub Desktop.
Chadwick Bureau Register tasks for STOMPER Projections
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
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