sqm-dashboards/app/models/school.rb
Nelson Jovel 33da0859b9 Split academic year into seasons if the academic year's range is
initialized with a season, i.e. "2024-25 Fall".  Update scapers for
admin data, enrollment and staffing to use the new range standard
correctly.   Update the loaders for admin data, enrollment and staffing
so that it populates all seasons in a given year.  So admin data for
2024-25 gets loaded into "2024-25 Fall" and "2024-25 Spring".  Add tests
for the new range format.  Set the default cutoff for the start of Spring season will be the last Sunday in February
2024-04-25 09:21:04 -07:00

26 lines
747 B
Ruby

# frozen_string_literal: true
class School < ApplicationRecord
belongs_to :district
has_many :survey_item_responses, dependent: :delete_all
validates :name, presence: true
scope :alphabetic, -> { order(name: :asc) }
scope :by_dese_id, -> { all.map { |school| [school.dese_id, school] }.to_h }
include FriendlyId
friendly_id :name, use: [:slugged]
def self.find_by_district_code_and_school_code(district_code, school_code)
School
.joins(:district)
.where(districts: { qualtrics_code: district_code })
.find_by_qualtrics_code(school_code)
end
def grades(academic_year:)
@grades ||= Respondent.by_school_and_year(school: self, academic_year:)&.enrollment_by_grade&.keys || (-1..12).to_a
end
end