mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 23:48:17 -07:00
to survey table. We no longer check or keep track of the survey type. Instead we look in the database to see if a survey item has at least 10 responses. If it does, that survey item was presented to the respondent and we count it, and all responses when calculating the response rate. Remove response rate timestamp from caching logic because we no longer add the response rate to the database. All response rates are calculated on the fly Update three_b_two scraper to use teacher only numbers swap over to using https://profiles.doe.mass.edu/statereport/gradesubjectstaffing.aspx as the source of staffing information
65 lines
2.2 KiB
Ruby
65 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class SurveyItem < ActiveRecord::Base
|
|
belongs_to :scale, counter_cache: true
|
|
has_one :measure, through: :scale
|
|
has_one :subcategory, through: :measure
|
|
|
|
has_many :survey_item_responses
|
|
|
|
def score(school:, academic_year:)
|
|
@score ||= Hash.new do |memo, (school, academic_year)|
|
|
memo[[school, academic_year]] =
|
|
survey_item_responses.exclude_boston.where(school:, academic_year:).average(:likert_score).to_f
|
|
end
|
|
@score[[school, academic_year]]
|
|
end
|
|
|
|
scope :student_survey_items, lambda {
|
|
where("survey_items.survey_item_id LIKE 's-%'")
|
|
}
|
|
scope :teacher_survey_items, lambda {
|
|
where("survey_items.survey_item_id LIKE 't-%'")
|
|
}
|
|
scope :short_form_items, lambda {
|
|
where(on_short_form: true)
|
|
}
|
|
scope :early_education_surveys, lambda {
|
|
where("survey_items.survey_item_id LIKE '%-%-es%'")
|
|
}
|
|
|
|
scope :survey_items_for_grade, lambda { |school, academic_year, grade|
|
|
includes(:survey_item_responses)
|
|
.where("survey_item_responses.grade": grade,
|
|
"survey_item_responses.school": school,
|
|
"survey_item_responses.academic_year": academic_year).distinct
|
|
}
|
|
|
|
scope :survey_item_ids_for_grade, lambda { |school, academic_year, grade|
|
|
survey_items_for_grade(school, academic_year, grade).pluck(:survey_item_id)
|
|
}
|
|
|
|
scope :survey_items_for_grade_and_subcategory, lambda { |school, academic_year, grade, subcategory|
|
|
includes(:survey_item_responses)
|
|
.where(
|
|
survey_item_id: subcategory.survey_items.pluck(:survey_item_id),
|
|
"survey_item_responses.school": school,
|
|
"survey_item_responses.academic_year": academic_year,
|
|
"survey_item_responses.grade": grade
|
|
)
|
|
}
|
|
|
|
scope :survey_type_for_grade, lambda { |school, academic_year, grade|
|
|
survey_items_set_by_grade = survey_items_for_grade(school, academic_year, grade).pluck(:survey_item_id).to_set
|
|
if survey_items_set_by_grade.size > 0 && survey_items_set_by_grade.subset?(early_education_surveys.pluck(:survey_item_id).to_set)
|
|
return :early_education
|
|
end
|
|
|
|
:regular
|
|
}
|
|
|
|
# TODO: rename this to Summary
|
|
def description
|
|
DataAvailability.new(survey_item_id, prompt, true)
|
|
end
|
|
end
|