scope school_categories to valid ones

pull/1/head
Jared Cosulich 8 years ago
parent 55263dd058
commit 76b98c2c25

@ -14,7 +14,7 @@ class CategoriesController < ApplicationController
district = @school.district
authenticate(district.name.downcase, "#{district.name.downcase}!")
@school_category = SchoolCategory.for(@school, @category).first
@child_school_categories = SchoolCategory.for_parent_category(@school, @category)
@child_school_categories = SchoolCategory.for_parent_category(@school, @category).valid
@questions = @category.questions
end

@ -9,6 +9,8 @@ class SchoolCategory < ApplicationRecord
scope :for, -> (school, category) { where(school: school).where(category: category) }
scope :for_parent_category, -> (school, category=nil) { where(school: school).joins(:category).merge(Category.for_parent(category)) }
scope :valid, -> { where("answer_index_total > 0 or zscore is not null") }
def answer_index_average
answer_index_total.to_f / response_count.to_f
end
@ -32,8 +34,8 @@ class SchoolCategory < ApplicationRecord
_aggregated_responses = aggregated_responses
child_school_categories = category.child_categories.collect do |cc|
SchoolCategory.for(school, cc)
end.flatten
SchoolCategory.for(school, cc).valid
end.flatten.compact
new_zscore = zscore
if new_zscore.nil?

@ -6,6 +6,8 @@
- likert = info.answer_index_average.nan? ? zscore : (info.answer_index_average + zscore) / 2
- likert = likert.round(1)
- return if likert.nan?
- average_offset = (likert/num_likerts) * 100
- approval_zone = [[76, 90], [77, 91], [71, 85], [73, 86], [73, 86], []][info.category.root_index]

Loading…
Cancel
Save