chore: start adding overview page

This commit is contained in:
Nelson Jovel 2024-01-17 12:49:23 -08:00
parent 1b0af124f7
commit 64b4d599c7
33 changed files with 783 additions and 199 deletions

View file

@ -1,32 +0,0 @@
module Dashboard
class DisaggregationLoader
attr_reader :path
def initialize(path:)
@path = path
initialize_directory
end
def load
data = {}
Dir.glob(Rails.root.join(path, "*.csv")).each do |filepath|
puts filepath
File.open(filepath) do |file|
headers = CSV.parse(file.first).first
file.lazy.each_slice(1000) do |lines|
CSV.parse(lines.join, headers:).map do |row|
values = DisaggregationRow.new(row:, headers:)
data[[values.lasid, values.district, values.academic_year]] = values
end
end
end
end
data
end
def initialize_directory
FileUtils.mkdir_p(path)
end
end
end

View file

@ -1,56 +0,0 @@
module Dashboard
class DisaggregationRow
attr_reader :row, :headers
def initialize(row:, headers:)
@row = row
@headers = headers
end
def district
@district ||= value_from(pattern: /District/i)
end
def academic_year
@academic_year ||= value_from(pattern: /Academic\s*Year/i)
end
def raw_income
@income ||= value_from(pattern: /Low\s*Income/i)
end
def lasid
@lasid ||= value_from(pattern: /LASID/i)
end
def raw_ell
@raw_ell ||= value_from(pattern: /EL Student First Year/i)
end
def ell
@ell ||= begin
value = value_from(pattern: /EL Student First Year/i).downcase
case value
when /lep student 1st year|LEP student not 1st year/i
"ELL"
when /Does not apply/i
"Not ELL"
else
"Unknown"
end
end
end
def value_from(pattern:)
output = nil
matches = headers.select do |header|
pattern.match(header)
end.map { |item| item.delete("\n") }
matches.each do |match|
output ||= row[match]
end
output
end
end
end

View file

@ -1,55 +0,0 @@
# frozen_string_literal: true
module Dashboard
class ResponseRateLoader
def self.reset(schools: School.all, academic_years: AcademicYear.all, subcategories: Subcategory.all)
subcategories.each do |subcategory|
schools.each do |school|
next if test_env? && (school != milford)
academic_years.each do |academic_year|
next if test_env? && (academic_year != test_year)
process_response_rate(subcategory:, school:, academic_year:)
end
end
end
end
private
def self.milford
School.find_by_slug "milford-high-school"
end
def self.test_year
AcademicYear.find_by_range "2020-21"
end
def self.rails_env
@rails_env ||= ENV["RAILS_ENV"]
end
def self.process_response_rate(subcategory:, school:, academic_year:)
student = StudentResponseRateCalculator.new(subcategory:, school:, academic_year:)
teacher = TeacherResponseRateCalculator.new(subcategory:, school:, academic_year:)
response_rate = ResponseRate.find_or_create_by!(subcategory:, school:, academic_year:)
response_rate.update!(student_response_rate: student.rate,
teacher_response_rate: teacher.rate,
meets_student_threshold: student.meets_student_threshold?,
meets_teacher_threshold: teacher.meets_teacher_threshold?)
end
def self.test_env?
rails_env == "test"
end
private_class_method :milford
private_class_method :test_year
private_class_method :rails_env
private_class_method :process_response_rate
private_class_method :test_env?
end
end