Class: QaServer::MonitorStatus::HistoryPresenter

Inherits:
Object
  • Object
show all
Includes:
GruffGraph
Defined in:
app/presenters/qa_server/monitor_status/history_presenter.rb

Constant Summary collapse

HISTORICAL_AUTHORITY_NAME_IDX =
0
HISTORICAL_FAILURE_COUNT_IDX =
1
HISTORICAL_PASSING_COUNT_IDX =
2

Instance Method Summary collapse

Constructor Details

#initialize(historical_summary_data:) ⇒ HistoryPresenter

Returns a new instance of HistoryPresenter.

Parameters:

  • historical_summary_data (Array<Hash>) —

    summary of past failuring runs per authority to drive chart



12
13
14
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 12

def initialize(historical_summary_data:)
  @historical_summary_data = historical_summary_data
end

Instance Method Details

#days_authority_failing(historical_entry) ⇒ Object



68
69
70
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 68

def days_authority_failing(historical_entry)
  historical_entry[HISTORICAL_FAILURE_COUNT_IDX]
end

#days_authority_passing(historical_entry) ⇒ Object



64
65
66
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 64

def days_authority_passing(historical_entry)
  historical_entry[HISTORICAL_PASSING_COUNT_IDX]
end

#days_authority_tested(historical_entry) ⇒ Object



72
73
74
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 72

def days_authority_tested(historical_entry)
  days_authority_passing(historical_entry) + days_authority_failing(historical_entry)
end

#display_historical_datatable? ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 103

def display_historical_datatable?
  QaServer.config.display_historical_datatable?
end

#display_historical_graph? ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 99

def display_historical_graph?
  QaServer.config.display_historical_graph?
end

#display_history_details? ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 95

def display_history_details?
  display_historical_graph? || display_historical_datatable?
end

#failure_style_class(historical_entry) ⇒ Object



84
85
86
87
88
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 84

def failure_style_class(historical_entry)
  return "status-neutral" if days_authority_failing(historical_entry) <= 0
  return "status-unknown" if percent_authority_failing(historical_entry) < 0.1
  "status-bad"
end

#historical_data_authority_name(historical_entry) ⇒ Object



60
61
62
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 60

def historical_data_authority_name(historical_entry)
  historical_entry[HISTORICAL_AUTHORITY_NAME_IDX]
end

#historical_graph ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 30

def historical_graph
  # g = Gruff::SideStackedBar.new('800x400')
  g = Gruff::SideStackedBar.new
  historical_graph_theme(g)
  g.title = ''
  historical_data = rework_historical_data_for_gruff
  g.labels = historical_data[0]
  g.data('Fail', historical_data[1])
  g.data('Pass', historical_data[2])
  g.write historical_graph_full_path
  File.join(graph_relative_path, historical_graph_filename)
end

#historical_summary ⇒ Array<Hash>

Returns historical test data to be displayed (authname, failing, passing).

Examples:

[ [ 'agrovoc', 0, 24 ],
  [ 'geonames_ld4l_cache', 2, 22 ] ... ]

Returns:

  • (Array<Hash>) —

    historical test data to be displayed (authname, failing, passing)



20
21
22
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 20

def historical_summary
  @historical_summary_data
end

#history? ⇒ Boolean

Returns true if historical test data exists; otherwise false.

Returns:

  • (Boolean) —

    true if historical test data exists; otherwise false



25
26
27
28
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 25

def history?
  return true if @historical_summary_data.present?
  false
end

#passing_style_class(historical_entry) ⇒ Object



90
91
92
93
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 90

def passing_style_class(historical_entry)
  return "status-bad" if days_authority_passing(historical_entry) <= 0
  "status-good"
end

#percent_authority_failing(historical_entry) ⇒ Object



76
77
78
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 76

def percent_authority_failing(historical_entry)
  days_authority_failing(historical_entry).to_f / days_authority_tested(historical_entry)
end

#percent_authority_failing_str(historical_entry) ⇒ Object



80
81
82
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 80

def percent_authority_failing_str(historical_entry)
  "#{percent_authority_failing(historical_entry) * 100}%"
end

#status_label(status) ⇒ String

Returns the name of the css style class to use for the status cell based on the status of the scenario test.

Returns:

  • (String) —

    the name of the css style class to use for the status cell based on the status of the scenario test.



49
50
51
52
53
54
55
56
57
58
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 49

def status_label(status)
  case status[:status]
  when :good
    QaServer::ScenarioRunHistory::GOOD_MARKER
  when :bad
    QaServer::ScenarioRunHistory::BAD_MARKER
  when :unknown
    QaServer::ScenarioRunHistory::UNKNOWN_MARKER
  end
end

#status_style_class(status) ⇒ String

Returns the name of the css style class to use for the status cell based on the status of the scenario test.

Returns:

  • (String) —

    the name of the css style class to use for the status cell based on the status of the scenario test.



44
45
46
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 44

def status_style_class(status)
  "status-#{status[:status]}"
end