Class: QaServer::MonitorStatus::HistoryPresenter

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

Constant Summary collapse

CAUTION_THRESHOLD =
0.05
WARNING_THRESHOLD =
0.1

Instance Method Summary collapse

Constructor Details

#initialize(parent:, historical_summary_data:) ⇒ HistoryPresenter

"AGROVOC_DIRECT"=>{:good=>4, :bad=>0,
"AGROVOC_LD4L_CACHE"=>:bad=>0

}

Examples:

historical_summary_data

Parameters:

  • parent (QaServer::MonitorStatusPresenter)

    parent presenter

  • historical_summary_data (Array<Hash>)

    summary of past failuring runs per authority to drive chart



15
16
17
18
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 15

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

Instance Method Details

#days_authority_failing(historical_entry) ⇒ Integer

Returns number of days with failing tests (e.g. 51).

Examples:

historical_entry

[ 'AUTH_NAME',  { good: 949, bad: 51 } ]

Parameters:

  • historical_entry (Array<String,Hash>)

    data for a single authority including name, # passing tests (good), # failing tests (bad)

Returns:

  • (Integer)

    number of days with failing tests (e.g. 51)



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

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

#days_authority_passing(historical_entry) ⇒ Integer

Returns number of days with passing tests (e.g. 949).

Examples:

historical_entry

[ 'AUTH_NAME',  { good: 949, bad: 51 } ]

Parameters:

  • historical_entry (Array<String,Hash>)

    data for a single authority including name, # passing tests (good), # failing tests (bad)

Returns:

  • (Integer)

    number of days with passing tests (e.g. 949)



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

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

#days_authority_tested(historical_entry) ⇒ Integer

Returns number of days tested (e.g. 1000).

Examples:

historical_entry

[ 'AUTH_NAME',  { good: 949, bad: 51 } ]

Parameters:

  • historical_entry (Array<String,Hash>)

    data for a single authority including name, # passing tests (good), # failing tests (bad)

Returns:

  • (Integer)

    number of days tested (e.g. 1000)



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

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

#display_historical_datatable?Boolean

Returns true if historical datatable should be visible; otherwise false.

Returns:

  • (Boolean)

    true if historical datatable should be visible; otherwise false



164
165
166
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 164

def display_historical_datatable?
  QaServer.config.display_historical_datatable?
end

#display_historical_graph?Boolean

Returns true if historical graph should be visible; otherwise false.

Returns:

  • (Boolean)

    true if historical graph should be visible; otherwise false



159
160
161
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 159

def display_historical_graph?
  QaServer.config.display_historical_graph? && QaServer::HistoryGraphingService.history_graph_image_exists?
end

#display_history_details?Boolean

Returns true if historical section should be visible; otherwise false.

Returns:

  • (Boolean)

    true if historical section should be visible; otherwise false



154
155
156
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 154

def display_history_details?
  display_historical_graph? || display_historical_datatable?
end

#failure_style_class(historical_entry) ⇒ String

Returns css class for background in Days Failing and Percent Failing columns (e.g. ‘status-neutral’, ‘status-unknown’, ‘status-bad’).

Examples:

historical_entry

[ 'AUTH_NAME',  { good: 949, bad: 51 } ]

Parameters:

  • historical_entry (Array<String,Hash>)

    data for a single authority including name, # passing tests (good), # failing tests (bad)

Returns:

  • (String)

    css class for background in Days Failing and Percent Failing columns (e.g. ‘status-neutral’, ‘status-unknown’, ‘status-bad’)



134
135
136
137
138
139
140
141
142
143
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 134

def failure_style_class(historical_entry)
  case percent_authority_failing(historical_entry)
  when 0.0...CAUTION_THRESHOLD
    "status-neutral"
  when CAUTION_THRESHOLD...WARNING_THRESHOLD
    "status-unknown"
  else
    "status-bad"
  end
end

#historical_data_authority_name(historical_entry) ⇒ String

Returns name of the authority (e.g. ‘AUTH_NAME’).

Examples:

historical_entry

[ 'AUTH_NAME',  { good: 949, bad: 51 } ]

Parameters:

  • historical_entry (Array<String,Hash>)

    data for a single authority including name, # passing tests (good), # failing tests (bad)

Returns:

  • (String)

    name of the authority (e.g. ‘AUTH_NAME’)



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

def historical_data_authority_name(historical_entry)
  historical_entry[0]
end

#historical_graphObject



30
31
32
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 30

def historical_graph
  QaServer::HistoryGraphingService.history_graph_image_path
end

#historical_summaryArray<Hash>

"AGROVOC_DIRECT"=>{:good=>4, :bad=>0,
"AGROVOC_LD4L_CACHE"=>:bad=>0

}

Returns:

  • (Array<Hash>)

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



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

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



35
36
37
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 35

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”)



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

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



55
56
57
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 55

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”)



41
42
43
44
45
46
47
48
49
50
51
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 41

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) ⇒ String

Returns css class for background in Days Passing column (e.g. ‘status-good’, ‘status-bad’).

Examples:

historical_entry

[ 'AUTH_NAME',  { good: 949, bad: 51 } ]

Parameters:

  • historical_entry (Array<String,Hash>)

    data for a single authority including name, # passing tests (good), # failing tests (bad)

Returns:

  • (String)

    css class for background in Days Passing column (e.g. ‘status-good’, ‘status-bad’)



149
150
151
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 149

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

#percent_authority_failing(historical_entry) ⇒ Float

Returns percent of failing to passing tests (e.g. 0.05374 ).

Examples:

historical_entry

[ 'AUTH_NAME',  { good: 949, bad: 51 } ]

Parameters:

  • historical_entry (Array<String,Hash>)

    data for a single authority including name, # passing tests (good), # failing tests (bad)

Returns:

  • (Float)

    percent of failing to passing tests (e.g. 0.05374 )



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

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) ⇒ String

Returns percent of failing to passing tests (e.g. ‘5.4%’).

Examples:

historical_entry

[ 'AUTH_NAME',  { good: 949, bad: 51 } ]

Parameters:

  • historical_entry (Array<String,Hash>)

    data for a single authority including name, # passing tests (good), # failing tests (bad)

Returns:

  • (String)

    percent of failing to passing tests (e.g. ‘5.4%’)



126
127
128
# File 'app/presenters/qa_server/monitor_status/history_presenter.rb', line 126

def percent_authority_failing_str(historical_entry)
  ActiveSupport::NumberHelper.number_to_percentage(percent_authority_failing(historical_entry) * 100, precision: 1)
end

#status_label(status) ⇒ String

Returns the marker to use for the status cell based on the status of the scenario test.

Returns:

  • (String)

    the marker 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