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.
23 lines
911 B
23 lines
911 B
require 'csv'
|
|
|
|
class AdminDataLoader
|
|
def self.load_data(filepath:)
|
|
CSV.parse(File.read(filepath), headers: true) do |row|
|
|
likert_score = row['LikertScore'] || row['Likert Score'] || row['Likert_Score']
|
|
likert_score = likert_score.to_f
|
|
likert_score = 1 if likert_score > 0 && likert_score < 1
|
|
next if likert_score == 0
|
|
|
|
ay = row['Academic Year'] || row['AcademicYear']
|
|
dese_id = row['DESE ID'] || row['Dese ID'] || row['Dese Id']
|
|
admin_data_item_id = row['Item ID'] || row['Item Id']
|
|
admin_data_value = AdminDataValue.new
|
|
admin_data_value.likert_score = likert_score
|
|
admin_data_value.academic_year = AcademicYear.find_by_range ay
|
|
admin_data_value.school = School.find_by_dese_id dese_id.to_i
|
|
admin_data_value.admin_data_item = AdminDataItem.find_by_admin_data_item_id admin_data_item_id
|
|
admin_data_value.save!
|
|
end
|
|
end
|
|
end
|