mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-10 16:00:33 -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
3589878700
commit
904d0d2f2c
4 changed files with 97 additions and 58 deletions
|
|
@ -4,6 +4,7 @@ require 'csv'
|
|||
|
||||
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)
|
||||
|
|
@ -12,8 +13,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
|
||||
|
|
@ -24,7 +27,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:)
|
||||
|
|
@ -32,6 +36,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
|
||||
|
|
@ -45,10 +54,13 @@ class AdminDataLoader
|
|||
end
|
||||
|
||||
def self.create_admin_data_value(row:, score:)
|
||||
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