fixing bugs

pull/1/head
Jared Cosulich 7 years ago
parent 10945d6c71
commit 76bdb86211

@ -18,7 +18,7 @@ class CategoriesController < ApplicationController
@year = (params[:year] || @years.first).to_i @year = (params[:year] || @years.first).to_i
@years.delete(@year) @years.delete(@year)
@school_category = school_categories.in(@year).first @school_category = school_categories.in(@year).first
@child_school_categories = SchoolCategory.for_parent_category(@school, @category).valid @child_school_categories = SchoolCategory.for_parent_category(@school, @category).in(@year).valid
@questions = @category.questions @questions = @category.questions
end end

@ -12,6 +12,7 @@ class Recipient < ApplicationRecord
validates :name, presence: true validates :name, presence: true
scope :for_school, -> (school) { where(school: school) } scope :for_school, -> (school) { where(school: school) }
scope :created_in, -> (year) { where('extract(year from recipients.created_at) = ?', year) }
before_destroy :sync_lists before_destroy :sync_lists

@ -32,7 +32,7 @@ class SchoolCategory < ApplicationRecord
response_count: attempt_data.response_count || 0, response_count: attempt_data.response_count || 0,
answer_index_total: attempt_data.answer_index_total || 0, answer_index_total: attempt_data.answer_index_total || 0,
zscore: attempt_data.answer_index_total.nil? ? zscore: attempt_data.answer_index_total.nil? ?
zscore : (attempt_data.response_count > MIN_RESPONSE_COUNT ? zscore : nil) :
(attempt_data.response_count > MIN_RESPONSE_COUNT ? (attempt_data.response_count > MIN_RESPONSE_COUNT ?
(attempt_data.answer_index_total.to_f / attempt_data.response_count.to_f - 3.to_f) : (attempt_data.answer_index_total.to_f / attempt_data.response_count.to_f - 3.to_f) :
nil) nil)
@ -43,7 +43,7 @@ class SchoolCategory < ApplicationRecord
_aggregated_responses = aggregated_responses _aggregated_responses = aggregated_responses
child_school_categories = category.child_categories.collect do |cc| child_school_categories = category.child_categories.collect do |cc|
SchoolCategory.for(school, cc).valid SchoolCategory.for(school, cc).in(year).valid
end.flatten.compact end.flatten.compact
average_zscore = nil average_zscore = nil
@ -70,6 +70,7 @@ class SchoolCategory < ApplicationRecord
def sync_aggregated_responses def sync_aggregated_responses
return if ENV['BULK_PROCESS'] return if ENV['BULK_PROCESS']
update_attributes(chained_aggregated_responses) update_attributes(chained_aggregated_responses)
return if response_count == 0
if category.parent_category.present? if category.parent_category.present?
parent_school_category = SchoolCategory.for(school, category.parent_category).in(year).first parent_school_category = SchoolCategory.for(school, category.parent_category).in(year).first
if parent_school_category.nil? if parent_school_category.nil?

@ -1,2 +1,2 @@
%p %p
= school_category.category.path.map { |c| link_to(c.name, [school_category.school, c]) }.join(' > ').html_safe = school_category.category.path.map { |c| link_to(c.name, school_category_path(school_category.school, c, year: school_category.year)) }.join(' > ').html_safe

@ -1,7 +1,7 @@
.row .row
.col .col
=# link_to(image_tag(@district.logo), @district) if @district.present? =# link_to(image_tag(@district.logo), @district) if @district.present?
%h2= link_to @school.name, @school %h2= link_to @school.name, school_path(@school, year: @year)
= simple_format(@school.description) = simple_format(@school.description)
- if @year.present? - if @year.present?
%p %p

@ -1,7 +1,7 @@
.col-12.col-sm-6.py-3 .col-12.col-sm-6.py-3
.school_category.short.p-2 .school_category.short.p-2
%h4.title.text-center.pt-3 %h4.title.text-center.pt-3
= link_to(school_category.category.name, [school_category.school, school_category.category]) = link_to(school_category.category.name, school_category_path(school_category.school, school_category.category, year: school_category.year))
.indicator-container.short .indicator-container.short
= render 'school_categories/indicator', info: school_category = render 'school_categories/indicator', info: school_category

@ -8,6 +8,7 @@
%h3 Insufficient Responses %h3 Insufficient Responses
%p No data is displayed for this school because of insufficient responses. %p No data is displayed for this school because of insufficient responses.
- else - else
= render @school_categories .row
= render @school_categories
= render "shared/performance_spectrum" = render "shared/performance_spectrum"

File diff suppressed because one or more lines are too long

@ -1,12 +1,10 @@
# PSQL: /Applications/Postgres.app/Contents/Versions/9.6/bin/psql -h localhost # PSQL: /Applications/Postgres.app/Contents/Versions/9.6/bin/psql -h localhost
# LOAD DATA # LOAD DATA
# RAILS_ENV=development rails db:environment:set db:drop db:create db:migrate # RAILS_ENV=development rails db:environment:set db:drop db:create db:migrate; /Applications/Postgres.app/Contents/Versions/9.6/bin/pg_restore --verbose --clean --no-acl --no-owner -h localhost -d mciea_development latest.dump; rake db:migrate;
# /Applications/Postgres.app/Contents/Versions/9.6/bin/pg_restore --verbose --clean --no-acl --no-owner -h localhost -d mciea_development latest.dump # rails c -> SchoolCategory.update_all(year: '2017')
# rake db:migrate # rake data:load_questions_csv; rake data:load_responses
# run console: SchoolCategory.update_all(year: '2017')
# rake data:load_questions_csv
# rake data:load_responses
# sudo heroku run:detached rake data:load_responses -a mciea-beta --size performance-l # sudo heroku run:detached rake data:load_responses -a mciea-beta --size performance-l
# Add: # Add:
@ -20,6 +18,8 @@
require 'csv' require 'csv'
namespace :data do namespace :data do
@year = 2018
desc "Load in all data" desc "Load in all data"
task load: :environment do task load: :environment do
# return if School.count > 0 # return if School.count > 0
@ -192,7 +192,6 @@ namespace :data do
unknown_schools = {} unknown_schools = {}
missing_questions = {} missing_questions = {}
bad_answers = {} bad_answers = {}
year = '2018'
timeToRun = 120 * 60 timeToRun = 120 * 60
startIndex = 0 startIndex = 0
@ -203,7 +202,7 @@ namespace :data do
['student_responses'].each do |file| ['student_responses'].each do |file|
recipients = file.split('_')[0] recipients = file.split('_')[0]
target_group = Question.target_groups["for_#{recipients}s"] target_group = Question.target_groups["for_#{recipients}s"]
csv_string = File.read(File.expand_path("../../../data/#{file}_#{year}.csv", __FILE__)) csv_string = File.read(File.expand_path("../../../data/#{file}_#{@year}.csv", __FILE__))
csv = CSV.parse(csv_string, :headers => true) csv = CSV.parse(csv_string, :headers => true)
puts("LOADING CSV: #{csv.length} ROWS") puts("LOADING CSV: #{csv.length} ROWS")
@ -244,7 +243,7 @@ namespace :data do
next next
end end
respondent_id = row['StudentID'] respondent_id = row['X']
recipient_id = respondent_map["#{school.id}-#{respondent_id}"] recipient_id = respondent_map["#{school.id}-#{respondent_id}"]
if recipient_id.present? if recipient_id.present?
recipient = school.recipients.where(id: recipient_id).first recipient = school.recipients.where(id: recipient_id).first
@ -271,7 +270,7 @@ namespace :data do
row.each do |key, value| row.each do |key, value|
t1 = Time.new t1 = Time.new
next if value.nil? or key.nil? or value.to_s == "-99" next if value.nil? or key.nil? or value.to_s == "-99"
key = key.gsub(/[[:space:]]/, ' ').strip.gsub(/\s+/, ' ') key = key.gsub(/[[:space:]]/, ' ').gsub(/\./, '-').strip.gsub(/\s+/, ' ')
value = value.gsub(/[[:space:]]/, ' ').strip.downcase value = value.gsub(/[[:space:]]/, ' ').strip.downcase
begin begin
@ -307,7 +306,9 @@ namespace :data do
answer_index = value.to_i answer_index = value.to_i
end end
responded_at = Date.strptime(row['End Date'], '%m/%d/%Y %H:%M') next if answer_index == 0
responded_at = Date.today#strptime(row['End Date'], '%m/%d/%Y %H:%M')
begin begin
recipient.attempts.create(question: question, answer_index: answer_index, responded_at: responded_at) recipient.attempts.create(question: question, answer_index: answer_index, responded_at: responded_at)
rescue Exception => e rescue Exception => e
@ -321,7 +322,7 @@ namespace :data do
sync_school_category_aggregates sync_school_category_aggregates
Recipient.all.each { |r| r.update_counts } Recipient.created_in(@year).each { |r| r.update_counts }
end end
desc 'Load in nonlikert values for each school' desc 'Load in nonlikert values for each school'
@ -426,14 +427,15 @@ namespace :data do
end end
def sync_school_category_aggregates def sync_school_category_aggregates
year = 2018 # School.all.each do |school|
School.all.each do |school| District.where(name: 'Winchester').first.schools.where(name: "Ambrose Elementary School").each do |school|
Category.all.each do |category| Category.all.each do |category|
school_category = SchoolCategory.for(school, category).in(year).first school_category = SchoolCategory.for(school, category).in(@year).first
if school_category.nil? if school_category.nil?
school_category = school.school_categories.create(category: category, year: year) school_category = school.school_categories.create(category: category, year: @year)
end end
school_category.sync_aggregated_responses school_category.sync_aggregated_responses
puts("SYNC: #{school.name}-#{category.name}-#{@year}: #{school_category.answer_index_total}")
end end
end end
end end

Loading…
Cancel
Save