|
|
|
@ -1,10 +1,10 @@
|
|
|
|
module Report
|
|
|
|
module Report
|
|
|
|
class Subcategory
|
|
|
|
class Subcategory
|
|
|
|
def self.create_report(schools: School.all.includes(:district), 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 = []
|
|
|
|
data = []
|
|
|
|
mutex = Thread::Mutex.new
|
|
|
|
mutex = Thread::Mutex.new
|
|
|
|
data << ['District', 'School', 'School Code', 'Academic Year', 'Recorded Date Range', 'Grades', 'Subcategory', 'Student Score', 'Student Zone', 'Teacher Score',
|
|
|
|
data << ["District", "School", "School Code", "Academic Year", "Recorded Date Range", "Grades", "Subcategory", "Student Score", "Student Zone", "Teacher Score",
|
|
|
|
'Teacher Zone', 'Admin Score', 'Admin Zone', 'All Score (Average)', 'All Score Zone']
|
|
|
|
"Teacher Zone", "Admin Score", "Admin Zone", "All Score (Average)", "All Score Zone"]
|
|
|
|
pool_size = 2
|
|
|
|
pool_size = 2
|
|
|
|
jobs = Queue.new
|
|
|
|
jobs = Queue.new
|
|
|
|
schools.each { |school| jobs << school }
|
|
|
|
schools.each { |school| jobs << school }
|
|
|
|
@ -14,7 +14,7 @@ module Report
|
|
|
|
while school = jobs.pop(true)
|
|
|
|
while school = jobs.pop(true)
|
|
|
|
academic_years.each do |academic_year|
|
|
|
|
academic_years.each do |academic_year|
|
|
|
|
subcategories.each do |subcategory|
|
|
|
|
subcategories.each do |subcategory|
|
|
|
|
respondents = Respondent.find_by(school:, academic_year:)
|
|
|
|
respondents = Respondent.by_school_and_year(school:, academic_year:)
|
|
|
|
next if respondents.nil?
|
|
|
|
next if respondents.nil?
|
|
|
|
|
|
|
|
|
|
|
|
response_rate = subcategory.response_rate(school:, academic_year:)
|
|
|
|
response_rate = subcategory.response_rate(school:, academic_year:)
|
|
|
|
@ -58,8 +58,8 @@ module Report
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
workers.each(&:join)
|
|
|
|
workers.each(&:join)
|
|
|
|
FileUtils.mkdir_p Rails.root.join('tmp', 'reports')
|
|
|
|
FileUtils.mkdir_p Rails.root.join("tmp", "reports")
|
|
|
|
filepath = Rails.root.join('tmp', 'reports', filename)
|
|
|
|
filepath = Rails.root.join("tmp", "reports", filename)
|
|
|
|
write_csv(data:, filepath:)
|
|
|
|
write_csv(data:, filepath:)
|
|
|
|
data
|
|
|
|
data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@ -76,7 +76,7 @@ module Report
|
|
|
|
def self.student_score(row:)
|
|
|
|
def self.student_score(row:)
|
|
|
|
row in [response_rate, subcategory, school, academic_year]
|
|
|
|
row in [response_rate, subcategory, school, academic_year]
|
|
|
|
student_score = subcategory.student_score(school:, academic_year:) if response_rate.meets_student_threshold?
|
|
|
|
student_score = subcategory.student_score(school:, academic_year:) if response_rate.meets_student_threshold?
|
|
|
|
student_score || 'N/A'
|
|
|
|
student_score || "N/A"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.student_zone(row:)
|
|
|
|
def self.student_zone(row:)
|
|
|
|
@ -86,14 +86,14 @@ module Report
|
|
|
|
academic_year:).type.to_s.capitalize
|
|
|
|
academic_year:).type.to_s.capitalize
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
student_zone || 'N/A'
|
|
|
|
student_zone || "N/A"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.teacher_score(row:)
|
|
|
|
def self.teacher_score(row:)
|
|
|
|
row in [response_rate, subcategory, school, academic_year]
|
|
|
|
row in [response_rate, subcategory, school, academic_year]
|
|
|
|
teacher_score = subcategory.teacher_score(school:, academic_year:) if response_rate.meets_teacher_threshold?
|
|
|
|
teacher_score = subcategory.teacher_score(school:, academic_year:) if response_rate.meets_teacher_threshold?
|
|
|
|
|
|
|
|
|
|
|
|
teacher_score || 'N/A'
|
|
|
|
teacher_score || "N/A"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.teacher_zone(row:)
|
|
|
|
def self.teacher_zone(row:)
|
|
|
|
@ -102,20 +102,20 @@ module Report
|
|
|
|
teacher_zone = subcategory.teacher_zone(school:, academic_year:).type.to_s.capitalize
|
|
|
|
teacher_zone = subcategory.teacher_zone(school:, academic_year:).type.to_s.capitalize
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
teacher_zone || 'N/A'
|
|
|
|
teacher_zone || "N/A"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.admin_score(row:)
|
|
|
|
def self.admin_score(row:)
|
|
|
|
row in [response_rate, subcategory, school, academic_year]
|
|
|
|
row in [response_rate, subcategory, school, academic_year]
|
|
|
|
admin_score = subcategory.admin_score(school:, academic_year:)
|
|
|
|
admin_score = subcategory.admin_score(school:, academic_year:)
|
|
|
|
admin_score = 'N/A' unless admin_score >= 0
|
|
|
|
admin_score = "N/A" unless admin_score >= 0
|
|
|
|
admin_score
|
|
|
|
admin_score
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.admin_zone(row:)
|
|
|
|
def self.admin_zone(row:)
|
|
|
|
row in [response_rate, subcategory, school, academic_year]
|
|
|
|
row in [response_rate, subcategory, school, academic_year]
|
|
|
|
tmp_zone = subcategory.admin_zone(school:, academic_year:).type
|
|
|
|
tmp_zone = subcategory.admin_zone(school:, academic_year:).type
|
|
|
|
tmp_zone == :insufficient_data ? 'N/A' : tmp_zone.to_s.capitalize
|
|
|
|
tmp_zone == :insufficient_data ? "N/A" : tmp_zone.to_s.capitalize
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|