You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqm-dashboards/app/controllers/overview_controller.rb

46 lines
1.3 KiB

# frozen_string_literal: true
class OverviewController < SqmApplicationController
before_action :check_empty_dataset, only: [:index]
before_action :response_rate_timestamp, only: [:index]
helper VarianceHelper
def index
@variance_chart_row_presenters = measures.map(&method(:presenter_for_measure))
@category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category:) }
end
private
def presenter_for_measure(measure)
score = measure.score(school: @school, academic_year: @academic_year)
VarianceChartRowPresenter.new(measure:, score:)
end
def check_empty_dataset
@has_empty_dataset = subcategories.none? do |subcategory|
response_rate = subcategory.response_rate(school: @school, academic_year: @academic_year)
response_rate.meets_student_threshold || response_rate.meets_teacher_threshold
end
end
def measures
@measures ||= Measure.all.includes(%i[scales admin_data_items category])
end
def subcategories
@subcategories ||= Subcategory.all
end
def response_rate_timestamp
@response_rate_timestamp = begin
rate = ResponseRate.where(school: @school,
academic_year: @academic_year).order(updated_at: :DESC).first || Today.new
rate.updated_at
end
@response_rate_timestamp
end
end