From 10945d6c712e33389f88e58c2f05e00451a718f8 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Sat, 21 Jul 2018 13:32:46 -0400 Subject: [PATCH] working on yearly aggregation --- app/models/school_category.rb | 12 ++++++------ lib/tasks/data.rake | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/school_category.rb b/app/models/school_category.rb index 56805fbb..7a108427 100644 --- a/app/models/school_category.rb +++ b/app/models/school_category.rb @@ -18,7 +18,7 @@ class SchoolCategory < ApplicationRecord answer_index_total.to_f / response_count.to_f end - def aggregated_responses(year) + def aggregated_responses attempt_data = Attempt. created_in(year). for_category(category). @@ -39,8 +39,8 @@ class SchoolCategory < ApplicationRecord } end - def chained_aggregated_responses(year) - _aggregated_responses = aggregated_responses(year) + def chained_aggregated_responses + _aggregated_responses = aggregated_responses child_school_categories = category.child_categories.collect do |cc| SchoolCategory.for(school, cc).valid @@ -67,15 +67,15 @@ class SchoolCategory < ApplicationRecord } end - def sync_aggregated_responses(year) + def sync_aggregated_responses return if ENV['BULK_PROCESS'] - update_attributes(chained_aggregated_responses(year)) + update_attributes(chained_aggregated_responses) if category.parent_category.present? parent_school_category = SchoolCategory.for(school, category.parent_category).in(year).first if parent_school_category.nil? parent_school_category = SchoolCategory.create(school: school, category: category.parent_category, year: year) end - parent_school_category.sync_aggregated_responses(year) + parent_school_category.sync_aggregated_responses end end end diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 1aac4af6..21ff3d86 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -426,14 +426,14 @@ namespace :data do end def sync_school_category_aggregates - year = '2018' + year = 2018 School.all.each do |school| Category.all.each do |category| school_category = SchoolCategory.for(school, category).in(year).first if school_category.nil? school_category = school.school_categories.create(category: category, year: year) end - school_category.sync_aggregated_responses(year) + school_category.sync_aggregated_responses end end end