|
|
|
|
@ -1,10 +1,17 @@
|
|
|
|
|
module Report
|
|
|
|
|
class Subcategory
|
|
|
|
|
def self.create_report(schools: School.all, academic_years: AcademicYear.all, subcategories: ::Subcategory.all, filename: 'subcategories.csv')
|
|
|
|
|
def self.create_report(schools: School.all.includes(:district), academic_years: AcademicYear.all, subcategories: ::Subcategory.all, filename: 'subcategories.csv')
|
|
|
|
|
data = []
|
|
|
|
|
mutex = Thread::Mutex.new
|
|
|
|
|
data << ['District', 'School', 'School Code', 'Academic Year', 'Grades', 'Subcategory', 'Student Score', 'Student Zone', 'Teacher Score',
|
|
|
|
|
'Teacher Zone', 'Admin Score', 'Admin Zone', 'All Score (Average)', 'All Score Zone']
|
|
|
|
|
schools.each do |school|
|
|
|
|
|
pool_size = 2
|
|
|
|
|
jobs = Queue.new
|
|
|
|
|
schools.each { |school| jobs << school }
|
|
|
|
|
|
|
|
|
|
workers = pool_size.times.map do
|
|
|
|
|
Thread.new do
|
|
|
|
|
while school = jobs.pop(true)
|
|
|
|
|
academic_years.each do |academic_year|
|
|
|
|
|
subcategories.each do |subcategory|
|
|
|
|
|
respondents = Respondent.find_by(school:, academic_year:)
|
|
|
|
|
@ -20,6 +27,7 @@ module Report
|
|
|
|
|
|
|
|
|
|
all_grades = respondents.counts_by_grade.keys
|
|
|
|
|
grades = "#{all_grades.first}-#{all_grades.last}"
|
|
|
|
|
mutex.synchronize do
|
|
|
|
|
data << [school.district.name,
|
|
|
|
|
school.name,
|
|
|
|
|
school.dese_id,
|
|
|
|
|
@ -37,7 +45,12 @@ module Report
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
rescue ThreadError
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
workers.each(&:join)
|
|
|
|
|
FileUtils.mkdir_p Rails.root.join('tmp', 'reports')
|
|
|
|
|
filepath = Rails.root.join('tmp', 'reports', filename)
|
|
|
|
|
write_csv(data:, filepath:)
|
|
|
|
|
|