Class: QaServer::MonitorStatus::HistoryPresenter

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

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Constructor Details

#initialize(parent:, historical_summary_data:) ⇒ HistoryPresenter

Returns a new instance of HistoryPresenter.

Parameters:

  • parent (QaServer::MonitorStatusPresenter)

    parent presenter

  • historical_summary_data (Array<Hash>)

    summary of past failuring runs per authority to drive chart



9
10
11
12
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 9

def initialize(parent:, historical_summary_data:)
  @parent = parent
  @historical_summary_data = historical_summary_data
end

Instance Method Details

#days_authority_failing(historical_entry) ⇒ Object



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

def days_authority_failing(historical_entry)
  historical_entry[1]["bad"]
end

#days_authority_passing(historical_entry) ⇒ Object



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

def days_authority_passing(historical_entry)
  historical_entry[1]["good"]
end

#days_authority_tested(historical_entry) ⇒ Object



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

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

#display_historical_datatable?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 123

def display_historical_datatable?
  QaServer.config.display_historical_datatable?
end

#display_historical_graph?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 119

def display_historical_graph?
  QaServer.config.display_historical_graph?
end

#display_history_details?Boolean

Returns:

  • (Boolean)


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

def display_history_details?
  display_historical_graph? || display_historical_datatable?
end

#failure_style_class(historical_entry) ⇒ Object



106
107
108
109
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 106

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

#historical_data_authority_name(historical_entry) ⇒ Object



82
83
84
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 82

def historical_data_authority_name(historical_entry)
  historical_entry[0]
end

#historical_graphObject



53
54
55
56
57
58
59
60
61
62
63
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 53

def historical_graph
  # g = Gruff::SideStackedBar.new('800x400')
  g = Gruff::SideStackedBar.new
  historical_graph_theme(g)
  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_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)



18
19
20
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 18

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



23
24
25
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 23

def history?
  @historical_summary_data.present?
end

#history_endString

Return the last date of data represented in the history graph and data table

Returns:

  • (String)

    string version of date formatted with just date (e.g. "02/01/2020")



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

def history_end
  QaServer::TimeService.pretty_date(history_end_dt)
end

#history_end_dtActiveSupport::TimeWithZone

Return the last date of data represented in the history graph and data table

Returns:

  • (ActiveSupport::TimeWithZone)

    date time stamp



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

def history_end_dt
  @parent.last_updated_dt
end

#history_startString

Return the first date of data represented in the history graph and data table

Returns:

  • (String)

    string version of date formatted with just date (e.g. "02/01/2020")



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

def history_start
  start_dt = case QaServer.config.historical_datatable_default_time_period
             when :month
               history_end_dt - 1.month
             when :year
               history_end_dt - 1.year
             else
               @parent.first_updated_dt
             end
  QaServer::TimeService.pretty_date(start_dt)
end

#passing_style_class(historical_entry) ⇒ Object



111
112
113
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 111

def passing_style_class(historical_entry)
  days_authority_passing(historical_entry) <= 0 ? "status-bad" : "status-good"
end

#percent_authority_failing(historical_entry) ⇒ Object



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

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



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

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.



71
72
73
74
75
76
77
78
79
80
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 71

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.



66
67
68
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 66

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