forked from codeforamerica/schoolselection
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNOTES
48 lines (44 loc) · 2.23 KB
/
NOTES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
ogr2ogr -t_srs EPSG:4326 school_parcels_2012/ facility_parcels/BPS_schools.shp
ruby
require 'rgeo'
require 'rgeo/shapefile'
require 'rgeo/geo_json'
parcels = RGeo::Shapefile::Reader.open('../../Projects/SchoolSelection/Data/school_parcels_2012/facility_parcels.shp')
schools = RGeo::Shapefile::Reader.open('../../Projects/SchoolSelection/Data/school_parcels_2012/BPS_schools.shp')
schools_array = []
schools.each do |s|
schools_array << s
end
parcels.each do |parcel|
rails_parcel = Parcel.find_or_create_by_build_name_and_address_and_city_id_and_zipcode_and_shape(parcel.attributes['BLDG_NAME'], parcel.attributes['ADDRESS'], City.find_or_create_by_name(parcel.attributes['CITY'].try(:id)), parcel.attributes['ZIPCODE'], parcel.geometry)
bps_school = schools_array.find {|x| x.attributes['BLDG_ID'] == parcel.attributes['BUILD_ID']}
if bps_school.present?
rails_school = School.find_by_bpsid(bps_school.attributes['SCH_ID'])
rails_school.update_attribute(:parcel_id, rails_parcel.id) if rails_school.present?
end
end
# zones = RGeo::Shapefile::Reader.open('../../Projects/SchoolSelection/Data/assignment_zones/zones_4326')
# dbf_schools = DBF::Table.new('../../Projects/SchoolSelection/Data/school_parcels_2011/schools.dbf')
# georuby_parcels = GeoRuby::Shp4r::ShpFile.open('../../Projects/SchoolSelection/Data/school_parcels/school_parcels')
IMPORT SCHOOLS FROM 2011-2012 CSV
CSV.foreach("../../Projects/SchoolSelection/Data/Spreadsheets/CSV/admissions.csv") do |row|
if row[0].present?
city = City.find_or_create_by_name(row[5])
neighborhood = Neighborhood.find_or_create_by_name(row[7])
assignment_zone = AssignmentZone.find_or_create_by_name(row[8])
grades = row[13].split(/\b*-\b*/)
puts grades.inspect
start_grade = GradeLevel.find_by_number(grades[0])
end_grade = GradeLevel.find_by_number(grades[1])
puts [start_grade,end_grade].inspect
if start_grade.present? && end_grade.present?
grade_levels = GradeLevel.where("(id >= #{start_grade.id}) AND (id <= #{end_grade.id})").all
puts grade_levels.inspect
school = School.find_or_create_by_bpsid(row[1])
school.grade_levels << grade_levels
school.save
else
school = School.find_or_create_by_bpsid(row[1])
end
end
end