Load 2020-21 student survey responses

pull/1/head
Alex Basson 4 years ago
parent edb1548593
commit fd091cfa4f

@ -7,7 +7,7 @@ class SurveyResponsesDataLoader
parsed_csv_file = CSV.parse(csv_file, headers: true) parsed_csv_file = CSV.parse(csv_file, headers: true)
survey_items = parsed_csv_file.headers survey_items = parsed_csv_file.headers
.filter { |header| !header.nil? } .filter { |header| !header.nil? }
.filter { |header| header.start_with? 't-' } .filter { |header| header.start_with? 't-' or header.start_with? 's-' }
.map { |survey_item_id| SurveyItem.find_by_survey_item_id survey_item_id } .map { |survey_item_id| SurveyItem.find_by_survey_item_id survey_item_id }
parsed_csv_file.each do |row| parsed_csv_file.each do |row|
@ -29,9 +29,9 @@ class SurveyResponsesDataLoader
school = school(row: row) school = school(row: row)
return if school.nil? return if school.nil?
return unless SurveyItemResponse.find_by_response_id(response_id).nil?
survey_items.each do |survey_item| survey_items.each do |survey_item|
return unless SurveyItemResponse.where(response_id: response_id, survey_item: survey_item).empty?
likert_score = row[survey_item.survey_item_id] likert_score = row[survey_item.survey_item_id]
next if likert_score.nil? next if likert_score.nil?
SurveyItemResponse.create( SurveyItemResponse.create(

File diff suppressed because it is too large Load Diff

@ -38,9 +38,12 @@ namespace :data do
desc "load survey responses" desc "load survey responses"
task load_survey_responses: :environment do task load_survey_responses: :environment do
filepath = Rails.root.join('data', 'survey_results', '2020-21_teacher_survey_responses.csv') survey_groups = %w(2020-21_teacher 2020-21_student)
puts "=====================> Loading data from csv at path: #{filepath}" survey_groups.each do |survey_group|
SurveyResponsesDataLoader.load_data filepath: filepath filepath = Rails.root.join('data', 'survey_results', "#{survey_group}_survey_responses.csv")
puts "=====================> Loading data from csv at path: #{filepath}"
SurveyResponsesDataLoader.load_data filepath: filepath
end
puts "=====================> Completed loading #{SurveyItemResponse.count} survey responses" puts "=====================> Completed loading #{SurveyItemResponse.count} survey responses"
end end

@ -0,0 +1,6 @@
Start Date,End Date,Response Type,IP Address,Progress,Duration (in seconds),Finished,Recorded Date,Response ID,Recipient Last Name,Recipient First Name,Recipient Email,External Data Reference,Location Latitude,Location Longitude,Distribution Channel,User Language,district_code,school_code,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,s-emsa-q1,s-emsa-q2,s-emsa-q3,s-tint-q1,s-tint-q2,#N/A,s-tint-q4,s-tint-q5,s-acpr-q1,s-acpr-q2,s-acpr-q3,s-acpr-q4,#N/A,#N/A,s-cure-q3,s-cure-q4,#N/A,s-sten-q2,s-sten-q3,s-sper-q1,s-sper-q2,s-sper-q3,s-sper-q4,s-civp-q1,s-civp-q2,s-civp-q3,s-civp-q4,s-grmi-q1,#N/A,#N/A,s-grmi-q4,s-appa-q1,s-appa-q2,#N/A,s-peff-q1,s-peff-q2,s-peff-q3,s-peff-q4,s-peff-q5,s-peff-q6,s-sbel-q1,s-sbel-q2,s-sbel-q3,s-sbel-q4,s-sbel-q5,s-phys-q1,s-phys-q2,s-phys-q3,s-phys-q4,s-vale-q1,#N/A,#N/A,s-vale-q4,#N/A,s-acst-q2,s-acst-q3,#N/A,#N/A,s-grit-q1,s-grit-q2,s-grit-q3,s-grit-q4,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A
2020-09-29 18:28:41,2020-09-29 18:48:28,0,73.249.89.226,6,1186,0,2020-09-30 18:48:50,student_survey_response_1,,,,,,,anonymous,EN,1,8,,,,dddd,4,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EN,,,,
2021-02-23 15:12:58,2021-02-23 15:13:17,0,50.207.254.114,0,19,0,2021-02-24 15:13:19,student_survey_response_2,,,,,,,anonymous,EN,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EN,,,,
2021-03-31 9:50:19,2021-03-31 9:59:01,0,108.7.17.250,100,522,1,2021-03-31 9:59:02,student_survey_response_3,,,,,42.53340149,-70.96530151,anonymous,EN,3,2,12,4,108,3300,7,1,,,,,,,,,,,,,,2,4,2,1,4,3,3,,,,,3,3,3,3,,,,,,,,,,,,,,3,2,3,3,2,1,3,4,1,3,3,4,4,2,4,3,3,4,3,3,3,4,3,3,3,3,3,,,,,,,,,,3,4,4,2,3,3,1,,3,,EN,Math teacher,,,
2021-03-31 9:50:09,2021-03-31 10:00:16,0,67.186.188.168,100,607,1,2021-03-31 10:00:17,student_survey_response_4,,,,,42.63510132,-71.30139923,anonymous,EN,3,2,12,18,108,2064,7,1,,2,2,1,,,,,,,,,,,,,,,,,,,,,,,,,3,5,3,3,,,,,,,,,,4,4,3,4,5,1,1,5,1,3,2,4,4,1,2,1,3,2,3,3,3,4,2,5,3,4,5,5,3,3,4,3,,,,,4,4,4,4,3,5,2,,2,,EN,,,,English teacher
2021-03-31 9:51:39,2021-03-31 10:01:36,0,73.47.153.77,100,596,1,2021-03-31 10:01:36,student_survey_response_5,,,,,42.65820313,-71.30580139,anonymous,EN,3,2,6,15,109,3710,7,1,,2,2,2,,,,,,,,,,3,3,4,3,3,3,3,4,3,4,3,4,4,5,4,3,4,3,5,2,2,3,,,,,,,,,,,,1,2,5,1,3,3,2,4,3,5,4,,,,,,,,,,,,5,4,3,4,4,4,4,4,4,,,,,,,2,,2,,EN,,,Social Studies teacher,
1 Start Date End Date Response Type IP Address Progress Duration (in seconds) Finished Recorded Date Response ID Recipient Last Name Recipient First Name Recipient Email External Data Reference Location Latitude Location Longitude Distribution Channel User Language district_code school_code #N/A #N/A #N/A #N/A #N/A #N/A #N/A s-emsa-q1 s-emsa-q2 s-emsa-q3 s-tint-q1 s-tint-q2 #N/A s-tint-q4 s-tint-q5 s-acpr-q1 s-acpr-q2 s-acpr-q3 s-acpr-q4 #N/A #N/A s-cure-q3 s-cure-q4 #N/A s-sten-q2 s-sten-q3 s-sper-q1 s-sper-q2 s-sper-q3 s-sper-q4 s-civp-q1 s-civp-q2 s-civp-q3 s-civp-q4 s-grmi-q1 #N/A #N/A s-grmi-q4 s-appa-q1 s-appa-q2 #N/A s-peff-q1 s-peff-q2 s-peff-q3 s-peff-q4 s-peff-q5 s-peff-q6 s-sbel-q1 s-sbel-q2 s-sbel-q3 s-sbel-q4 s-sbel-q5 s-phys-q1 s-phys-q2 s-phys-q3 s-phys-q4 s-vale-q1 #N/A #N/A s-vale-q4 #N/A s-acst-q2 s-acst-q3 #N/A #N/A s-grit-q1 s-grit-q2 s-grit-q3 s-grit-q4 #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A
2 2020-09-29 18:28:41 2020-09-29 18:48:28 0 73.249.89.226 6 1186 0 2020-09-30 18:48:50 student_survey_response_1 anonymous EN 1 8 dddd 4 3 EN
3 2021-02-23 15:12:58 2021-02-23 15:13:17 0 50.207.254.114 0 19 0 2021-02-24 15:13:19 student_survey_response_2 anonymous EN EN
4 2021-03-31 9:50:19 2021-03-31 9:59:01 0 108.7.17.250 100 522 1 2021-03-31 9:59:02 student_survey_response_3 42.53340149 -70.96530151 anonymous EN 3 2 12 4 108 3300 7 1 2 4 2 1 4 3 3 3 3 3 3 3 2 3 3 2 1 3 4 1 3 3 4 4 2 4 3 3 4 3 3 3 4 3 3 3 3 3 3 4 4 2 3 3 1 3 EN Math teacher
5 2021-03-31 9:50:09 2021-03-31 10:00:16 0 67.186.188.168 100 607 1 2021-03-31 10:00:17 student_survey_response_4 42.63510132 -71.30139923 anonymous EN 3 2 12 18 108 2064 7 1 2 2 1 3 5 3 3 4 4 3 4 5 1 1 5 1 3 2 4 4 1 2 1 3 2 3 3 3 4 2 5 3 4 5 5 3 3 4 3 4 4 4 4 3 5 2 2 EN English teacher
6 2021-03-31 9:51:39 2021-03-31 10:01:36 0 73.47.153.77 100 596 1 2021-03-31 10:01:36 student_survey_response_5 42.65820313 -71.30580139 anonymous EN 3 2 6 15 109 3710 7 1 2 2 2 3 3 4 3 3 3 3 4 3 4 3 4 4 5 4 3 4 3 5 2 2 3 1 2 5 1 3 3 2 4 3 5 4 5 4 3 4 4 4 4 4 4 2 2 EN Social Studies teacher

@ -1,6 +1,6 @@
Start Date,End Date,Response Type,IP Address,Progress,Duration (in seconds),Finished,Recorded Date,Response ID,Recipient Last Name,Recipient First Name,Recipient Email,External Data Reference,Location Latitude,Location Longitude,Distribution Channel,User Language,district_code,school_code,,,t-prep-q1,t-prep-q2,t-prep-q3,t-pcom-q1,t-pcom-q2,t-pcom-q3,t-pcom-q4,t-pcom-q5,t-ieff-q1,t-ieff-q2,t-ieff-q3,t-ieff-q4,t-qupd-q3,t-qupd-q2,t-qupd-q1,t-qupd-q4,t-coll-q1,t-coll-q2,t-coll-q3,t-prtr-q1,t-prtr-q2,t-prtr-q3,t-inle-q1,"t-inle-q2",t-inle-q3,t-pvic-q1,t-pvic-q2,t-pvic-q3,t-psup-q1,t-psup-q2,t-psup-q3,t-psup-q4,t-acch-q1,t-acch-q2,t-acch-q3,t-reso-q1,t-reso-q2,t-reso-q3,t-reso-q4,t-reso-q5,t-sust-q1,t-sust-q2,t-sust-q3,t-sust-q4,t-curv-q1,t-curv-q2,t-curv-q3,t-curv-q4,t-cure-q1,t-cure-q2,t-cure-q3,t-cure-q4,t-peng-q1,t-peng-q2,t-peng-q3,t-peng-q4,t-ceng-q1,t-ceng-q2,t-ceng-q3,t-ceng-q4,#N/A,t-sach-q2,t-sach-q3,t-psol-q1,t-psol-q2,t-psol-q3,t-expa-q2,t-expa-q3,t-phya-q2,t-phya-q3,,,, Start Date,End Date,Response Type,IP Address,Progress,Duration (in seconds),Finished,Recorded Date,Response ID,Recipient Last Name,Recipient First Name,Recipient Email,External Data Reference,Location Latitude,Location Longitude,Distribution Channel,User Language,district_code,school_code,,,t-prep-q1,t-prep-q2,t-prep-q3,t-pcom-q1,t-pcom-q2,t-pcom-q3,t-pcom-q4,t-pcom-q5,t-ieff-q1,t-ieff-q2,t-ieff-q3,t-ieff-q4,t-qupd-q3,t-qupd-q2,t-qupd-q1,t-qupd-q4,t-coll-q1,t-coll-q2,t-coll-q3,t-prtr-q1,t-prtr-q2,t-prtr-q3,t-inle-q1,"t-inle-q2",t-inle-q3,t-pvic-q1,t-pvic-q2,t-pvic-q3,t-psup-q1,t-psup-q2,t-psup-q3,t-psup-q4,t-acch-q1,t-acch-q2,t-acch-q3,t-reso-q1,t-reso-q2,t-reso-q3,t-reso-q4,t-reso-q5,t-sust-q1,t-sust-q2,t-sust-q3,t-sust-q4,t-curv-q1,t-curv-q2,t-curv-q3,t-curv-q4,t-cure-q1,t-cure-q2,t-cure-q3,t-cure-q4,t-peng-q1,t-peng-q2,t-peng-q3,t-peng-q4,t-ceng-q1,t-ceng-q2,t-ceng-q3,t-ceng-q4,#N/A,t-sach-q2,t-sach-q3,t-psol-q1,t-psol-q2,t-psol-q3,t-expa-q2,t-expa-q3,t-phya-q2,t-phya-q3,,,,
2020-10-09 9:42:45,2020-10-09 11:08:57,0,50.204.125.194,93,5172,0,2020-10-16 11:09:03,survey_response_1,,,,,,,anonymous,EN,1,1,4,,,,,,,3,,,,,,,,,,,3,3,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5,,,,,,,,,,,, 2020-10-09 9:42:45,2020-10-09 11:08:57,0,50.204.125.194,93,5172,0,2020-10-16 11:09:03,teacher_survey_response_1,,,,,,,anonymous,EN,1,1,4,,,,,,,3,,,,,,,,,,,3,3,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5,,,,,,,,,,,,
2020-10-09 9:21:30,2020-10-09 14:28:09,0,50.204.125.194,24,18398,0,2020-10-16 14:28:18,survey_response_2,,,,,,,anonymous,EN,1,1,4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2020-10-09 9:21:30,2020-10-09 14:28:09,0,50.204.125.194,24,18398,0,2020-10-16 14:28:18,teacher_survey_response_2,,,,,,,anonymous,EN,1,1,4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2020-12-06 8:28:00,2020-12-06 8:36:52,0,73.61.140.32,100,532,1,2020-12-06 8:36:52,survey_response_3,,,,,41.92610168,-71.30110168,anonymous,EN,1,2,2,,5,5,5,5,5,5,5,1,5,5,5,5,3,2,1,5,4,5,5,4,4,5,5,5,5,3,3,3,3,1,3,3,4,3,2,4,4,4,4,3,3,2,2,2,4,4,4,3,2,3,2,5,4,5,5,3,4,4,3,5,2,1,3,4,3,3,4,4,3,3,,9,9, 2020-12-06 8:28:00,2020-12-06 8:36:52,0,73.61.140.32,100,532,1,2020-12-06 8:36:52,teacher_survey_response_3,,,,,41.92610168,-71.30110168,anonymous,EN,1,2,2,,5,5,5,5,5,5,5,1,5,5,5,5,3,2,1,5,4,5,5,4,4,5,5,5,5,3,3,3,3,1,3,3,4,3,2,4,4,4,4,3,3,2,2,2,4,4,4,3,2,3,2,5,4,5,5,3,4,4,3,5,2,1,3,4,3,3,4,4,3,3,,9,9,
2020-12-06 8:41:41,2020-12-06 8:51:25,0,96.230.183.162,100,584,1,2020-12-06 8:51:25,survey_response_4,,,,,41.98530579,-71.5184021,anonymous,EN,1,2,2,,5,5,5,4,4,4,4,1,4,4,4,4,3,3,3,2,5,2,4,5,4,5,4,4,4,3,3,3,3,4,4,3,3,3,3,3,4,3,3,4,4,3,2,4,4,4,4,4,3,2,3,4,5,3,2,2,4,4,3,3,4,3,3,3,3,3,3,4,3,3,,9,6, 2020-12-06 8:41:41,2020-12-06 8:51:25,0,96.230.183.162,100,584,1,2020-12-06 8:51:25,teacher_survey_response_4,,,,,41.98530579,-71.5184021,anonymous,EN,1,2,2,,5,5,5,4,4,4,4,1,4,4,4,4,3,3,3,2,5,2,4,5,4,5,4,4,4,3,3,3,3,4,4,3,3,3,3,3,4,3,3,4,4,3,2,4,4,4,4,4,3,2,3,4,5,3,2,2,4,4,3,3,4,3,3,3,3,3,3,4,3,3,,9,6,
2020-12-06 8:44:42,2020-12-06 8:55:58,0,216.41.82.178,100,675,1,2020-12-06 8:55:58,survey_response_5,,,,,41.92610168,-71.30110168,anonymous,EN,1,2,2,,5,4,4,2,2,4,1,2,4,4,4,4,3,3,3,2,4,3,5,4,3,4,3,3,4,2,2,4,4,2,4,3,4,4,3,3,2,3,2,3,3,2,4,4,3,4,4,3,2,2,4,4,5,2,3,1,4,4,3,3,3,2,2,4,4,3,3,3,3,3,,7,5,"These questions are very difficult to address during a PANDEMIC! So it is not your average typical year. Our principal may not be as concerned about academics, because they are too busy navigating the complexities COVID has caused. I am honestly unsure why we would get surveyed during this time. " 2020-12-06 8:44:42,2020-12-06 8:55:58,0,216.41.82.178,100,675,1,2020-12-06 8:55:58,teacher_survey_response_5,,,,,41.92610168,-71.30110168,anonymous,EN,1,2,2,,5,4,4,2,2,4,1,2,4,4,4,4,3,3,3,2,4,3,5,4,3,4,3,3,4,2,2,4,4,2,4,3,4,4,3,3,2,3,2,3,3,2,4,4,3,4,4,3,2,2,4,4,5,2,3,1,4,4,3,3,3,2,2,4,4,3,3,3,3,3,,7,5,"These questions are very difficult to address during a PANDEMIC! So it is not your average typical year. Our principal may not be as concerned about academics, because they are too busy navigating the complexities COVID has caused. I am honestly unsure why we would get surveyed during this time. "

1 Start Date End Date Response Type IP Address Progress Duration (in seconds) Finished Recorded Date Response ID Recipient Last Name Recipient First Name Recipient Email External Data Reference Location Latitude Location Longitude Distribution Channel User Language district_code school_code t-prep-q1 t-prep-q2 t-prep-q3 t-pcom-q1 t-pcom-q2 t-pcom-q3 t-pcom-q4 t-pcom-q5 t-ieff-q1 t-ieff-q2 t-ieff-q3 t-ieff-q4 t-qupd-q3 t-qupd-q2 t-qupd-q1 t-qupd-q4 t-coll-q1 t-coll-q2 t-coll-q3 t-prtr-q1 t-prtr-q2 t-prtr-q3 t-inle-q1 t-inle-q2 t-inle-q3 t-pvic-q1 t-pvic-q2 t-pvic-q3 t-psup-q1 t-psup-q2 t-psup-q3 t-psup-q4 t-acch-q1 t-acch-q2 t-acch-q3 t-reso-q1 t-reso-q2 t-reso-q3 t-reso-q4 t-reso-q5 t-sust-q1 t-sust-q2 t-sust-q3 t-sust-q4 t-curv-q1 t-curv-q2 t-curv-q3 t-curv-q4 t-cure-q1 t-cure-q2 t-cure-q3 t-cure-q4 t-peng-q1 t-peng-q2 t-peng-q3 t-peng-q4 t-ceng-q1 t-ceng-q2 t-ceng-q3 t-ceng-q4 #N/A t-sach-q2 t-sach-q3 t-psol-q1 t-psol-q2 t-psol-q3 t-expa-q2 t-expa-q3 t-phya-q2 t-phya-q3
2 2020-10-09 9:42:45 2020-10-09 11:08:57 0 50.204.125.194 93 5172 0 2020-10-16 11:09:03 survey_response_1 teacher_survey_response_1 anonymous EN 1 1 4 3 3 3 3 5
3 2020-10-09 9:21:30 2020-10-09 14:28:09 0 50.204.125.194 24 18398 0 2020-10-16 14:28:18 survey_response_2 teacher_survey_response_2 anonymous EN 1 1 4
4 2020-12-06 8:28:00 2020-12-06 8:36:52 0 73.61.140.32 100 532 1 2020-12-06 8:36:52 survey_response_3 teacher_survey_response_3 41.92610168 -71.30110168 anonymous EN 1 2 2 5 5 5 5 5 5 5 1 5 5 5 5 3 2 1 5 4 5 5 4 4 5 5 5 5 3 3 3 3 1 3 3 4 3 2 4 4 4 4 3 3 2 2 2 4 4 4 3 2 3 2 5 4 5 5 3 4 4 3 5 2 1 3 4 3 3 4 4 3 3 9 9
5 2020-12-06 8:41:41 2020-12-06 8:51:25 0 96.230.183.162 100 584 1 2020-12-06 8:51:25 survey_response_4 teacher_survey_response_4 41.98530579 -71.5184021 anonymous EN 1 2 2 5 5 5 4 4 4 4 1 4 4 4 4 3 3 3 2 5 2 4 5 4 5 4 4 4 3 3 3 3 4 4 3 3 3 3 3 4 3 3 4 4 3 2 4 4 4 4 4 3 2 3 4 5 3 2 2 4 4 3 3 4 3 3 3 3 3 3 4 3 3 9 6
6 2020-12-06 8:44:42 2020-12-06 8:55:58 0 216.41.82.178 100 675 1 2020-12-06 8:55:58 survey_response_5 teacher_survey_response_5 41.92610168 -71.30110168 anonymous EN 1 2 2 5 4 4 2 2 4 1 2 4 4 4 4 3 3 3 2 4 3 5 4 3 4 3 3 4 2 2 4 4 2 4 3 4 4 3 3 2 3 2 3 3 2 4 4 3 4 4 3 2 2 4 4 5 2 3 1 4 4 3 3 3 2 2 4 4 3 3 3 3 3 7 5 These questions are very difficult to address during a PANDEMIC! So it is not your average typical year. Our principal may not be as concerned about academics, because they are too busy navigating the complexities COVID has caused. I am honestly unsure why we would get surveyed during this time.

@ -1,66 +1,122 @@
require 'rails_helper' require 'rails_helper'
describe SurveyResponsesDataLoader do describe SurveyResponsesDataLoader do
let(:path_to_csv) { Rails.root.join('spec', 'fixtures', 'test_2020-21_teacher_survey_responses.csv') } let(:path_to_teacher_responses) { Rails.root.join('spec', 'fixtures', 'test_2020-21_teacher_survey_responses.csv') }
let(:path_to_student_responses) { Rails.root.join('spec', 'fixtures', 'test_2020-21_student_survey_responses.csv') }
let(:ay_2020_21) { AcademicYear.find_by_range '2020-21' } let(:ay_2020_21) { AcademicYear.find_by_range '2020-21' }
let(:attleboro_high_school) { School.find_by_slug 'attleboro-high-school' } let(:attleboro_high_school) { School.find_by_slug 'attleboro-high-school' }
let(:butler_middle_school) { School.find_by_slug 'butler-middle-school' }
let(:t_pcom_q3) { SurveyItem.find_by_survey_item_id 't-pcom-q3' } let(:t_pcom_q3) { SurveyItem.find_by_survey_item_id 't-pcom-q3' }
let(:t_pcom_q2) { SurveyItem.find_by_survey_item_id 't-pcom-q2' } let(:t_pcom_q2) { SurveyItem.find_by_survey_item_id 't-pcom-q2' }
let(:s_phys_q1) { SurveyItem.find_by_survey_item_id 's-phys-q1' }
let(:s_phys_q2) { SurveyItem.find_by_survey_item_id 's-phys-q2' }
describe 'self.load_data' do describe 'self.load_data' do
before :each do context 'loading teacher survey responses' do
SurveyResponsesDataLoader.load_data filepath: path_to_csv before :each do
end SurveyResponsesDataLoader.load_data filepath: path_to_teacher_responses
end
it 'loads the csv data into the database' do it 'assigns the academic year to the survey item responses' do
expect(SurveyItemResponse.count).to be > 0 expect(SurveyItemResponse.find_by_response_id('teacher_survey_response_1').academic_year).to eq ay_2020_21
end end
it 'assigns the academic year to the survey item responses' do it 'assigns the school to the survey item responses' do
expect(SurveyItemResponse.first.academic_year).to eq ay_2020_21 expect(SurveyItemResponse.find_by_response_id('teacher_survey_response_1').school).to eq attleboro_high_school
end end
it 'assigns the school to the survey item responses' do it 'loads all the survey item responses for a given survey response' do
expect(SurveyItemResponse.first.school).to eq attleboro_high_school expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_1').count).to eq 5
end expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_2').count).to eq 0
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_3').count).to eq 69
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_4').count).to eq 69
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_5').count).to eq 69
end
it 'loads all the survey item responses for a given survey response' do it 'loads all the survey item responses for a given survey item' do
expect(SurveyItemResponse.where(response_id: 'survey_response_1').count).to eq 5 expect(SurveyItemResponse.where(survey_item: t_pcom_q2).count).to eq 3
expect(SurveyItemResponse.where(response_id: 'survey_response_2').count).to eq 0 expect(SurveyItemResponse.where(survey_item: t_pcom_q3).count).to eq 4
expect(SurveyItemResponse.where(response_id: 'survey_response_3').count).to eq 69 end
end
it 'loads all the survey item responses for a given survey item' do it 'captures the likert scores for the survey item responses' do
expect(SurveyItemResponse.where(survey_item: t_pcom_q2).count).to eq 3 expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_1').where(survey_item: t_pcom_q2)).to be_empty
expect(SurveyItemResponse.where(survey_item: t_pcom_q3).count).to eq 4 expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_1').where(survey_item: t_pcom_q3).first.likert_score).to eq 3
end
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_2').where(survey_item: t_pcom_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_2').where(survey_item: t_pcom_q3)).to be_empty
it 'captures the likert scores for the survey item responses' do expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_3').where(survey_item: t_pcom_q2).first.likert_score).to eq 5
expect(SurveyItemResponse.where(response_id: 'survey_response_1').where(survey_item: t_pcom_q2)).to be_empty expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_3').where(survey_item: t_pcom_q3).first.likert_score).to eq 5
expect(SurveyItemResponse.where(response_id: 'survey_response_1').where(survey_item: t_pcom_q3).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: 'survey_response_2').where(survey_item: t_pcom_q2)).to be_empty expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_4').where(survey_item: t_pcom_q2).first.likert_score).to eq 4
expect(SurveyItemResponse.where(response_id: 'survey_response_2').where(survey_item: t_pcom_q3)).to be_empty expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_4').where(survey_item: t_pcom_q3).first.likert_score).to eq 4
expect(SurveyItemResponse.where(response_id: 'survey_response_3').where(survey_item: t_pcom_q2).first.likert_score).to eq 5 expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_5').where(survey_item: t_pcom_q2).first.likert_score).to eq 2
expect(SurveyItemResponse.where(response_id: 'survey_response_3').where(survey_item: t_pcom_q3).first.likert_score).to eq 5 expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_5').where(survey_item: t_pcom_q3).first.likert_score).to eq 4
end
expect(SurveyItemResponse.where(response_id: 'survey_response_4').where(survey_item: t_pcom_q2).first.likert_score).to eq 4 it 'is idempotent, i.e. loading the data a second time does not duplicate survey item responses' do
expect(SurveyItemResponse.where(response_id: 'survey_response_4').where(survey_item: t_pcom_q3).first.likert_score).to eq 4 number_of_survey_item_responses = SurveyItemResponse.count
expect(SurveyItemResponse.where(response_id: 'survey_response_5').where(survey_item: t_pcom_q2).first.likert_score).to eq 2 SurveyResponsesDataLoader.load_data filepath: path_to_teacher_responses
expect(SurveyItemResponse.where(response_id: 'survey_response_5').where(survey_item: t_pcom_q3).first.likert_score).to eq 4
expect(SurveyItemResponse.count).to eq number_of_survey_item_responses
end
end end
it 'is idempotent, i.e. loading the data a second time does not duplicate survey item responses' do context 'student survey responses' do
number_of_survey_item_responses = SurveyItemResponse.count before :each do
SurveyResponsesDataLoader.load_data filepath: path_to_student_responses
end
it 'assigns the academic year to the survey item responses' do
expect(SurveyItemResponse.find_by_response_id('student_survey_response_3').academic_year).to eq ay_2020_21
end
it 'assigns the school to the survey item responses' do
expect(SurveyItemResponse.find_by_response_id('student_survey_response_3').school).to eq butler_middle_school
end
it 'loads all the survey item responses for a given survey response' do
expect(SurveyItemResponse.where(response_id: 'student_survey_response_1').count).to eq 0
expect(SurveyItemResponse.where(response_id: 'student_survey_response_2').count).to eq 0
expect(SurveyItemResponse.where(response_id: 'student_survey_response_3').count).to eq 25
expect(SurveyItemResponse.where(response_id: 'student_survey_response_4').count).to eq 22
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5').count).to eq 27
end
it 'loads all the survey item responses for a given survey item' do
expect(SurveyItemResponse.where(survey_item: s_phys_q1).count).to eq 3
expect(SurveyItemResponse.where(survey_item: s_phys_q2).count).to eq 3
end
it 'captures the likert scores for the survey item responses' do
expect(SurveyItemResponse.where(response_id: 'student_survey_response_1').where(survey_item: s_phys_q1)).to be_empty
expect(SurveyItemResponse.where(response_id: 'student_survey_response_1').where(survey_item: s_phys_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: 'student_survey_response_2').where(survey_item: s_phys_q1)).to be_empty
expect(SurveyItemResponse.where(response_id: 'student_survey_response_2').where(survey_item: s_phys_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: 'student_survey_response_3').where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_3').where(survey_item: s_phys_q2).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: 'student_survey_response_4').where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_4').where(survey_item: s_phys_q2).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5').where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5').where(survey_item: s_phys_q2).first.likert_score).to eq 2
end
it 'is idempotent, i.e. loading the data a second time does not duplicate survey item responses' do
number_of_survey_item_responses = SurveyItemResponse.count
SurveyResponsesDataLoader.load_data filepath: path_to_csv SurveyResponsesDataLoader.load_data filepath: path_to_student_responses
expect(SurveyItemResponse.count).to eq number_of_survey_item_responses expect(SurveyItemResponse.count).to eq number_of_survey_item_responses
end
end end
end end
end end

Loading…
Cancel
Save