Class: ConceptAIDisplayer

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/displayer/concept_ai_displayer.rb

Instance Method Summary collapse

Instance Method Details

#call(concepts_ai) ⇒ Object

Display ConceptAI stat on screen

Parameters:

  • concepts_ai (Array)


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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
# File 'lib/asker/displayer/concept_ai_displayer.rb', line 13

def call(concepts_ai)
  stages = Application.instance.config["questions"]["stages"]
  # Create table HEAD
  screen_table = Terminal::Table.new do |st|
    title = %w[Concept Questions Entries xFactor]
    %w[d b f i s t].each do |i|
      if stages.include? i.to_sym
        title << i
        next
      end
      title << Rainbow(i).yellow.bright
    end
    st << title
    st << :separator
  end
  # Create table BODY
  total = {}
  total[:q] = total[:e] = total[:c] = 0
  total[:sd] = total[:sb] = total[:sf] = 0
  total[:si] = total[:ss] = total[:st] = 0

  concepts_ai.each do |concept_ai|
    next unless concept_ai.concept.process?

    e = concept_ai.concept.texts.size
    e += concept_ai.concept.images.size
    concept_ai.concept.tables.each { |t| e += t.fields.size * t.rows.size }

    sd = sb = sf = 0
    si = ss = st = 0
    sd = concept_ai.questions[:d].size if stages.include? :d
    sb = concept_ai.questions[:b].size if stages.include? :b
    sf = concept_ai.questions[:f].size if stages.include? :f
    si = concept_ai.questions[:i].size if stages.include? :i
    ss = concept_ai.questions[:s].size if stages.include? :s
    st = concept_ai.questions[:t].size if stages.include? :t
    t = sd + sb + sf + si + ss + st

    factor = "Unknown"
    factor = (t.to_f / e).round(2).to_s unless e.zero?
    screen_table.add_row [Rainbow(concept_ai.concept.name(:screen)).green.bright,
      t, e, factor, sd, sb, sf, si, ss, st]

    total[:q] += t
    total[:e] += e
    total[:c] += 1
    total[:sd] += sd
    total[:sb] += sb
    total[:sf] += sf
    total[:si] += si
    total[:ss] += ss
    total[:st] += st
  end
  return if total[:c].zero? # No concepts to be process?

  # Add row with excluded questions
  export_excluded_questions(screen_table, concepts_ai)

  # Create table TAIL
  screen_table.add_separator
  screen_table.add_row [Rainbow("#{total[:c]} concept/s").bright,
    Rainbow(total[:q].to_s).bright,
    Rainbow(total[:e].to_s).bright,
    Rainbow((total[:q].to_f / total[:e]).round(2)).bright,
    total[:sd], total[:sb], total[:sf],
    total[:si], total[:ss], total[:st]]
  export_notes
  Logger.info "#{screen_table}\n"
end