Set up bullet gem. Implement bullet gem suggestions.

This commit is contained in:
Nelson Jovel 2022-01-07 15:37:32 +01:00
parent 3408ecd749
commit 5a8d032dd0
10 changed files with 39 additions and 17 deletions

View file

@ -1,7 +1,7 @@
class HomeController < ApplicationController
def index
@districts = District.all.order(:name)
@schools = School.all.order(:name)
@schools = School.all.includes([:district]).order(:name)
@categories = Category.sorted.map { |category| CategoryPresenter.new(category: category) }
end

View file

@ -12,8 +12,8 @@ class SqmApplicationController < ApplicationController
def set_schools_and_districts
@district = District.find_by_slug district_slug
@districts = District.all.order(:name)
@school = School.find_by_slug school_slug
@schools = School.where(district: @district).order(:name)
@school = School.find_by_slug(school_slug)
@schools = School.includes([:district]).where(district: @district).order(:name)
@academic_year = AcademicYear.find_by_range params[:year]
@has_empty_dataset = Measure.none_meet_threshold? school: @school, academic_year: @academic_year
end

View file

@ -2,7 +2,7 @@ class Category < ActiveRecord::Base
include FriendlyId
friendly_id :name, use: [:slugged]
scope :sorted, -> { order(:sort_index) }
scope :sorted, -> { order(:sort_index)}
has_many :subcategories
has_many :measures, through: :subcategories

View file

@ -56,7 +56,7 @@ class CategoryPresenter
end
def subcategories(academic_year:, school:)
@category.subcategories.sort_by(&:subcategory_id).map do |subcategory|
@category.subcategories.includes([:measures]).sort_by(&:subcategory_id).map do |subcategory|
SubcategoryPresenter.new(
subcategory: subcategory,
academic_year: academic_year,

View file

@ -31,7 +31,7 @@ class SubcategoryPresenter
end
def measure_presenters
@subcategory.measures.sort_by(&:measure_id).map do |measure|
@subcategory.measures.includes([:admin_data_items]).sort_by(&:measure_id).map do |measure|
MeasurePresenter.new(measure: measure, academic_year: @academic_year, school: @school)
end
end
@ -39,15 +39,15 @@ class SubcategoryPresenter
private
def scale
Scale.new(
watch_low_benchmark: measures.map(&:watch_low_benchmark).average,
growth_low_benchmark: measures.map(&:growth_low_benchmark).average,
approval_low_benchmark: measures.map(&:approval_low_benchmark).average,
ideal_low_benchmark: measures.map(&:ideal_low_benchmark).average
)
Scale.new(
watch_low_benchmark: measures.map(&:watch_low_benchmark).average,
growth_low_benchmark: measures.map(&:growth_low_benchmark).average,
approval_low_benchmark: measures.map(&:approval_low_benchmark).average,
ideal_low_benchmark: measures.map(&:ideal_low_benchmark).average
)
end
def measures
@measures ||= @subcategory.measures.order(:measure_id)
@measures ||= @subcategory.measures.includes([:admin_data_items]).order(:measure_id)
end
end