Skip to content

Instantly share code, notes, and snippets.

@nilbus
Created July 29, 2011 15:28
Show Gist options
  • Save nilbus/1114042 to your computer and use it in GitHub Desktop.
Save nilbus/1114042 to your computer and use it in GitHub Desktop.
# Import the college board schools
imported_schools = import_from(dat_file)
# Find schools matching CBIDs, combine ones with the same CBID, and update that school's data
for each college_board_school in imported_schools:
matching_robertson_schools = find_schools_by_cbid(college_board_school.cbid) # There are sometimes several that match a CBID
keeper_school = matching_robertson_schools.first
keeper_school.update_info_using(college_board_school)
duplicate_schools = matching_robertson_schools[1..-1]
for each duplicate in duplicate_schools:
replace_school(duplicate, keeper_school)
# Clear out CBIDs that don't exist
real_cbids = imported_schools.map(:cbid)
for each school in all_robertson_schools:
unless real_cbids.includes(school.cbid):
school.cbid = null
# Match up duplicate high schools that had no CBID entered
schools_without_cbid = all_robertson_schools.where('cbid is blank')
for each school in schools_without_cbid:
matching_college_board_school = imported_schools.find_where:
school.name == imported_school.name
school.state == imported_school.state
school.city == imported_school.city
# Other required match criteria? I think this is sufficient, or we may have more false negatives
if exists(matching_college_board_school):
replace_school(shcool, matching_college_board_school)
function replace_school(duplicate, replacement):
# A user_high_school is created for each high school attended by an applicant. Its fields include the dates and school attended.
user_high_schools_referencing_this_duplicate = duplicate.user_high_schools
for each user_high_school in user_high_schools_referencing_this_duplicate:
user_high_school.high_school = replacement
duplicate.delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment