diff --git a/app/views/questions/_question.html.haml b/app/views/questions/_question.html.haml
index 70aba61e..1cae75c0 100644
--- a/app/views/questions/_question.html.haml
+++ b/app/views/questions/_question.html.haml
@@ -1,7 +1,7 @@
- aggregated_responses = question.aggregated_responses_for_school(@school)
- return if aggregated_responses.nil?
-- school_questions = SchoolQuestion.for(@school, question)
-- valid_responses = (aggregated_responses.count.to_f / @school.available_responders_for(question).to_f) >= 0.3
+- school_question = SchoolQuestion.for(@school, question).first
+- valid_responses = school_question.nil? ? true : school_question.response_rate > 0.3 # || (aggregated_responses.count.to_f / @school.available_responders_for(question).to_f)) >= 0.3
.col-12.col-md-6.py-3
.question.p-2{id: "question-#{question.id}"}
@@ -49,9 +49,6 @@
%p.collapse{id: "raw-data#{question.id}"}
= aggregated_responses.responses.map(&:answer_index_with_reverse).join(', ')
- - if school_questions.present?
+ - if school_question.present?
.clearfix
- - if school_questions.length > 1
- %p= "More than one school question: #{school_questions.length}"
- - school_question = school_questions.first
%p= "Attempts: #{school_question.attempt_count}, Responses: #{school_question.response_count}, Response Rate: #{number_to_percentage(school_question.response_rate * 100, precision: 0)}"
diff --git a/app/views/school_categories/_school_category.html.haml b/app/views/school_categories/_school_category.html.haml
index b72ed8db..1e0a75a9 100644
--- a/app/views/school_categories/_school_category.html.haml
+++ b/app/views/school_categories/_school_category.html.haml
@@ -3,16 +3,20 @@
%h4.title.text-center.pt-3
= link_to(school_category.category.name, school_category_path(school_category.school, school_category.category, year: school_category.year))
- .indicator-container.short
- = render 'school_categories/indicator', info: school_category
+ - if (school_category.valid_child_count || 1) > 0
+ .indicator-container.short
+ = render 'school_categories/indicator', info: school_category
- .description.px-2.pt-3.pb-2.mt-2
- - if false #(measurements = school_category.questions.measurements.for_school(school_measure.school)).present?
- = render 'measurements/nonlikert', measurement: measurements.first, description: school_measure.measure.description
- - else
- = school_category.category.blurb || truncate(school_category.category.description, length: 108)
+ .description.px-2.pt-3.pb-2.mt-2
+ - if false #(measurements = school_category.questions.measurements.for_school(school_measure.school)).present?
+ = render 'measurements/nonlikert', measurement: measurements.first, description: school_measure.measure.description
+ - else
+ = school_category.category.blurb || truncate(school_category.category.description, length: 108)
- - if school_category.valid_child_count.present?
- %br
- %br
- %p= "Valid Child Count: #{school_category.valid_child_count}"
+ - else
+ .row.pt-2
+ .col-12.centered
+ .px-2
+ %h5 Insufficient Responses
+ %p No data is displayed for this measure because of insufficient responses.
+ -#%p= "Responded: #{aggregated_responses.count}, Possible: #{@school.available_responders_for(question)}"
diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake
index 784f2130..c86ee39a 100644
--- a/lib/tasks/data.rake
+++ b/lib/tasks/data.rake
@@ -449,7 +449,7 @@ namespace :data do
Recipient.created_in(@year).each { |r| r.update_counts }
end
- desc 'Create SchoolQuestions'
+ desc 'Create School Questions'
task create_school_questions: :environment do
Category.joins(:questions).uniq.all.each do |category|
category.school_categories.includes(school: [:district]).find_in_batches(batch_size: 100) do |group|
@@ -552,25 +552,39 @@ end
#
#
+# level = 1
+# categories = Category.joins(:questions).uniq.all
# loop do
-# categories = Category.joins(:school_categories)
-# .merge(SchoolCategory.where("valid_child_count is not null"))
-# .uniq
-# break if categories.count == 0
-# categories.all.each do |category|
+# parent_categories = []
+# categories.each_with_index do |category, i|
# parent_category = category.parent_category
+# next if parent_category.nil? || parent_categories.include?(parent_category)
+# parent_categories << parent_category
#
-# parent_category.school_categories.find_in_batches(batch_size: 100) do |group|
-# group.each do |school_category|
-# next if school_category.valid_child_count.present?
+# school_categories = parent_category.school_categories.joins(school: :district).where("districts.name = 'Boston'")
+# school_categories.each_with_index do |school_category, index|
+# school = school_category.school
#
-# school = school_category.school
-# children = SchoolCategory.for_parent_category(school, parent_category).in(school_category.year)
-# school_category.update(
-# valid_child_count: children.where("valid_child_count > 1").count
-# )
-# end
-# end
+# children = SchoolCategory.for_parent_category(school, parent_category).in(school_category.year)
+# valid_child_count = children.where("valid_child_count > 0").count
+# school_category.update(
+# valid_child_count: valid_child_count
+# )
+# puts ""
+# puts ""
+# puts("#{level} (#{i}/#{categories.length}) UPDATED (#{index}/#{school_categories.length}): #{school.slug} -> #{parent_category.slug} -> #{school_category.year} -> #{valid_child_count} --- PARENT: #{parent_categories.length}")
+# puts ""
+# puts ""
# end
# end
+#
+# puts ""
+# puts ""
+# puts "PARENT CATEGORIES: #{parent_categories.uniq.length}"
+# puts ""
+# puts ""
+#
+# level += 1
+# categories = parent_categories.uniq
+# break if categories.blank?
# end