@@ -34,7 +34,16 @@ def exec(filename:, book_uuid:)
34
34
record_failures do |failures |
35
35
ProcessSpreadsheet . call ( filename : filename , headers : :downcase ) do |headers , row , row_index |
36
36
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
38
47
39
48
pre_or_post_index ||= headers . index { |header | header &.start_with? ( 'pre' ) && header . end_with? ( 'post' ) }
40
49
raise ArgumentError , 'Could not find "Pre or Post" column' if pre_or_post_index . nil?
@@ -45,10 +54,14 @@ def exec(filename:, book_uuid:)
45
54
raise ArgumentError , 'Could not find "Question Stem" column' if question_stem_index . nil?
46
55
47
56
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 ')
49
58
end
50
59
raise ArgumentError , 'Could not find "Answer Choice" columns' if answer_choice_indices . empty?
51
60
61
+ feedback_indices ||= headers . filter_map . with_index do |header , index |
62
+ index if header &.include? ( 'feedback' )
63
+ end
64
+
52
65
correct_answer_index ||= headers . index { |header | header &.start_with? ( 'correct' ) }
53
66
raise ArgumentError , 'Could not find "Correct Answer" column' if correct_answer_index . nil?
54
67
@@ -57,9 +70,14 @@ def exec(filename:, book_uuid:)
57
70
58
71
row_number = row_index + 1
59
72
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
+
61
79
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" }
63
81
next
64
82
end
65
83
@@ -85,9 +103,14 @@ def exec(filename:, book_uuid:)
85
103
answer_choice_indices . each_with_index do |row_index , answer_index |
86
104
content = row [ row_index ]
87
105
next if content . blank?
106
+
107
+ feedback_index = feedback_indices [ answer_index ]
108
+ feedback = row [ feedback_index ] unless feedback_index . nil?
109
+
88
110
stem . stem_answers << StemAnswer . new (
89
111
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 )
91
114
)
92
115
end
93
116
0 commit comments