Class: Report

Inherits:
Object
  • Object
show all
Defined in:
lib/teuton/report/show.rb,
lib/teuton/report/close.rb,
lib/teuton/report/report.rb

Overview

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

  • report/show.rb

  • report/close.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = "00") ⇒ Report

Class constructor



32
33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



16
17
18
# File 'lib/teuton/report/report.rb', line 16

def filename
  @filename
end

#formatObject

Returns the value of attribute format.



28
29
30
# File 'lib/teuton/report/report.rb', line 28

def format
  @format
end

#headHash

Returns Report head information.

Returns:

  • (Hash)

    Report head information.



19
20
21
# File 'lib/teuton/report/report.rb', line 19

def head
  @head
end

#historyObject (readonly)

Returns the value of attribute history.



29
30
31
# File 'lib/teuton/report/report.rb', line 29

def history
  @history
end

#idInteger

Returns It is the [Case] number. Zero indicates Resume Report.

Returns:

  • (Integer)

    It is the [Case] number. Zero indicates Resume Report.



16
17
18
# File 'lib/teuton/report/report.rb', line 16

def id
  @id
end

#linesArray

Returns Report body information.

Returns:

  • (Array)

    Report body information.



22
23
24
# File 'lib/teuton/report/report.rb', line 22

def lines
  @lines
end

#output_dirObject

Returns the value of attribute output_dir.



16
17
18
# File 'lib/teuton/report/report.rb', line 16

def output_dir
  @output_dir
end

#tailHash

Returns Report tail information.

Returns:

  • (Hash)

    Report tail information.



25
26
27
# File 'lib/teuton/report/report.rb', line 25

def tail
  @tail
end

Instance Method Details

#closeObject

Calculate final values:

  • grade

  • max_weight

  • good_weight,d

  • fail_weight

  • fail_counter



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/teuton/report/close.rb', line 9

def close
  app = Application.instance
  max = 0.0
  good = 0.0
  fail = 0.0
  fail_counter = 0
  @lines.each do |i|
    next unless i.instance_of? 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) ⇒ Object

Export [Case] data to specified format.

Parameters:

  • format (Symbol) (defaults to: :txt)

    Select export format. Default value is :txt.



48
49
50
51
52
53
54
55
# 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) ⇒ Object

Export resumed data from all Cases, to specified format.

Parameters:

  • format (Symbol) (defaults to: :txt)

    Select export format. Default value is :txt.



60
61
62
63
64
65
66
67
68
69
70
# 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

#showObject

Display [Report] information on screen



7
8
9
10
11
12
13
14
15
16
# 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