mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
adding SchoolQuestion
This commit is contained in:
parent
559cd103f9
commit
819ff49c63
8 changed files with 117 additions and 6 deletions
2
Gemfile
2
Gemfile
|
|
@ -52,7 +52,7 @@ gem 'omniauth'
|
|||
|
||||
gem 'twilio-ruby', '~> 4.11.1'
|
||||
|
||||
|
||||
gem 'activerecord-import'
|
||||
|
||||
group :development, :test do
|
||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ GEM
|
|||
activemodel (= 5.0.7)
|
||||
activesupport (= 5.0.7)
|
||||
arel (~> 7.0)
|
||||
activerecord-import (0.27.0)
|
||||
activerecord (>= 3.2)
|
||||
activesupport (5.0.7)
|
||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||
i18n (>= 0.7, < 2)
|
||||
|
|
@ -250,6 +252,7 @@ PLATFORMS
|
|||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord-import
|
||||
bootstrap (~> 4.0.0.alpha6)
|
||||
byebug
|
||||
capybara
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ class School < ApplicationRecord
|
|||
friendly_id :name, :use => [:slugged]
|
||||
|
||||
def available_responders_for(question)
|
||||
if question.target_group == "for_students"
|
||||
if question.for_students?
|
||||
return student_count || 1
|
||||
elsif question.target_group == "for_teachers"
|
||||
elsif question.for_teachers?
|
||||
return teacher_count || 1
|
||||
else
|
||||
return 1
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ class SchoolCategory < ApplicationRecord
|
|||
belongs_to :school
|
||||
belongs_to :category
|
||||
|
||||
has_many :school_questions
|
||||
|
||||
validates_associated :school
|
||||
validates_associated :category
|
||||
|
||||
|
|
|
|||
13
app/models/school_question.rb
Normal file
13
app/models/school_question.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class SchoolQuestion < ApplicationRecord
|
||||
|
||||
belongs_to :school
|
||||
belongs_to :question
|
||||
belongs_to :school_category
|
||||
|
||||
validates_associated :school
|
||||
validates_associated :question
|
||||
validates_associated :school_category
|
||||
|
||||
scope :for, -> (school, question) { where(school_id: school.id, question_id: question.id) }
|
||||
|
||||
end
|
||||
18
db/migrate/20181218154720_add_school_questions.rb
Normal file
18
db/migrate/20181218154720_add_school_questions.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class AddSchoolQuestions < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :school_questions do |t|
|
||||
t.integer :school_id
|
||||
t.integer :question_id
|
||||
t.integer :school_category_id
|
||||
t.integer :attempt_count
|
||||
t.integer :response_count
|
||||
t.float :response_rate
|
||||
t.string :year
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_column :school_categories, :valid_child_count, :integer
|
||||
add_column :school_categories, :response_rate, :integer
|
||||
end
|
||||
end
|
||||
22
db/schema.rb
22
db/schema.rb
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20180711164051) do
|
||||
ActiveRecord::Schema.define(version: 20181218154720) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
|
@ -152,17 +152,33 @@ ActiveRecord::Schema.define(version: 20180711164051) do
|
|||
t.float "nonlikert"
|
||||
t.float "zscore"
|
||||
t.string "year"
|
||||
t.integer "valid_child_count"
|
||||
t.integer "response_rate"
|
||||
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
|
||||
|
||||
create_table "school_questions", force: :cascade do |t|
|
||||
t.integer "school_id"
|
||||
t.integer "question_id"
|
||||
t.integer "school_category_id"
|
||||
t.integer "attempt_count"
|
||||
t.integer "response_count"
|
||||
t.float "response_rate"
|
||||
t.string "year"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
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.index ["slug"], name: "index_schools_on_slug", unique: true, using: :btree
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -501,3 +501,62 @@ end
|
|||
# puts ""
|
||||
# puts "MISSING SCHOOLS: #{missing_schools.length}"
|
||||
# missing_schools.each { |s| puts(s) }
|
||||
#
|
||||
#
|
||||
# Category.joins(:questions).uniq.all.each do |category|
|
||||
# category.school_categories.includes(school: [:district]).find_in_batches(batch_size: 100) do |group|
|
||||
# group.each do |school_category|
|
||||
# school_questions = []
|
||||
#
|
||||
# category.questions.created_in(school_category.year).each do |question|
|
||||
# school = school_category.school
|
||||
# next if school.district.name != "Boston"
|
||||
# attempt_count = Attempt.
|
||||
# created_in(school_category.year).
|
||||
# for_question(question).
|
||||
# for_school(school).count
|
||||
#
|
||||
# available_responders = school.available_responders_for(question)
|
||||
# school_questions << school_category.school_questions.new(
|
||||
# school: school,
|
||||
# question: question,
|
||||
# school_category: school_category,
|
||||
# year: school_category.year,
|
||||
# attempt_count: available_responders,
|
||||
# response_count: attempt_count,
|
||||
# response_rate: attempt_count.to_f / available_responders.to_f
|
||||
# )
|
||||
# end
|
||||
#
|
||||
# SchoolQuestion.import school_questions
|
||||
# valid_questions = school_questions.select { |sc| sc.response_rate > 0.3 }
|
||||
# school_category.update(
|
||||
# valid_child_count: valid_questions.length
|
||||
# )
|
||||
# end
|
||||
#
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# loop do
|
||||
# categories = Category.joins(:school_categories)
|
||||
# .merge(SchoolCategory.where("valid_child_count is not null"))
|
||||
# .uniq
|
||||
# break if categories.count == 0
|
||||
# categories.all.each do |category|
|
||||
# parent_category = category.parent_category
|
||||
#
|
||||
# parent_category.school_categories.find_in_batches(batch_size: 100) do |group|
|
||||
# group.each do |school_category|
|
||||
# next if school_category.valid_child_count.present?
|
||||
#
|
||||
# school = school_category.school
|
||||
# children = SchoolCategory.for_parent_category(school, parent_category).in(school_category.year)
|
||||
# school_category.update(
|
||||
# valid_child_count: children.where("valid_child_count > 1").count
|
||||
# )
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue