mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
data migration and rake task for nonlikert categories
This commit is contained in:
parent
5ebb5de439
commit
24d442497a
3 changed files with 29 additions and 40 deletions
|
|
@ -0,0 +1,8 @@
|
|||
class AddNonLikertFieldsToCategory < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :categories, :benchmark, :float
|
||||
add_column :categories, :benchmark_description, :string
|
||||
|
||||
add_column :school_categories, :nonlikert, :float
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20171028181758) do
|
||||
ActiveRecord::Schema.define(version: 20180119145356) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
|
@ -39,9 +39,11 @@ ActiveRecord::Schema.define(version: 20171028181758) do
|
|||
t.text "description"
|
||||
t.string "external_id"
|
||||
t.integer "parent_category_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.float "benchmark"
|
||||
t.string "benchmark_description"
|
||||
t.index ["slug"], name: "index_categories_on_slug", unique: true, using: :btree
|
||||
end
|
||||
|
||||
|
|
@ -144,6 +146,7 @@ ActiveRecord::Schema.define(version: 20171028181758) do
|
|||
t.integer "answer_index_total", default: 0
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.float "nonlikert"
|
||||
t.index ["category_id"], name: "index_school_categories_on_category_id", using: :btree
|
||||
t.index ["school_id"], name: "index_school_categories_on_school_id", using: :btree
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,59 +17,37 @@ namespace :data do
|
|||
task load_categories: :environment do
|
||||
measures = JSON.parse(File.read(File.expand_path('../../../data/measures.json', __FILE__)))
|
||||
measures.each_with_index do |measure, index|
|
||||
category = Category.create(
|
||||
name: measure['title'],
|
||||
category = Category.create_with(
|
||||
blurb: measure['blurb'],
|
||||
description: measure['text'],
|
||||
external_id: measure['id'] || index + 1
|
||||
)
|
||||
).find_or_create_by(name: measure['title'])
|
||||
|
||||
measure['sub'].keys.sort.each do |key|
|
||||
subinfo = measure['sub'][key]
|
||||
subcategory = category.child_categories.create(
|
||||
name: subinfo['title'],
|
||||
subcategory = category.child_categories.create_with(
|
||||
blurb: subinfo['blurb'],
|
||||
description: subinfo['text'],
|
||||
external_id: key
|
||||
)
|
||||
).find_or_create_by(name: subinfo['title'])
|
||||
|
||||
subinfo['measures'].keys.sort.each do |subinfo_key|
|
||||
subsubinfo = subinfo['measures'][subinfo_key]
|
||||
subsubcategory = subcategory.child_categories.create(
|
||||
name: subsubinfo['title'],
|
||||
subsubcategory = subcategory.child_categories.create_with(
|
||||
blurb: subsubinfo['blurb'],
|
||||
description: subsubinfo['text'],
|
||||
external_id: subinfo_key
|
||||
)
|
||||
).find_or_create_by(name: subsubinfo['title'])
|
||||
|
||||
# if subsubinfo['nonlikert'].present?
|
||||
# subsubinfo['nonlikert'].each do |nonlikert_info|
|
||||
# next unless nonlikert_info['likert'].present?
|
||||
# nonlikert = subsubcategory.child_measures.create(
|
||||
# name: nonlikert_info['title'],
|
||||
# description: nonlikert_info['benchmark_explanation'],
|
||||
# benchmark: nonlikert_info['benchmark']
|
||||
# )
|
||||
#
|
||||
# name_map = {
|
||||
# "argenziano": "dr-albert-f-argenziano-school-at-lincoln-park",
|
||||
# "healey": "arthur-d-healey-school",
|
||||
# "brown": "benjamin-g-brown-school",
|
||||
# "east": "east-somerville-community-school",
|
||||
# "kennedy": "john-f-kennedy-elementary-school",
|
||||
# "somervillehigh": "somerville-high-school",
|
||||
# "west": "west-somerville-neighborhood-school",
|
||||
# "winter": "winter-hill-community-innovation-school"
|
||||
# }
|
||||
#
|
||||
# nonlikert_info['likert'].each do |key, likert|
|
||||
# school_name = name_map[key.to_sym]
|
||||
# next if school_name.nil?
|
||||
# school = School.friendly.find(school_name)
|
||||
# nonlikert.measurements.create(school: school, likert: likert, nonlikert: nonlikert_info['values'][key])
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
if subsubinfo['nonlikert'].present?
|
||||
subsubinfo['nonlikert'].each do |nonlikert_info|
|
||||
puts("NONLIKERT FOUND: #{nonlikert_info['title']}")
|
||||
nonlikert = subsubcategory.child_categories.create_with(
|
||||
benchmark_description: nonlikert_info['benchmark_explanation'],
|
||||
benchmark: nonlikert_info['benchmark']
|
||||
).find_or_create_by(name: nonlikert_info['title'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue