Class: ONCCertificationG10TestKit::Tasks::GenerateMatrix

Inherits:
Object
  • Object
show all
Includes:
ONCCertificationG10TestKit
Defined in:
lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb

Constant Summary collapse

FILE_NAME =
'onc_certification_g10_matrix.xlsx'.freeze

Constants included from ONCCertificationG10TestKit

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rowObject

Returns the value of attribute row.



12
13
14
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 12

def row
  @row
end

Instance Method Details

#add_group(group) ⇒ Object



258
259
260
261
262
263
264
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 258

def add_group(group)
  add_group_title(group)

  group.tests.each { |test| add_test(test) }

  group.groups.each { |nested_group| add_group(nested_group) }
end

#add_group_title(group, column: 1) ⇒ Object



252
253
254
255
256
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 252

def add_group_title(group, column: 1)
  inferno_worksheet.add_cell(row, column, "#{group.short_id}: #{group.title}")
  inferno_worksheet.add_cell(row, 6, applicable_options(group).map(&:value).uniq.join(', '))
  next_row
end

#add_test(test) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 238

def add_test(test)
  this_row = columns.map do |column|
    column[2].call(test)
  end

  this_row.each_with_index do |value, index|
    inferno_worksheet.add_cell(row, index, value).change_text_wrap(true)
  end
  inferno_worksheet
    .change_row_height(row, [26, ((test.description || '').strip.lines.count * 10) + 10].max)
  inferno_worksheet.change_row_vertical_alignment(row, 'top')
  next_row
end

#all_descendant_tests(runnable) ⇒ Object



53
54
55
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 53

def all_descendant_tests(runnable)
  runnable.tests + runnable.groups.flat_map { |group| all_descendant_tests(group) }
end

#applicable_options(runnable) ⇒ Object

returns an array of options that apply to this test or group



204
205
206
207
208
209
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 204

def applicable_options(runnable)
  runnable_and_parents = [runnable].tap do |parents|
    parents << parents.last.parent while parents.last.parent.present?
  end
  runnable_and_parents.map(&:suite_option_requirements).compact.flatten
end

#columnsObject

rubocop:disable Metrics/CyclomaticComplexity



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 215

def columns # rubocop:disable Metrics/CyclomaticComplexity
  @columns ||= [
    ['', 3, ->(_test) { '' }],
    ['', 3, ->(_test) { '' }],
    ['Inferno Test ID', 22, ->(test) { test.short_id.to_s }],
    ['Inferno Test Name', 65, ->(test) { test.title }],
    ['Inferno Test Description', 65, lambda do |test|
                                       description = test.description || ''
                                       natural_indent =
                                         description
                                           .lines
                                           .collect { |l| l.index(/[^ ]/) }
                                           .select { |l| !l.nil? && l.positive? }
                                           .min || 0
                                       description.lines.map { |l| l[natural_indent..] || "\n" }.join.strip
                                     end],
    ['Test Procedure Steps', 30, ->(test) { inferno_to_procedure_map[test.short_id].join(', ') }],
    ['Standard Version Filter', 30, lambda do |test|
                                      applicable_options(test).map(&:value).uniq.join(', ')
                                    end]
  ]
end

#generate_inferno_test_worksheetObject



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 266

def generate_inferno_test_worksheet
  workbook.add_worksheet('Inferno Tests')

  columns.each_with_index do |row_name, index|
    inferno_worksheet.add_cell(0, index, row_name.first)
  end

  self.row = 1

  test_suite.groups.each do |group|
    next if group.short_id == '6' # Skip US Core 5

    next_row
    add_group(group)
  end

  columns.each_with_index do |column, index|
    inferno_worksheet.change_column_width(index, column[1])
  end
end

#generate_matrix_worksheetObject

rubocop:disable Metrics/CyclomaticComplexity



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 57

def generate_matrix_worksheet # rubocop:disable Metrics/CyclomaticComplexity
  matrix_worksheet = workbook.worksheets[0]
  matrix_worksheet.sheet_name = 'Matrix'

  col = 2
  matrix_worksheet.add_cell(0, 1, "ONC Certification (g)(10) Test Kit (v#{ONCCertificationG10TestKit::VERSION})")
  matrix_worksheet.change_row_height(0, 20)
  matrix_worksheet.change_row_vertical_alignment(0, 'distributed')
  column_map = {}
  matrix_worksheet.change_column_width(1, 25)
  matrix_worksheet.change_row_height(1, 20)
  matrix_worksheet.change_row_horizontal_alignment(1, 'center')
  matrix_worksheet.change_row_vertical_alignment(1, 'distributed')
  matrix_worksheet.change_row_height(2, 70)
  column_borders = []

  test_suite.groups.each do |group|
    next if group.short_id == '6' # Skip US Core 5

    matrix_worksheet.add_cell(1, col, group.title).change_text_wrap(true)
    matrix_worksheet.merge_cells(1, col, 1, col + group.groups.length - 1) if group.groups.length.positive?
    matrix_worksheet.change_column_border(col, :left, 'medium')
    matrix_worksheet.change_column_border_color(col, :left, '000000')
    column_borders << col

    group.tests.each do |test|
      column_map[test.short_id] = col
    end

    group.groups.each do |test_case|
      matrix_worksheet.change_column_width(col, 4.2)

      cell = matrix_worksheet.add_cell(2, col,
                                       "#{test_case.short_id} #{test_case.short_title || test_case.title}")
      cell.change_text_rotation(90)
      cell.change_border_color(:bottom, '000000')
      cell.change_border(:bottom, 'medium')
      matrix_worksheet.change_column_border(col, :right, 'thin')
      matrix_worksheet.change_column_border_color(col, :right, '666666')

      all_descendant_tests(test_case).each { |test| column_map[test.short_id] = col }
      col += 1
    end
  end

  total_width = col - 1
  matrix_worksheet.merge_cells(0, 1, 0, total_width)
  matrix_worksheet.change_row_horizontal_alignment(0, 'center')

  matrix_worksheet.add_cell(2, total_width + 2, 'Supported?')
  self.row = 3

  test_procedure.sections.each do |section|
    section.steps.each do |step|
      step_id = step.id.upcase
      matrix_worksheet.add_cell(row, 1, "#{step_id} ")
      matrix_worksheet.change_row_height(row, 13)
      matrix_worksheet.change_row_vertical_alignment(row, 'distributed')

      (2..total_width).each do |column|
        matrix_worksheet.add_cell(row, column, '')
      end

      step.inferno_tests.each do |test_id|
        column = column_map[test_id]
        inferno_to_procedure_map[test_id].push(step_id)
        if column.nil?
          puts "No such test found: #{test_id}"
          next
        end

        matrix_worksheet.add_cell(row, column, '').change_fill('3C63FF')
      end

      matrix_worksheet.add_cell(row, total_width + 2, step.inferno_supported.upcase)

      next_row
    end
  end
  matrix_worksheet.change_column_horizontal_alignment(1, 'right')
  matrix_worksheet.change_row_horizontal_alignment(0, 'center')

  column_borders.each do |column|
    matrix_worksheet.change_column_border(column, :left, 'medium')
    matrix_worksheet.change_column_border_color(column, :left, '000000')
  end
  matrix_worksheet.change_column_border_color(total_width, :right, '000000')
  matrix_worksheet.change_column_border(total_width, :right, 'medium')
  matrix_worksheet.change_column_width(total_width + 1, 3)

  matrix_worksheet.change_column_width(total_width + 3, 6)
  matrix_worksheet.change_column_width(total_width + 4, 2)
  matrix_worksheet.change_column_width(total_width + 5, 60)
  matrix_worksheet.add_cell(1, total_width + 3, '').change_fill('3C63FF')
  this_text = 'Blue boxes indicate that the Inferno test (top) covers this test procedure step (left).'
  matrix_worksheet.add_cell(1, total_width + 5, this_text).change_text_wrap(true)
  matrix_worksheet.change_column_horizontal_alignment(total_width + 5, :left)
end

#generate_test_procedure_worksheetObject

rubocop:disable Metrics/CyclomaticComplexity



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 156

def generate_test_procedure_worksheet # rubocop:disable Metrics/CyclomaticComplexity
  workbook.add_worksheet('Test Procedure')
  tp_worksheet = workbook.worksheets[1]

  [3, 3, 22, 65, 65, 3, 15, 30, 65, 65].each_with_index do |width, index|
    tp_worksheet.change_column_width(index, width)
  end
  ['',
   '',
   'ID',
   'System Under Test',
   'Test Lab Verifies',
   '',
   'Inferno Supports?',
   'Inferno Tests',
   'Inferno Notes',
   'Alternate Test Methodology'].each_with_index { |text, index| tp_worksheet.add_cell(0, index, text) }

  self.row = 2

  test_procedure.sections.each do |section|
    tp_worksheet.add_cell(row, 0, section.name)
    next_row
    section.steps.group_by(&:group).each do |group_name, steps|
      tp_worksheet.add_cell(row, 1, group_name)
      next_row
      steps.each do |step|
        longest_line = [step.s_u_t, step.t_l_v, step.inferno_notes, step.alternate_test].map do |text|
          text&.lines&.count || 0
        end.max
        tp_worksheet.change_row_height(row, (longest_line * 10) + 10)
        tp_worksheet.change_row_vertical_alignment(row, 'top')
        tp_worksheet.add_cell(row, 2, "#{step.id.upcase} ")
        tp_worksheet.add_cell(row, 3, step.s_u_t).change_text_wrap(true)
        tp_worksheet.add_cell(row, 4, step.t_l_v).change_text_wrap(true)
        tp_worksheet.add_cell(row, 5, '')
        tp_worksheet.add_cell(row, 6, step.inferno_supported)
        tp_worksheet.add_cell(row, 7, step.inferno_tests.join(', ')).change_text_wrap(true)
        tp_worksheet.add_cell(row, 8, step.inferno_notes).change_text_wrap(true)
        tp_worksheet.add_cell(row, 9, step.alternate_test).change_text_wrap(true)
        next_row
      end
    end
    next_row
  end
end

#inferno_to_procedure_mapObject



16
17
18
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 16

def inferno_to_procedure_map
  @inferno_to_procedure_map ||= Hash.new { |h, k| h[k] = [] }
end

#inferno_worksheetObject



211
212
213
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 211

def inferno_worksheet
  workbook.worksheets[2]
end

#next_rowObject



40
41
42
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 40

def next_row
  self.row += 1
end

#runObject



44
45
46
47
48
49
50
51
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 44

def run
  generate_matrix_worksheet
  generate_test_procedure_worksheet
  generate_inferno_test_worksheet

  Inferno.logger.info "Writing to #{FILE_NAME}"
  workbook.write(FILE_NAME)
end

#test_procedureObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 20

def test_procedure
  @test_procedure ||=
    if File.file? File.join('lib', 'onc_certification_g10_test_kit', 'onc_program_procedure.yml')
      TestProcedure.new(
        YAML.load_file(File.join('lib', 'onc_certification_g10_test_kit',
                                 'onc_program_procedure.yml')).deep_symbolize_keys
      )
    else
      TestProcedure.new
    end
end

#test_suiteObject



32
33
34
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 32

def test_suite
  ONCCertificationG10TestKit::G10CertificationSuite
end

#workbookObject



36
37
38
# File 'lib/onc_certification_g10_test_kit/tasks/generate_matrix.rb', line 36

def workbook
  @workbook ||= RubyXL::Workbook.new
end