You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
680 B
32 lines
680 B
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
|
|
|