@@ -34,7 +34,16 @@ def exec(filename:, book_uuid:)
3434 record_failures do |failures |
3535 ProcessSpreadsheet . call ( filename : filename , headers : :downcase ) do |headers , row , row_index |
3636 uuid_index ||= headers . index { |header | header == 'uuid' || header == 'page uuid' }
37- raise ArgumentError , 'Could not find page "UUID" column' if uuid_index . nil?
37+
38+ section_index ||= headers . index { |header | header == 'section' }
39+ raise ArgumentError , 'Could not find "UUID" or "Section" columns' if uuid_index . nil? && section_index . nil?
40+
41+ unless section_index . nil?
42+ book = OpenStax ::Content ::Abl . new . approved_books . find { |book | book . uuid == book_uuid }
43+ page_uuid_by_book_location = { }
44+ book . all_pages . each { |page | page_uuid_by_book_location [ page . book_location ] = page . uuid }
45+ raise ArgumentError , "Could not find book with UUID #{ book_uuid } in the ABL" if book . nil?
46+ end
3847
3948 pre_or_post_index ||= headers . index { |header | header &.start_with? ( 'pre' ) && header . end_with? ( 'post' ) }
4049 raise ArgumentError , 'Could not find "Pre or Post" column' if pre_or_post_index . nil?
@@ -45,10 +54,14 @@ def exec(filename:, book_uuid:)
4554 raise ArgumentError , 'Could not find "Question Stem" column' if question_stem_index . nil?
4655
4756 answer_choice_indices ||= headers . filter_map . with_index do |header , index |
48- index if header &.start_with? ( 'answer' ) || header &.end_with? ( 'choice' )
57+ index if ( header &.start_with? ( 'answer' ) || header &.end_with? ( 'choice' ) ) && ! header . include? ( 'feedback ')
4958 end
5059 raise ArgumentError , 'Could not find "Answer Choice" columns' if answer_choice_indices . empty?
5160
61+ feedback_indices ||= headers . filter_map . with_index do |header , index |
62+ index if header &.include? ( 'feedback' )
63+ end
64+
5265 correct_answer_index ||= headers . index { |header | header &.start_with? ( 'correct' ) }
5366 raise ArgumentError , 'Could not find "Correct Answer" column' if correct_answer_index . nil?
5467
@@ -57,9 +70,14 @@ def exec(filename:, book_uuid:)
5770
5871 row_number = row_index + 1
5972
60- page_uuid = row [ uuid_index ]
73+ page_uuid = if uuid_index . nil? || row [ uuid_index ] . blank?
74+ page_uuid_by_book_location [ row [ section_index ] . split ( '.' ) . map ( &:to_i ) ] unless row [ section_index ] . blank?
75+ else
76+ row [ uuid_index ]
77+ end
78+
6179 if page_uuid . blank?
62- Rails . logger . info { "Skipped row ##{ row_number } with blank page UUID" }
80+ Rails . logger . info { "Skipped row ##{ row_number } with blank Section or Page UUID" }
6381 next
6482 end
6583
@@ -85,9 +103,14 @@ def exec(filename:, book_uuid:)
85103 answer_choice_indices . each_with_index do |row_index , answer_index |
86104 content = row [ row_index ]
87105 next if content . blank?
106+
107+ feedback_index = feedback_indices [ answer_index ]
108+ feedback = row [ feedback_index ] unless feedback_index . nil?
109+
88110 stem . stem_answers << StemAnswer . new (
89111 answer : Answer . new ( question : question , content : parse ( content , exercise ) ) ,
90- correctness : answer_index == correct_answer ? 1 : 0
112+ correctness : answer_index == correct_answer ? 1 : 0 ,
113+ feedback : parse ( feedback , exercise )
91114 )
92115 end
93116
0 commit comments