From df594b9666625ec2eccb05cefab0cdbccd922aa5 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Thu, 16 Mar 2017 14:13:03 -0400 Subject: [PATCH] source for data: --- app/assets/stylesheets/questions.scss | 62 ++++++++++--------- app/models/question.rb | 6 ++ app/views/questions/_question.html.haml | 3 +- ...0316154053_add_target_group_to_question.rb | 5 ++ db/schema.rb | 7 ++- lib/tasks/data.rake | 4 +- 6 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 db/migrate/20170316154053_add_target_group_to_question.rb diff --git a/app/assets/stylesheets/questions.scss b/app/assets/stylesheets/questions.scss index f8afbd65..860ef4d1 100644 --- a/app/assets/stylesheets/questions.scss +++ b/app/assets/stylesheets/questions.scss @@ -2,39 +2,45 @@ // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -.answers { - width: 100%; - border-bottom: 1px solid #ccc; +.question { + .question-text { + height: 3em; + } - .answer { - border-top: 1px solid #ccc; + .answers { + width: 100%; + border-bottom: 1px solid #ccc; - .text { - width: 50%; - } + .answer { + border-top: 1px solid #ccc; - td { - line-height: 2em; - div { - margin: 0.25em 0; - height: 1.5em; + .text { + width: 50%; } - } - .bar0 { - background-color: red; - } - .bar1 { - background-color: orange; - } - .bar2 { - background-color: lightgreen; - } - .bar3 { - background-color: green; - } - .bar4 { - background-color: gray; + td { + line-height: 2em; + div { + margin: 0.25em 0; + height: 1.5em; + } + } + + .bar0 { + background-color: red; + } + .bar1 { + background-color: orange; + } + .bar2 { + background-color: lightgreen; + } + .bar3 { + background-color: green; + } + .bar4 { + background-color: gray; + } } } } diff --git a/app/models/question.rb b/app/models/question.rb index 748b1c00..2578c61b 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -22,6 +22,12 @@ class Question < ApplicationRecord scope :for_category, -> (category) { where(category: category) } + enum target_group: [:unknown, :for_students, :for_teachers, :for_parents] + + def source + target_group.gsub('for_', '') + end + def options [option1, option2, option3, option4, option5] end diff --git a/app/views/questions/_question.html.haml b/app/views/questions/_question.html.haml index ea19f542..ceb49ecc 100644 --- a/app/views/questions/_question.html.haml +++ b/app/views/questions/_question.html.haml @@ -4,7 +4,6 @@ .col-6.py-3 .question.p-2{id: "question-#{question.id}"} %p.question-text.pt-3.px-2 - %b Question: = question.text .pb-3.px-2 @@ -20,7 +19,7 @@ = truncate(aggregated_responses.most_popular_answer, length: 27) %p %b Source: - =# question.source(@school) + = question.source.titleize .clearfix diff --git a/db/migrate/20170316154053_add_target_group_to_question.rb b/db/migrate/20170316154053_add_target_group_to_question.rb new file mode 100644 index 00000000..79997c0c --- /dev/null +++ b/db/migrate/20170316154053_add_target_group_to_question.rb @@ -0,0 +1,5 @@ +class AddTargetGroupToQuestion < ActiveRecord::Migration[5.0] + def change + add_column :questions, :target_group, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 03f74196..6ea0561a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170312202259) do +ActiveRecord::Schema.define(version: 20170316154053) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -65,8 +65,9 @@ ActiveRecord::Schema.define(version: 20170312202259) do t.string "option4" t.string "option5" t.integer "category_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "target_group", default: 0 end create_table "recipient_lists", force: :cascade do |t| diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index abe2d17c..7f2058bd 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -143,7 +143,7 @@ namespace :data do bad_answers = {} year = '2016' ['student_responses', 'teacher_responses'].each do |file| - # source = Measurement.sources[file.split('_')[0]] + target_group = Question.target_groups["for_#{file.split('_')[0]}s"] csv_string = File.read(File.expand_path("../../../data/#{file}_#{year}.csv", __FILE__)) csv = CSV.parse(csv_string, :headers => true) csv.each do |row| @@ -179,6 +179,8 @@ namespace :data do puts "Unable to find question: #{key}" missing_questions[key] = true next + else + question.update_attributes(target_group: target_group) if question.unknown? end answer_index = question.option_index(value)