mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 07:28:41 -07:00
It's possible for admin data likert score values to be above 5. If that happens, we
cap the likert score at 5. This was happening already at the scraper level but it's also now being done by the admin data loader for safety. Also make sure to just update admin data instead of deleting and reloading all values each load. Add tests to confirm this behavior
This commit is contained in:
parent
c789c46032
commit
0f23053294
6 changed files with 223 additions and 59 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class AdminDataLoader
|
||||
def self.load_data(filepath:)
|
||||
admin_data_values = []
|
||||
CSV.parse(File.read(filepath), headers: true) do |row|
|
||||
score = likert_score(row:)
|
||||
unless valid_likert_score(likert_score: score)
|
||||
|
|
@ -10,8 +11,10 @@ class AdminDataLoader
|
|||
admin data item #{admin_data_item(row:)} "
|
||||
next
|
||||
end
|
||||
create_admin_data_value(row:, score:)
|
||||
admin_data_values << create_admin_data_value(row:, score:)
|
||||
end
|
||||
|
||||
AdminDataValue.import(admin_data_values.flatten.compact, on_duplicate_key_update: :all)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -22,7 +25,8 @@ class AdminDataLoader
|
|||
|
||||
def self.likert_score(row:)
|
||||
likert_score = (row['LikertScore'] || row['Likert Score'] || row['Likert_Score']).to_f
|
||||
round_up_to_one(likert_score:)
|
||||
likert_score = round_up_to_one(likert_score:)
|
||||
round_down_to_five(likert_score:)
|
||||
end
|
||||
|
||||
def self.round_up_to_one(likert_score:)
|
||||
|
|
@ -30,6 +34,11 @@ class AdminDataLoader
|
|||
likert_score
|
||||
end
|
||||
|
||||
def self.round_down_to_five(likert_score:)
|
||||
likert_score = 5 if likert_score > 5
|
||||
likert_score
|
||||
end
|
||||
|
||||
def self.ay(row:)
|
||||
row['Academic Year'] || row['AcademicYear']
|
||||
end
|
||||
|
|
@ -43,11 +52,13 @@ class AdminDataLoader
|
|||
end
|
||||
|
||||
def self.create_admin_data_value(row:, score:)
|
||||
# byebug unless %w[a-vale-i1 a-sust-i3].include? admin_data_item(row:)
|
||||
AdminDataValue.create!(likert_score: score,
|
||||
academic_year: AcademicYear.find_by_range(ay(row:)),
|
||||
school: School.find_by_dese_id(dese_id(row:).to_i),
|
||||
admin_data_item: AdminDataItem.find_by_admin_data_item_id(admin_data_item(row:)))
|
||||
admin_data_value = AdminDataValue.find_or_initialize_by(school: School.find_by_dese_id(dese_id(row:).to_i),
|
||||
academic_year: AcademicYear.find_by_range(ay(row:)),
|
||||
admin_data_item: AdminDataItem.find_by_admin_data_item_id(admin_data_item(row:)))
|
||||
return nil if admin_data_value.likert_score == score
|
||||
|
||||
admin_data_value.likert_score = score
|
||||
admin_data_value
|
||||
end
|
||||
|
||||
private_class_method :valid_likert_score
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue