class Report

Close Show methods for Report class.

This class maintain the results of every case, in a structured way.

Show methods for Report class.

Attributes

filename[RW]

@!attribute id

@return [Integer] It is the [Case] number. Zero indicates Resume Report.
format[R]

@!attribute format

@return [Symbol] Indicate export format.
head[RW]

@!attribute head

@return [Hash] Report head information.
history[R]
id[RW]

@!attribute id

@return [Integer] It is the [Case] number. Zero indicates Resume Report.
lines[RW]

@!attribute lines

@return [Array] Report body information.
output_dir[RW]

@!attribute id

@return [Integer] It is the [Case] number. Zero indicates Resume Report.
tail[RW]

@!attribute tail

@return [Hash] Report tail information.

Public Class Methods

new(id = '00') click to toggle source

Class constructor

# File lib/teuton/report/report.rb, line 32
def initialize(id = '00')
  @id = id
  @filename = "case-#{@id}"
  @output_dir = Application.instance.output_basedir
  @head = {}
  @lines = []
  @tail = {}
  # @history save 1 letter for every target.
  # For example: "..F." means: good, good, fail and good
  # I will use this in the future stats manager.
  @history = ''
end

Public Instance Methods

close() click to toggle source

Calculate final values:

  • grade

  • max_weight

  • good_weight,d

  • fail_weight

  • fail_counter

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

# File lib/teuton/report/close.rb, line 14
def close
  app = Application.instance
  max = 0.0
  good = 0.0
  fail = 0.0
  fail_counter = 0
  @lines.each do |i|
    next unless i.class.to_s == 'Hash'

    max += i[:weight] if i[:weight].positive?
    if i[:check]
      good += i[:weight]
      @history += app.letter[:good]
    else
      fail += i[:weight]
      fail_counter += 1
      @history += app.letter[:bad]
    end
  end
  @tail[:max_weight] = max
  @tail[:good_weight] = good
  @tail[:fail_weight] = fail
  @tail[:fail_counter] = fail_counter

  i = good.to_f / max
  i = 0 if i.nan?
  @tail[:grade] = (100.0 * i).round
  @tail[:grade] = 0 if @tail[:unique_fault].positive?
end
export(format = :txt) click to toggle source

Export [Case] data to specified format. @param format [Symbol] Select export format. Default value is :txt.

# File lib/teuton/report/report.rb, line 48
def export(format = :txt)
  @format = format
  filepath = File.join(@output_dir, @filename + '.' \
           + FormatterFactory.ext(@format))

  formatter = FormatterFactory.get(self, @format, filepath)
  formatter.process
end
export_resume(format = :txt) click to toggle source

Export resumed data from all Cases, to specified format. @param format [Symbol] Select export format. Default value is :txt.

# File lib/teuton/report/report.rb, line 60
def export_resume(format = :txt)
  @format = "resume_#{format}".to_sym
  filepath = File.join(@output_dir, @filename + '.' \
           + FormatterFactory.ext(@format))
  formatter = FormatterFactory.get(self, @format, filepath)
  formatter.process

  filepath = File.join(@output_dir, 'moodle.csv')
  formatter = FormatterFactory.get(self, :moodle_csv, filepath)
  formatter.process
end
show() click to toggle source

Display [Report] information on screen

# File lib/teuton/report/show.rb, line 7
def show
  show_initial_configurations
  if @filename.to_s.include? 'resume'
    show_resume
  else
    show_targets_history
  end
  show_final_values
  show_hall_of_fame
end

Private Instance Methods

show_case_list() click to toggle source

Display case list

# File lib/teuton/report/show.rb, line 41
def show_case_list
  puts Rainbow('CASE RESULTS').bright
  my_screen_table = Terminal::Table.new do |st|
    st.add_row %w[CASE MEMBERS GRADE STATE]
    @lines.each do |line|
      st.add_row [line[:id], line[:members], line[:grade], line[:letter]]
    end
  end
  puts "#{my_screen_table}\n\n"
end
show_conn_status() click to toggle source

Display Connection status rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize

# File lib/teuton/report/show.rb, line 56
def show_conn_status
  errors = 0
  @lines.each { |line| errors += line[:conn_status].size }
  return if errors.zero?

  puts Rainbow('CONN ERRORS').bright
  my_screen_table = Terminal::Table.new do |st|
    st.add_row %w[CASE MEMBERS HOST ERROR]
    @lines.each do |line|
      line[:conn_status].each_pair do |host, error|
        st.add_row [line[:id], line[:members], host,
                    Rainbow(error).red.bright]
      end
    end
  end
  puts "#{my_screen_table}\n\n"
end
show_final_values() click to toggle source

Display final values section on screen

# File lib/teuton/report/show.rb, line 108
def show_final_values
  puts Rainbow('FINAL VALUES').bright
  my_screen_table = Terminal::Table.new do |st|
    @tail.each do |key, value|
      st.add_row [key.to_s, value.to_s]
    end
  end
  puts "#{my_screen_table}\n\n"
end
show_hall_of_fame() click to toggle source

Display hall of fame section on screen

# File lib/teuton/report/show.rb, line 120
def show_hall_of_fame
  app = Application.instance
  return if app.hall_of_fame.size < 3

  puts Rainbow('HALL OF FAME').bright
  my_screen_table = Terminal::Table.new do |st|
    app.hall_of_fame.each do |line|
      st.add_row [line[0], line[1]]
    end
  end
  puts "#{my_screen_table}\n"
end
show_initial_configurations() click to toggle source

Display initial configurations

# File lib/teuton/report/show.rb, line 22
def show_initial_configurations
  puts Rainbow('INITIAL CONFIGURATIONS').bright
  my_screen_table = Terminal::Table.new do |st|
    @head.each do |key, value|
      st.add_row [key.to_s, trim(value)]
    end
  end
  puts "#{my_screen_table}\n\n"
end
show_resume() click to toggle source

Display resume

# File lib/teuton/report/show.rb, line 34
def show_resume
  show_case_list
  show_conn_status
end
show_targets_history() click to toggle source

rubocop:disable Style/FormatString rubocop:disable Style/FormatStringToken rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

# File lib/teuton/report/show.rb, line 80
def show_targets_history
  tab = '  '
  puts Rainbow('CASE RESULTS').bright
  if @lines.size == 1
    puts @lines[0]
  else
    @lines.each do |i|
      if i.class.to_s == 'Hash'
        value = 0.0
        value = i[:weight] if i[:check]
        print tab + '%03d' % i[:id].to_i
        print ' (%2.1f' % value.to_f
        print '/%2.1f' % i[:weight].to_f
        puts ') %s' % i[:description].to_s
      else
        puts "#{tab}=>  #{i}"
      end
    end
  end
  puts "\n\n"
end
trim(input) click to toggle source

Trim absolute path values

# File lib/teuton/report/show.rb, line 135
def trim(input)
  return input unless input.to_s.start_with? Dir.pwd.to_s
  return input if input == Dir.pwd.to_s

  offset = Dir.pwd.length + 1
  input[offset, input.size].to_s
end