Class: QaServer::ScenarioRunHistory

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/qa_server/scenario_run_history.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

GOOD_MARKER =
''
BAD_MARKER =
'X'
UNKNOWN_MARKER =
'?'

Class Method Summary collapse

Class Method Details

.historical_summary(force: false) ⇒ Object

Get a summary level of historical data

Examples:

auth_name, failing, passing
[ [ 'agrovoc', 0, 24 ],
  [ 'geonames_ld4l_cache', 2, 22 ] ... ]


140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/models/qa_server/scenario_run_history.rb', line 140

def self.historical_summary(force: false)
  Rails.cache.fetch("#{self.class}/#{__method__}", expires_in: QaServer.cache_expiry, race_condition_ttl: 1.hour, force: force) do
    Rails.logger.info("#{self.class}##{__method__} - calculating pass/fail per authority across all time - cache expired or refresh requested (#{force})")
    runs = all_runs_per_authority
    failures = failing_runs_per_authority
    return [] unless runs.present?
    data = []
    runs.each do |auth_name, run_count|
      data << pass_fail_stats_for_authority(failures, auth_name, run_count)
    end
    data
  end
end

.run_failures(run_id:, force: false) ⇒ Object

Get set of failures for a run, if any.

Examples:

[ { status: :bad,
    authority_name: "geonames_ld4l_cache",
    subauthority_name: "area",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/geonames_ld4l_cache/area?q=France&maxRecords=4",
    err_message: "Unable to connect to authority",
    scenario_type: :connection
    run_time: 11.2 },
  { status: :unknown,
    authority_name: "oclcfast_ld4l_cache",
    subauthority_name: "Person",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/oclcfast_ld4l_cache/person?q=mark twain&maxRecords=4",
    err_message: "Not enough search results returned",
    scenario_type: :connection
    run_time: 0.123 } ]

Parameters:

  • run_id (Integer)

    the run on which to gather statistics

  • force (Boolean) (defaults to: false)

    if true, forces cache to regenerate; otherwise, returns value from cache unless expired



127
128
129
130
131
132
133
# File 'app/models/qa_server/scenario_run_history.rb', line 127

def self.run_failures(run_id:, force: false)
  return [] unless run_id
  Rails.cache.fetch("#{self.class}/#{__method__}", expires_in: QaServer.cache_expiry, race_condition_ttl: 1.hour, force: force) do
    Rails.logger.info("#{self.class}##{__method__} - finding failures in latest run - cache expired or refresh requested (#{force})")
    QaServer::ScenarioRunHistory.where(scenario_run_registry_id: run_id).where.not(status: :good).to_a
  end
end

.run_results(run_id:, authority_name: nil, status: nil, url: nil) ⇒ Object

Deprecated.

Not used anywhere. Being removed.

Get set of all scenario results for a run.

Examples:

[ { status: :bad,
    authority_name: "geonames_ld4l_cache",
    subauthority_name: "area",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/geonames_ld4l_cache/area?q=France&maxRecords=4",
    err_message: "Unable to connect to authority",
    scenario_type: :connection
    run_time: 11.2 },
  { status: :good,
    authority_name: "oclcfast_ld4l_cache",
    subauthority_name: "Organization",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/oclcfast_ld4l_cache/organization?q=mark twain&maxRecords=4",
    err_message: "",
    scenario_type: :connection
    run_time: 0.131 },
  { status: :unknown,
    authority_name: "oclcfast_ld4l_cache",
    subauthority_name: "Person",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/oclcfast_ld4l_cache/person?q=mark twain&maxRecords=4",
    err_message: "Not enough search results returned",
    scenario_type: :connection
    run_time: 0.123 } ]

Parameters:

  • run_id (Integer)

    the run on which to gather statistics

  • authority_name (String) (defaults to: nil)

    limit results to those for the authority with this name

  • status (Array<Symbol> | Symbol) (defaults to: nil)

    :good, :bad, :unknown, or any of these in an array to select multiple status

  • url (String) (defaults to: nil)

    limit results to a specific scenario URL



93
94
95
96
97
98
99
100
101
# File 'app/models/qa_server/scenario_run_history.rb', line 93

def self.run_results(run_id:, authority_name: nil, status: nil, url: nil)
  return [] unless run_id
  where = {}
  where[:scenario_run_registry_id] = run_id
  where[:authority_name] = authority_name if authority_name.present?
  where[:status] = status if status.present?
  where[:url] = url if url.present?
  QaServer::ScenarioRunHistory.where(where).to_a
end

.run_summary(scenario_run:, force: false) ⇒ Object

Get a summary of passing/failing tests for a run.

Examples:

ScenarioRunSummary includes methods for accessing

* run_id: 14,
* run_dt_stamp:
* authority_count: 22,
* failing_authority_count: 1
* passing_scenario_count: 156,
* failing_scenario_count: 3,
* total_scenario_count: 159,

Parameters:

  • scenario_run (QaServer::ScenarioRunRegistry)

    the run on which to gather statistics

  • force (Boolean) (defaults to: false)

    if true, forces cache to regenerate; otherwise, returns value from cache unless expired



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/qa_server/scenario_run_history.rb', line 45

def self.run_summary(scenario_run:, force: false)
  Rails.cache.fetch("#{self.class}/#{__method__}", expires_in: QaServer.cache_expiry, race_condition_ttl: 1.hour, force: force) do
    Rails.logger.info("#{self.class}##{__method__} - creating summary of latest run - cache expired or refresh requested (#{force})")
    status = status_counts_in_run(run_id: scenario_run.id)
    summary_class.new(run_id: scenario_run.id,
                      run_dt_stamp: scenario_run.dt_stamp,
                      authority_count: authorities_in_run(run_id: scenario_run.id).count,
                      failing_authority_count: authorities_with_failures_in_run(run_id: scenario_run.id).count,
                      passing_scenario_count: status['good'],
                      failing_scenario_count: status['bad'] + status['unknown'])
  end
end

.save_result(run_id:, scenario_result:) ⇒ Object

Save a scenario result

Parameters:

  • run_id (Integer)

    the run on which to gather statistics

  • result (Hash)

    the scenario result to be saved



21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/qa_server/scenario_run_history.rb', line 21

def self.save_result(run_id:, scenario_result:)
  QaServer::ScenarioRunHistory.create(scenario_run_registry_id: run_id,
                                      status: scenario_result[:status],
                                      authority_name: scenario_result[:authority_name],
                                      subauthority_name: scenario_result[:subauthority_name],
                                      service: scenario_result[:service],
                                      action: scenario_result[:action],
                                      url: scenario_result[:url],
                                      err_message: scenario_result[:err_message],
                                      run_time: scenario_result[:run_time])
end