chore:seed demographics

This commit is contained in:
Nelson Jovel 2024-01-12 15:36:23 -08:00
parent 27550e0b30
commit bd8dfe45d3
33 changed files with 2423 additions and 8 deletions

View file

@ -0,0 +1,32 @@
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