diff --git a/app/views/categories/show.html.haml b/app/views/categories/show.html.haml
index aa6c4aec..03e3c7ed 100644
--- a/app/views/categories/show.html.haml
+++ b/app/views/categories/show.html.haml
@@ -36,6 +36,9 @@
= @school_category.zscore.round(1) + 3
(out of 5)
+ %b Valid Children:
+ = @school_category.valid_child_count || "N/A"
+
.indicator-container.py-3
= render 'school_categories/indicator', info: @school_category
diff --git a/app/views/questions/_question.html.haml b/app/views/questions/_question.html.haml
index 6a8606cd..9119c51d 100644
--- a/app/views/questions/_question.html.haml
+++ b/app/views/questions/_question.html.haml
@@ -1,5 +1,6 @@
- aggregated_responses = question.aggregated_responses_for_school(@school)
- return if aggregated_responses.nil?
+- school_question = SchoolQuestion.for(@school, question)
- valid_responses = (aggregated_responses.count.to_f / @school.available_responders_for(question).to_f) >= 0.3
.col-12.col-md-6.py-3
@@ -47,3 +48,7 @@
%p.collapse{id: "raw-data#{question.id}"}
= aggregated_responses.responses.map(&:answer_index_with_reverse).join(', ')
+
+ - if school_question.present?
+ .clearfix
+ %p= "Attempts: #{school_question.attempt_count}, Responses: #{school_question.response_count}, Response Rate: #{school_question.response_rate}"
diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake
index 621e9f08..784f2130 100644
--- a/lib/tasks/data.rake
+++ b/lib/tasks/data.rake
@@ -455,7 +455,7 @@ namespace :data do
category.school_categories.includes(school: [:district]).find_in_batches(batch_size: 100) do |group|
group.each do |school_category|
school_questions = []
-
+ new_school_questions = []
category.questions.created_in(school_category.year).each do |question|
school = school_category.school
next if school.district.name != "Boston"
@@ -465,18 +465,26 @@ namespace :data do
for_school(school).count
available_responders = school.available_responders_for(question)
- school_questions << school_category.school_questions.new(
- school: school,
- question: question,
- school_category: school_category,
- year: school_category.year,
- attempt_count: available_responders,
- response_count: attempt_count,
- response_rate: attempt_count.to_f / available_responders.to_f
- )
+
+ school_question = school_category.school_questions.for(school, question)
+ if school_question.present?
+ school_questions << school_question
+ else
+ school_question = school_category.school_questions.new(
+ school: school,
+ question: question,
+ school_category: school_category,
+ year: school_category.year,
+ attempt_count: available_responders,
+ response_count: attempt_count,
+ response_rate: attempt_count.to_f / available_responders.to_f
+ )
+ new_school_questions << school_question
+ school_questions << school_question
+ end
end
- SchoolQuestion.import school_questions
+ SchoolQuestion.import new_school_questions
valid_questions = school_questions.select { |sc| sc.response_rate > 0.3 }
school_category.update(
valid_child_count: valid_questions.length
@@ -544,7 +552,6 @@ end
#
#
-#
# loop do
# categories = Category.joins(:school_categories)
# .merge(SchoolCategory.where("valid_child_count is not null"))