diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index abd79446..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index 724057be..ef8c94a2 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ # Ignore Byebug command history file. .byebug_history config/local_env.yml +.DS_Store diff --git a/app/models/school_category.rb b/app/models/school_category.rb index 330fad4d..91137019 100644 --- a/app/models/school_category.rb +++ b/app/models/school_category.rb @@ -35,6 +35,15 @@ class SchoolCategory < ApplicationRecord SchoolCategory.for(school, cc) end.flatten + new_zscore = zscore + if new_zscore.nil? + zscore_categories = child_school_categories.select { |csc| csc.zscore.present? } + if zscore_categories.length > 0 + total_zscore = zscore_categories.inject(0) { |total, zc| total + zc.zscore } + new_zscore = total_zscore / zscore_categories.length + end + end + return { attempt_count: _aggregated_responses[:attempt_count] + @@ -44,7 +53,8 @@ class SchoolCategory < ApplicationRecord child_school_categories.inject(0) { |total, csc| total + csc.response_count }, answer_index_total: _aggregated_responses[:answer_index_total] + - child_school_categories.inject(0) { |total, csc| total + csc.answer_index_total } + child_school_categories.inject(0) { |total, csc| total + csc.answer_index_total }, + zscore: new_zscore } end diff --git a/app/views/categories/show.html.haml b/app/views/categories/show.html.haml index 12cd8c15..0e41ff21 100644 --- a/app/views/categories/show.html.haml +++ b/app/views/categories/show.html.haml @@ -13,14 +13,23 @@ %p= @category.description %p - %b Total Responses: - = number_with_delimiter(@school_category.response_count) + - if @school_category.response_count > 0 + %b Total Responses: + = number_with_delimiter(@school_category.response_count) -       +       - %b Average Response: - = @school_category.answer_index_average.round(1) - (out of 5) + %b Average Response: + = @school_category.answer_index_average.round(1) + (out of 5) + + - if @school_category.response_count > 0 && @school_category.zscore.present? +       + + - if @school_category.zscore.present? + %b Administrative Data + = @school_category.zscore.round(1) + 3 + (out of 5) .indicator-container.py-3 = render 'school_categories/indicator', info: @school_category diff --git a/app/views/school_categories/_indicator.html.haml b/app/views/school_categories/_indicator.html.haml index cbeb6cef..734124fd 100644 --- a/app/views/school_categories/_indicator.html.haml +++ b/app/views/school_categories/_indicator.html.haml @@ -1,5 +1,11 @@ - num_likerts = 5 + - likert = info.answer_index_average +- zscore = info.zscore.present? ? info.zscore + 3 : nil +- if zscore.present? + - likert = info.answer_index_average.nan? ? zscore : (info.answer_index_average + zscore) / 2 +- likert = likert.round(1) + - average_offset = (likert/num_likerts) * 100 - approval_zone = [[76, 90], [77, 91], [71, 85], [73, 86], [73, 86], []][info.category.root_index] @@ -32,7 +38,7 @@ This School - else .average{style: "left: #{average_offset - 5}%", title: this_school_zone} - %span This School + %span= "This School #{likert}" - if local_assigns[:caption] .explanation diff --git a/data/samplenonlikert.csv b/data/samplenonlikert.csv new file mode 100644 index 00000000..ee9ba516 --- /dev/null +++ b/data/samplenonlikert.csv @@ -0,0 +1 @@ +NonLikert Title,District,School,Value,Z-Score Percentage of Teachers Working in Area of Licensure,Winchester,Vinson-Owen Elementary School,100%,2 Percentage of Teachers Working in Area of Licensure,Winchester,Lynch Elementary School,100%,2 Percentage of Teachers Working in Area of Licensure,Winchester,McCall Middle School,100%,2 \ No newline at end of file diff --git a/db/migrate/20180120150542_add_z_score_to_school_categories.rb b/db/migrate/20180120150542_add_z_score_to_school_categories.rb new file mode 100644 index 00000000..b2234f58 --- /dev/null +++ b/db/migrate/20180120150542_add_z_score_to_school_categories.rb @@ -0,0 +1,5 @@ +class AddZScoreToSchoolCategories < ActiveRecord::Migration[5.0] + def change + add_column :school_categories, :zscore, :float + end +end diff --git a/db/schema.rb b/db/schema.rb index 72ddc896..99289e89 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: 20180119145356) do +ActiveRecord::Schema.define(version: 20180120150542) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -147,6 +147,7 @@ ActiveRecord::Schema.define(version: 20180119145356) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.float "nonlikert" + t.float "zscore" t.index ["category_id"], name: "index_school_categories_on_category_id", using: :btree t.index ["school_id"], name: "index_school_categories_on_school_id", using: :btree end diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index ec97177c..ade44a9a 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -241,16 +241,48 @@ namespace :data do end end ENV.delete('BULK_PROCESS') + + sync_school_category_aggregates + + Recipient.all.each { |r| r.update_counts } + end + + desc 'Load in nonlikert values for each school' + task load_nonlikert_values: :environment do + ENV['BULK_PROCESS'] = 'true' + + csv_string = File.read(File.expand_path("../../../data/samplenonlikert.csv", __FILE__)) + csv = CSV.parse(csv_string, :headers => true) + puts("LOADING NONLIKERT CSV: #{csv.length} ROWS") + + t = Time.new + school_category_id = -1 + csv.each_with_index do |row, index| + nonlikert_category = Category.find_by_name(row["NonLikert Title"]) + district = District.find_by_name(row["District"]) + school = district.schools.find_by_name(row["School"]) + school_category = school.school_categories.find_or_create_by(category: nonlikert_category) + school_category.update( + nonlikert: row["Value"], + zscore: row["Z-Score"] + ) + school_category_id = school_category.id + end + + ENV.delete('BULK_PROCESS') + + sync_school_category_aggregates + end + + def sync_school_category_aggregates School.all.each do |school| Category.all.each do |category| school_category = SchoolCategory.for(school, category).first if school_category.nil? - school_category = SchoolCategory.create(school: school, category: category) + school_category = school.school_categories.create(category: category) end school_category.sync_aggregated_responses end end - - Recipient.all.each { |r| r.update_counts } end end