chore: start adding overview page

This commit is contained in:
Nelson Jovel 2024-01-17 12:49:23 -08:00
parent 1b0af124f7
commit 64b4d599c7
33 changed files with 783 additions and 199 deletions

View file

@ -37,6 +37,5 @@ module Dashboard
private_class_method :academic_years
private_class_method :parse_year_range
end
AcademicYearRange = Struct.new(:start, :end)
end
AcademicYearRange = Struct.new(:start, :end)

View file

@ -1,11 +1,11 @@
module Dashboard
class Measure < ApplicationRecord
belongs_to :subcategory, class_name: "Subcategory", foreign_key: :dashboard_subcategory_id
has_one :dashboard_category, through: :dashboard_subcategory
has_many :dashboard_scales
has_many :dashboard_admin_data_items, through: :scales
has_many :dashboard_survey_items, through: :scales
has_many :dashboard_survey_item_responses, through: :survey_items
has_one :dashboard_category, through: :subcategory
has_many :scales, class_name: "Scale", foreign_key: :dashboard_measure_id
has_many :admin_data_items, through: :scales
has_many :survey_items, through: :scales
has_many :survey_item_responses, through: :survey_items
def none_meet_threshold?(school:, academic_year:)
@none_meet_threshold ||= Hash.new do |memo, (school, academic_year)|
@ -24,15 +24,17 @@ module Dashboard
end
def student_survey_items_with_sufficient_responses(school:, academic_year:)
@student_survey_items_with_sufficient_responses ||= SurveyItem.where(id: SurveyItem.joins("inner join survey_item_responses on survey_item_responses.survey_item_id = survey_items.id")
.student_survey_items
.where("survey_item_responses.school": school,
"survey_item_responses.academic_year": academic_year,
"survey_item_responses.survey_item_id": survey_items.student_survey_items,
"survey_item_responses.grade": school.grades(academic_year:))
.group("survey_items.id")
.having("count(*) >= 10")
.count.keys)
# @student_survey_items_with_sufficient_responses ||= SurveyItem.where(id: SurveyItem.joins("inner join dashboard_survey_item_responses on dashboard_survey_item_responses.survey_item_id = dashboard_survey_items.id")
# .student_survey_items
# .where("dashboard_survey_item_responses.school": school,
# "dashboard_survey_item_responses.academic_year": academic_year,
# "dashboard_survey_item_responses.survey_item_id": survey_items.student_survey_items,
# "dashboard_survey_item_responses.grade": school.grades(academic_year:))
# .group("survey_items.id")
# .having("count(*) >= 10")
# .count.keys)
@student_survey_items_with_sufficient_responses ||= student_survey_items
end
def teacher_scales

View file

@ -1,7 +1,18 @@
module Dashboard
class ResponseRate < ApplicationRecord
belongs_to :dashboard_subcategory
belongs_to :school
belongs_to :dashboard_academic_year
TEACHER_RATE_THRESHOLD = 24.5
STUDENT_RATE_THRESHOLD = 24.5
belongs_to :subcategory, class_name: "Subcategory", foreign_key: :dashboard_subcategory_id
belongs_to :school, class_name: "School", foreign_key: :dashboard_school_id
belongs_to :academic_year, class_name: "AcademicYear", foreign_key: :dashboard_academic_year_id
def meets_student_threshold?
student_response_rate >= 24.5
end
def meets_teacher_threshold?
teacher_response_rate >= 24.5
end
end
end

View file

@ -2,8 +2,6 @@
module Dashboard
class ResponseRateCalculator
TEACHER_RATE_THRESHOLD = 25
STUDENT_RATE_THRESHOLD = 25
attr_reader :subcategory, :school, :academic_year
def initialize(subcategory:, school:, academic_year:)
@ -22,14 +20,6 @@ module Dashboard
cap_at_one_hundred(raw_response_rate).round
end
def meets_student_threshold?
rate >= STUDENT_RATE_THRESHOLD
end
def meets_teacher_threshold?
rate >= TEACHER_RATE_THRESHOLD
end
private
def cap_at_one_hundred(response_rate)

View file

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

View file

@ -37,8 +37,7 @@ module Dashboard
student = StudentResponseRateCalculator.new(subcategory: self, school:, academic_year:)
teacher = TeacherResponseRateCalculator.new(subcategory: self, school:, academic_year:)
memo[[school, academic_year]] = ResponseRate.new(school:, academic_year:, subcategory: self, student_response_rate: student.rate,
teacher_response_rate: teacher.rate, meets_student_threshold: student.meets_student_threshold?,
meets_teacher_threshold: teacher.meets_teacher_threshold?)
teacher_response_rate: teacher.rate)
end
@response_rate[[school, academic_year]]

View file

@ -15,26 +15,26 @@ module Dashboard
end
scope :student_survey_items, lambda {
where("survey_items.survey_item_id LIKE 's-%'")
where("dashboard_survey_items.survey_item_id LIKE 's-%'")
}
scope :standard_survey_items, lambda {
where("survey_items.survey_item_id LIKE 's-%-q%'")
where("dashboard_survey_items.survey_item_id LIKE 's-%-q%'")
}
scope :teacher_survey_items, lambda {
where("survey_items.survey_item_id LIKE 't-%'")
where("dashboard_survey_items.survey_item_id LIKE 't-%'")
}
scope :short_form_survey_items, lambda {
where(on_short_form: true)
}
scope :early_education_survey_items, lambda {
where("survey_items.survey_item_id LIKE '%-%-es%'")
where("dashboard_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
.where("dashboard_survey_item_responses.grade": grade,
"dashboard_survey_item_responses.school": school,
"dashboard_survey_item_responses.academic_year": academic_year).distinct
}
scope :survey_item_ids_for_grade, lambda { |school, academic_year, grade|
@ -45,9 +45,9 @@ module Dashboard
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
"dashboard_survey_item_responses.school": school,
"dashboard_survey_item_responses.academic_year": academic_year,
"dashboard_survey_item_responses.grade": grade
)
}

View file

@ -3,16 +3,16 @@ module Dashboard
TEACHER_RESPONSE_THRESHOLD = 2
STUDENT_RESPONSE_THRESHOLD = 10
belongs_to :school
belongs_to :dashboard_survey_item
belongs_to :dashboard_academic_year
belongs_to :school, class_name: "School", foreign_key: :dashboard_school_id
belongs_to :survey_item, class_name: "SurveyItem", foreign_key: :dashboard_survey_item_id
belongs_to :academic_year, class_name: "AcademicYear", foreign_key: :dashboard_academic_year
belongs_to :dashboard_student, optional: true
belongs_to :dashboard_gender, optional: true
belongs_to :dashboard_income, optional: true
belongs_to :dashboard_ell, optional: true
belongs_to :dashboard_sped, optional: true
has_one :dashboard_measure, through: :dashboard_survey_item
has_one :dashboard_measure, through: :survey_item
validates :likert_score, numericality: { greater_than: 0, less_than_or_equal_to: 5 }
@ -61,10 +61,10 @@ module Dashboard
def self.teacher_survey_items_with_sufficient_responses(school:, academic_year:)
@teacher_survey_items_with_sufficient_responses ||= Hash.new do |memo, (school, academic_year)|
hash = SurveyItem.joins("inner join survey_item_responses on survey_item_responses.survey_item_id = survey_items.id")
hash = SurveyItem.joins("inner join dashboard_survey_item_responses on dashboard_survey_item_responses.dashboard_survey_item_id = dashboard_survey_items.id")
.teacher_survey_items
.where("survey_item_responses.school": school, "survey_item_responses.academic_year": academic_year)
.group("survey_items.id")
.where("dashboard_survey_item_responses.dashboard_school_id": school.id, "dashboard_survey_item_responses.dashboard_academic_year_id": academic_year.id)
.group("dashboard_survey_items.id")
.having("count(*) > 0").count
memo[[school, academic_year]] = hash
end
@ -73,9 +73,9 @@ module Dashboard
def self.student_survey_items_with_sufficient_responses_by_grade(school:, academic_year:)
@student_survey_items_with_sufficient_responses_by_grade ||= Hash.new do |memo, (school, academic_year)|
hash = SurveyItem.joins("inner join survey_item_responses on survey_item_responses.survey_item_id = survey_items.id")
hash = SurveyItem.joins("inner join dashboard_survey_item_responses on dashboard_survey_item_responses.dashboard_survey_item_id = dashboard_survey_items.id")
.student_survey_items
.where("survey_item_responses.school": school, "survey_item_responses.academic_year": academic_year)
.where("dashboard_survey_item_responses.dashboard_school_id": school.id, "dashboard_survey_item_responses.dashboard_academic_year_id": academic_year.id)
.group(:grade, :id)
.count
memo[[school, academic_year]] = hash