mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
reversed questions
This commit is contained in:
parent
aa5f1ad157
commit
e73351d0f5
8 changed files with 19 additions and 8 deletions
|
|
@ -51,7 +51,7 @@ class Attempt < ApplicationRecord
|
||||||
|
|
||||||
def response
|
def response
|
||||||
return 'No Answer Yet' if answer_index.blank?
|
return 'No Answer Yet' if answer_index.blank?
|
||||||
question.options[answer_index - 1]
|
question.options[answer_index_with_reverse - 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_response(answer_index: nil, twilio_details: nil, responded_at: Time.new)
|
def save_response(answer_index: nil, twilio_details: nil, responded_at: Time.new)
|
||||||
|
|
@ -66,6 +66,11 @@ class Attempt < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def answer_index_with_reverse
|
||||||
|
return 5 - answer_index if question.reverse?
|
||||||
|
return answer_index
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def update_school_categories
|
def update_school_categories
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,9 @@ class Question < ApplicationRecord
|
||||||
school_responses = attempts.for_school(school).with_answer.order(id: :asc)
|
school_responses = attempts.for_school(school).with_answer.order(id: :asc)
|
||||||
return unless school_responses.present?
|
return unless school_responses.present?
|
||||||
|
|
||||||
response_answer_total = school_responses.inject(0) { |total, response| total + response.answer_index }
|
response_answer_total = school_responses.inject(0) { |total, response| total + response.answer_index_with_reverse }
|
||||||
|
histogram = school_responses.group_by(&:answer_index_with_reverse)
|
||||||
|
|
||||||
histogram = school_responses.group_by(&:answer_index)
|
|
||||||
most_popular_answer_index = histogram.to_a.sort_by { |info| info[1].length }.last[0]
|
most_popular_answer_index = histogram.to_a.sort_by { |info| info[1].length }.last[0]
|
||||||
most_popular_answer = send("option#{most_popular_answer_index}")
|
most_popular_answer = send("option#{most_popular_answer_index}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class SchoolCategory < ApplicationRecord
|
||||||
for_school(school).
|
for_school(school).
|
||||||
select('count(attempts.id) as attempt_count').
|
select('count(attempts.id) as attempt_count').
|
||||||
select('count(attempts.answer_index) as response_count').
|
select('count(attempts.answer_index) as response_count').
|
||||||
select('sum(attempts.answer_index) as answer_index_total')[0]
|
select('sum(case when questions.reverse then 5 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
attempt_count: attempt_data.attempt_count || 0,
|
attempt_count: attempt_data.attempt_count || 0,
|
||||||
|
|
|
||||||
|
|
@ -35,4 +35,4 @@
|
||||||
= render 'shared/histogram', data: aggregated_responses
|
= render 'shared/histogram', data: aggregated_responses
|
||||||
|
|
||||||
%p.collapse{id: "raw-data#{question.id}"}
|
%p.collapse{id: "raw-data#{question.id}"}
|
||||||
= aggregated_responses.responses.map(&:answer_index).join(', ')
|
= aggregated_responses.responses.map(&:answer_index_with_reverse).join(', ')
|
||||||
|
|
|
||||||
|
|
@ -76,4 +76,4 @@
|
||||||
%td
|
%td
|
||||||
= attempt.sent_at.strftime('%x') if attempt.sent_at.present?
|
= attempt.sent_at.strftime('%x') if attempt.sent_at.present?
|
||||||
%td= link_to truncate(attempt.question.text, length: 60), [@school, attempt.question], title: attempt.question.text
|
%td= link_to truncate(attempt.question.text, length: 60), [@school, attempt.question], title: attempt.question.text
|
||||||
%td= "(#{attempt.answer_index}) #{attempt.response}"
|
%td= "(#{attempt.answer_index_with_reverse}) #{attempt.response}"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
- histogram = data.responses.map(&:answer_index).group_by { |a| a.to_s }
|
- histogram = data.responses.map(&:answer_index_with_reverse).group_by { |a| a.to_s }
|
||||||
%table.answers
|
%table.answers
|
||||||
%tbody
|
%tbody
|
||||||
- data.question.options.each_with_index do |option, index|
|
- data.question.options.each_with_index do |option, index|
|
||||||
|
|
|
||||||
5
db/migrate/20171028181758_add_reverse_to_questions.rb
Normal file
5
db/migrate/20171028181758_add_reverse_to_questions.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddReverseToQuestions < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
add_column :questions, :reverse, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20170418173141) do
|
ActiveRecord::Schema.define(version: 20171028181758) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
@ -72,6 +72,7 @@ ActiveRecord::Schema.define(version: 20170418173141) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "target_group", default: 0
|
t.integer "target_group", default: 0
|
||||||
t.boolean "for_recipient_students", default: false
|
t.boolean "for_recipient_students", default: false
|
||||||
|
t.boolean "reverse", default: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "recipient_lists", force: :cascade do |t|
|
create_table "recipient_lists", force: :cascade do |t|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue