Class: QaServer::MonitorStatusPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/qa_server/monitor_status_presenter.rb

Overview

rubocop:disable Metrics/ClassLength

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(current_summary:, current_failure_data:, historical_summary_data:, performance_data:) ⇒ MonitorStatusPresenter

Returns a new instance of MonitorStatusPresenter.

Parameters:

  • current_summary (ScenarioRunSummary)

    summary status of the latest run of test scenarios

  • current_data (Array<Hash>)

    current set of failures for the latest test run, if any

  • historical_summary_data (Array<Hash>)

    summary of past failuring runs per authority to drive chart



16
17
18
19
20
21
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 16

def initialize(current_summary:, current_failure_data:, historical_summary_data:, performance_data:)
  @current_summary = current_summary
  @current_failure_data = current_failure_data
  @historical_summary_data = historical_summary_data
  @performance_data = performance_data
end

Instance Method Details

#authorities_countInteger

Returns number of loaded authorities.

Returns:

  • (Integer)

    number of loaded authorities



34
35
36
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 34

def authorities_count
  @current_summary.authority_count
end

#authorities_count_styleString

Returns css style class representing whether all tests passed or any failed.

Returns:

  • (String)

    css style class representing whether all tests passed or any failed



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

def authorities_count_style
  failures? ? 'status-bad' : 'status-good'
end

#days_authority_failing(historical_entry) ⇒ Object



139
140
141
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 139

def days_authority_failing(historical_entry)
  historical_entry[QaServer::MonitorStatusPresenter::HISTORICAL_FAILURE_COUNT_IDX]
end

#days_authority_passing(historical_entry) ⇒ Object



135
136
137
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 135

def days_authority_passing(historical_entry)
  historical_entry[QaServer::MonitorStatusPresenter::HISTORICAL_PASSING_COUNT_IDX]
end

#days_authority_tested(historical_entry) ⇒ Object



143
144
145
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 143

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

#display_historical_datatable?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 174

def display_historical_datatable?
  QaServer.config.display_historical_datatable?
end

#display_historical_graph?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 170

def display_historical_graph?
  QaServer.config.display_historical_graph?
end

#display_history_details?Boolean

Returns:

  • (Boolean)


166
167
168
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 166

def display_history_details?
  display_historical_graph? || display_historical_datatable?
end

#failing_authorities_countInteger

Returns number of authorities with failing tests in the latest test run.

Returns:

  • (Integer)

    number of authorities with failing tests in the latest test run



39
40
41
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 39

def failing_authorities_count
  @current_failure_data.map { |f| f[:authority_name] }.uniq.count
end

#failing_tests_countInteger

Returns number of failing tests in the latest test run.

Returns:

  • (Integer)

    number of failing tests in the latest test run



59
60
61
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 59

def failing_tests_count
  @current_summary.failing_scenario_count
end

#failing_tests_styleString

Returns css style class representing whether all tests passed or any failed.

Returns:

  • (String)

    css style class representing whether all tests passed or any failed



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

def failing_tests_style
  failures? ? 'status-bad' : 'status-good'
end

#failure_style_class(historical_entry) ⇒ Object



155
156
157
158
159
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 155

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

#failuresArray<Hash>

Returns A list of failures data in the latest test run, if any.

Examples:

[ { status: :FAIL,
    status_label: 'X',
    authority_name: 'LOCNAMES_LD4L_CACHE',
    subauthority_name: 'person',
    service: 'ld4l_cache',
    action: 'search',
    url: '/qa/search/linked_data/locnames_ld4l_cache/person?q=mark twain&maxRecords=4',
    err_message: 'Exception: Something went wrong.' }, ... ]

Returns:

  • (Array<Hash>)

    A list of failures data in the latest test run, if any



78
79
80
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 78

def failures
  @current_failure_data
end

#failures?Boolean

Returns true if failure data exists for the latest test run; otherwise false.

Returns:

  • (Boolean)

    true if failure data exists for the latest test run; otherwise false



83
84
85
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 83

def failures?
  failing_tests_count.positive?
end

#first_updatedString

Returns date of first recorded test run.

Returns:

  • (String)

    date of first recorded test run



29
30
31
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 29

def first_updated
  QaServer::ScenarioRunRegistry.first.dt_stamp.in_time_zone("Eastern Time (US & Canada)").strftime("%m/%d/%y - %I:%M %p")
end

#historical_data_authority_name(historical_entry) ⇒ Object



131
132
133
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 131

def historical_data_authority_name(historical_entry)
  historical_entry[QaServer::MonitorStatusPresenter::HISTORICAL_AUTHORITY_NAME_IDX]
end

#historical_graphObject



101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 101

def historical_graph
  # g = Gruff::SideStackedBar.new('800x400')
  g = Gruff::SideStackedBar.new
  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(historical_graph_relative_path, historical_graph_filename)
end

#historical_summaryArray<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)



91
92
93
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 91

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



96
97
98
99
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 96

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

#last_updatedString

Returns date of last test run.

Returns:

  • (String)

    date of last test run



24
25
26
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 24

def last_updated
  @current_summary.run_dt_stamp.in_time_zone("Eastern Time (US & Canada)").strftime("%m/%d/%y - %I:%M %p")
end

#passing_style_class(historical_entry) ⇒ Object



161
162
163
164
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 161

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

#passing_tests_countInteger

Returns number of passing tests in the latest test run.

Returns:

  • (Integer)

    number of passing tests in the latest test run



54
55
56
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 54

def passing_tests_count
  @current_summary.passing_scenario_count
end

#percent_authority_failing(historical_entry) ⇒ Object



147
148
149
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 147

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



151
152
153
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 151

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.



120
121
122
123
124
125
126
127
128
129
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 120

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.



115
116
117
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 115

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

#tests_countInteger

Returns number of tests in the latest test run.

Returns:

  • (Integer)

    number of tests in the latest test run



49
50
51
# File 'app/presenters/qa_server/monitor_status_presenter.rb', line 49

def tests_count
  @current_summary.total_scenario_count
end