adding response_total to SchoolQuestion

pull/1/head
Jared Cosulich 7 years ago
parent 341c561a67
commit a82deaafd8

@ -49,6 +49,6 @@
%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? - if school_question.present?
-# .clearfix .clearfix
-# %p= "Attempts: #{school_question.attempt_count}, Responses: #{school_question.response_count}, Response Rate: #{number_to_percentage(school_question.response_rate * 100, precision: 0)}" %p= "Attempts: #{school_question.attempt_count}, Responses: #{school_question.response_count}, Response Rate: #{number_to_percentage(school_question.response_rate * 100, precision: 0)}, Total: #{school_question.response_total}"

@ -0,0 +1,5 @@
class AddResponseTotalToSchoolQuestions < ActiveRecord::Migration[5.0]
def change
add_column :school_questions, :response_total, :integer
end
end

@ -459,10 +459,10 @@ namespace :data do
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"
attempt_count = Attempt. attempts = Attempt.
created_in(school_category.year). created_in(school_category.year).
for_question(question). for_question(question).
for_school(school).count for_school(school)
available_responders = school.available_responders_for(question) available_responders = school.available_responders_for(question)
@ -476,8 +476,11 @@ namespace :data do
school_category: school_category, school_category: school_category,
year: school_category.year, year: school_category.year,
attempt_count: available_responders, attempt_count: available_responders,
response_count: attempt_count, response_count: attempts.count,
response_rate: attempt_count.to_f / available_responders.to_f response_rate: attempts.count.to_f / available_responders.to_f
response_total: attempts.sum do |a|
question.reverse? ? 6 - a.answer_index : a.answer_index
end
) )
new_school_questions << school_question new_school_questions << school_question
school_questions << school_question school_questions << school_question

Loading…
Cancel
Save