using valid_child_count

pull/1/head
Jared Cosulich 7 years ago
parent d6ae78bcad
commit 4ad2660e28

@ -36,6 +36,9 @@
= @school_category.zscore.round(1) + 3 = @school_category.zscore.round(1) + 3
(out of 5) (out of 5)
%b Valid Children:
= @school_category.valid_child_count || "N/A"
.indicator-container.py-3 .indicator-container.py-3
= render 'school_categories/indicator', info: @school_category = render 'school_categories/indicator', info: @school_category

@ -1,5 +1,6 @@
- aggregated_responses = question.aggregated_responses_for_school(@school) - aggregated_responses = question.aggregated_responses_for_school(@school)
- return if aggregated_responses.nil? - 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 - valid_responses = (aggregated_responses.count.to_f / @school.available_responders_for(question).to_f) >= 0.3
.col-12.col-md-6.py-3 .col-12.col-md-6.py-3
@ -47,3 +48,7 @@
%p.collapse{id: "raw-data#{question.id}"} %p.collapse{id: "raw-data#{question.id}"}
= aggregated_responses.responses.map(&:answer_index_with_reverse).join(', ') = 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}"

@ -455,7 +455,7 @@ namespace :data do
category.school_categories.includes(school: [:district]).find_in_batches(batch_size: 100) do |group| category.school_categories.includes(school: [:district]).find_in_batches(batch_size: 100) do |group|
group.each do |school_category| group.each do |school_category|
school_questions = [] school_questions = []
new_school_questions = []
category.questions.created_in(school_category.year).each do |question| category.questions.created_in(school_category.year).each do |question|
school = school_category.school school = school_category.school
next if school.district.name != "Boston" next if school.district.name != "Boston"
@ -465,18 +465,26 @@ namespace :data do
for_school(school).count for_school(school).count
available_responders = school.available_responders_for(question) available_responders = school.available_responders_for(question)
school_questions << school_category.school_questions.new(
school: school, school_question = school_category.school_questions.for(school, question)
question: question, if school_question.present?
school_category: school_category, school_questions << school_question
year: school_category.year, else
attempt_count: available_responders, school_question = school_category.school_questions.new(
response_count: attempt_count, school: school,
response_rate: attempt_count.to_f / available_responders.to_f 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 end
SchoolQuestion.import school_questions SchoolQuestion.import new_school_questions
valid_questions = school_questions.select { |sc| sc.response_rate > 0.3 } valid_questions = school_questions.select { |sc| sc.response_rate > 0.3 }
school_category.update( school_category.update(
valid_child_count: valid_questions.length valid_child_count: valid_questions.length
@ -544,7 +552,6 @@ end
# #
# #
#
# loop do # loop do
# categories = Category.joins(:school_categories) # categories = Category.joins(:school_categories)
# .merge(SchoolCategory.where("valid_child_count is not null")) # .merge(SchoolCategory.where("valid_child_count is not null"))

Loading…
Cancel
Save