Add qualtrics_code to District and School

This commit is contained in:
Alex Basson 2021-09-20 16:15:32 -04:00
parent 12415861c1
commit 8fc6fae16b
7 changed files with 239 additions and 11 deletions

View file

@ -0,0 +1,5 @@
class AddQualtricsCodeToDistricts < ActiveRecord::Migration[5.0]
def change
add_column :districts, :qualtrics_code, :integer
end
end

View file

@ -0,0 +1,5 @@
class AddQualtricsCodeToSchools < ActiveRecord::Migration[5.0]
def change
add_column :schools, :qualtrics_code, :integer
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20210920175116) do
ActiveRecord::Schema.define(version: 20210920194221) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -51,9 +51,10 @@ ActiveRecord::Schema.define(version: 20210920175116) do
create_table "districts", force: :cascade do |t|
t.string "name"
t.integer "state_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.integer "qualtrics_code"
t.index ["slug"], name: "index_districts_on_slug", unique: true, using: :btree
end
@ -185,12 +186,13 @@ ActiveRecord::Schema.define(version: 20210920175116) do
create_table "schools", force: :cascade do |t|
t.string "name"
t.integer "district_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description"
t.string "slug"
t.integer "student_count"
t.integer "teacher_count"
t.integer "qualtrics_code"
t.index ["slug"], name: "index_schools_on_slug", unique: true, using: :btree
end

View file

@ -1,7 +1,30 @@
require 'csv'
csv_file = File.read(Rails.root.join('data', '2021-measure-key.csv'))
CSV.parse(csv_file, headers: true).each do |row|
qualtrics_district_and_school_code_key = File.read(Rails.root.join('data', 'qualtrics_district_and_school_code_key.csv'))
CSV.parse(qualtrics_district_and_school_code_key, headers: true).each do |row|
district_name = row['District']
district_code = row['District Code']
school_name = row['School Name']
school_code = row['School Code']
school_slug = school_name.parameterize
district = District.find_by_name(district_name)
if district.nil?
District.create name: district_name, qualtrics_code: district_code, slug: district_name.parameterize, state_id: 1
else
district.update(qualtrics_code: district_code) if district.qualtrics_code.nil?
end
school = School.find_by_slug(school_slug)
if school.nil?
School.create district: district, name: school_name, qualtrics_code: school_code, slug: school_slug
else
school.update(qualtrics_code: school_code) if school.qualtrics_code.nil?
end
end
measure_key_2021 = File.read(Rails.root.join('data', '2021-measure-key.csv'))
CSV.parse(measure_key_2021, headers: true).each do |row|
next if row['Source'] == 'Admin Data'
category_name = row['Category']