chore: seed framework

This commit is contained in:
Nelson Jovel 2024-01-11 17:55:01 -08:00
parent cd7b05df73
commit 27550e0b30
10 changed files with 83 additions and 82 deletions

View file

@ -6,7 +6,7 @@ module Dashboard
academic_years << { range: } academic_years << { range: }
end end
AcademicYear.insert_all(academic_years, unique_by: [:id]) AcademicYear.upsert_all(academic_years)
end end
def seed_districts_and_schools(csv_file) def seed_districts_and_schools(csv_file)
@ -30,7 +30,7 @@ module Dashboard
is_hs: marked?(hs), slug: school_name.parameterize } is_hs: marked?(hs), slug: school_name.parameterize }
end end
School.upsert_all(schools) School.insert_all(schools)
Respondent.joins(:school).where.not("school.dese_id": dese_ids).destroy_all Respondent.joins(:school).where.not("school.dese_id": dese_ids).destroy_all
School.where.not(dese_id: dese_ids).destroy_all School.where.not(dese_id: dese_ids).destroy_all
@ -93,7 +93,7 @@ module Dashboard
end end
end end
AdminDataValue.where.not(admin_data_item_id: admin_data_item_ids).delete_all AdminDataValue.where.not(admin_data_item: admin_data_item_ids).delete_all
AdminDataItem.where.not(id: admin_data_item_ids).delete_all AdminDataItem.where.not(id: admin_data_item_ids).delete_all
end end

View file

@ -1,7 +1,7 @@
module Dashboard module Dashboard
class AdminDataItem < ApplicationRecord class AdminDataItem < ApplicationRecord
belongs_to :dashboard_scale belongs_to :scale, class_name: "Scale", foreign_key: :dashboard_scale_id
has_many :dashboard_admin_data_values has_many :admin_data_values, class_name: "AdminDataValue", foreign_key: :dashboard_admin_data_item_id
scope :for_measures, lambda { |measures| scope :for_measures, lambda { |measures|
joins(:scale).where('scale.measure': measures) joins(:scale).where('scale.measure': measures)

View file

@ -1,8 +1,8 @@
module Dashboard module Dashboard
class AdminDataValue < ApplicationRecord class AdminDataValue < ApplicationRecord
belongs_to :school belongs_to :school, class_name: "School", foreign_key: :dashboard_school_id
belongs_to :dashboard_admin_data_item belongs_to :admin_data_item, class_name: "AdminDataItem", foreign_key: :dashboard_admin_data_item_id
belongs_to :dashboard_academic_year belongs_to :academic_year, class_name: "AcademicYear", foreign_key: :dashboard_academic_year_id
validates :likert_score, numericality: { greater_than: 0, less_than_or_equal_to: 5 } validates :likert_score, numericality: { greater_than: 0, less_than_or_equal_to: 5 }
end end

View file

@ -5,7 +5,7 @@ module Dashboard
scope :sorted, -> { order(:category_id) } scope :sorted, -> { order(:category_id) }
has_many :subcategories, class_name: "Subcategory", foreign_key: :dashboard_category_id has_many :subcategories, class_name: "Subcategory", foreign_key: :dashboard_categories_id
has_many :measures, through: :subcategories has_many :measures, through: :subcategories
has_many :admin_data_items, through: :measures has_many :admin_data_items, through: :measures
has_many :scales, through: :subcategories has_many :scales, through: :subcategories

View file

@ -1,6 +1,6 @@
module Dashboard module Dashboard
class Measure < ApplicationRecord class Measure < ApplicationRecord
belongs_to :dashboard_subcategory belongs_to :subcategory, class_name: "Subcategory", foreign_key: :dashboard_subcategory_id
has_one :dashboard_category, through: :dashboard_subcategory has_one :dashboard_category, through: :dashboard_subcategory
has_many :dashboard_scales has_many :dashboard_scales
has_many :dashboard_admin_data_items, through: :scales has_many :dashboard_admin_data_items, through: :scales

View file

@ -1,9 +1,9 @@
module Dashboard module Dashboard
class Scale < ApplicationRecord class Scale < ApplicationRecord
belongs_to :dashboard_measure belongs_to :measure, class_name: "Measure", foreign_key: :dashboard_measure_id
has_many :dashboard_survey_items has_many :survey_items
has_many :dashboard_survey_item_responses, through: :dashboard_survey_items has_many :survey_item_responses, through: :survey_items
has_many :dashboard_admin_data_items has_many :admin_data_items, class_name: "AdminDataItem", foreign_key: :admin_data_item_id
def score(school:, academic_year:) def score(school:, academic_year:)
@score ||= Hash.new do |memo, (school, academic_year)| @score ||= Hash.new do |memo, (school, academic_year)|

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class StudentResponseRateCalculator < ResponseRateCalculator module Dashboard
class StudentResponseRateCalculator < ResponseRateCalculator
def raw_response_rate def raw_response_rate
rates_by_grade.values.length.positive? ? weighted_average : 0 rates_by_grade.values.length.positive? ? weighted_average : 0
end end
@ -64,4 +65,5 @@ class StudentResponseRateCalculator < ResponseRateCalculator
respondents.total_students respondents.total_students
end end
end end
end
end end

View file

@ -1,12 +1,12 @@
module Dashboard module Dashboard
class Subcategory < ApplicationRecord class Subcategory < ApplicationRecord
belongs_to :category, class_name: "Category", foreign_key: :dashboard_category_id belongs_to :category, class_name: "Category", foreign_key: :dashboard_categories_id
has_many :dashboard_measures has_many :measures, class_name: "Measure", foreign_key: :dashboard_subcategory_id
has_many :dashboard_survey_items, through: :dashboard_measures has_many :survey_items, through: :measures
has_many :dashboard_admin_data_items, through: :dashboard_measures has_many :admin_data_items, through: :measures
has_many :dashboard_survey_items, through: :dashboard_measures has_many :survey_items, through: :measures
has_many :dashboard_scales, through: :dashboard_measures has_many :scales, through: :measures
def score(school:, academic_year:) def score(school:, academic_year:)
measures.map do |measure| measures.map do |measure|

View file

@ -1,11 +1,10 @@
module Dashboard module Dashboard
class SurveyItem < ApplicationRecord class SurveyItem < ApplicationRecord
# belongs_to :dashboard_scale belongs_to :scale, class_name: "Scale", foreign_key: :dashboard_scale_id
has_many :survey_item_responses, class_name: "SurveyItemResponse", foreign_key: :dashboard_survey_item_id
# has_one :dashboard_measure, through: dashboard_scale has_one :measure, through: :scale
# has_one :dashboard_subcategory, through: dashboard_measure has_one :subcategory, through: :measure
has_many :dashboard_survey_item_responses
def score(school:, academic_year:) def score(school:, academic_year:)
@score ||= Hash.new do |memo, (school, academic_year)| @score ||= Hash.new do |memo, (school, academic_year)|

View file

@ -8,7 +8,7 @@ namespace :dashboard do
"2023-24" "2023-24"
seeder.seed_districts_and_schools Dashboard::Engine.root.join("data", "dashboard", seeder.seed_districts_and_schools Dashboard::Engine.root.join("data", "dashboard",
"master_list_of_schools_and_districts.csv") "master_list_of_schools_and_districts.csv")
# seeder.seed_sqm_framework Dashboard::Engine.root.join("data", "dashboard", "sqm_framework.csv") seeder.seed_sqm_framework Dashboard::Engine.root.join("data", "dashboard", "sqm_framework.csv")
# seeder.seed_demographics Rails.root.join("data", "demographics.csv") # seeder.seed_demographics Rails.root.join("data", "demographics.csv")
# seeder.seed_enrollment Rails.root.join("data", "enrollment", "enrollment.csv") # seeder.seed_enrollment Rails.root.join("data", "enrollment", "enrollment.csv")
# seeder.seed_enrollment Rails.root.join("data", "enrollment", "nj_enrollment.csv") # seeder.seed_enrollment Rails.root.join("data", "enrollment", "nj_enrollment.csv")