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

33 lines
961 B

class OverviewController < SqmApplicationController
before_action :check_empty_dataset, 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.any? 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
end