Class: QaServer::ScenarioRunHistory

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.historical_summaryObject

Get a summary level of historical data

Examples:

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


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/models/qa_server/scenario_run_history.rb', line 130

def self.historical_summary
  runs = all_runs_per_authority
  failures = failing_runs_per_authority
  return [] unless runs.present?
  data = []
  runs.each do |auth_name, run_count|
    auth_data = []
    auth_data[0] = auth_name
    failure_count = (failures.key? auth_name) ? failures[auth_name] : 0 # rubocop:disable Style/TernaryParentheses
    auth_data[1] = failure_count
    auth_data[2] = run_count - failure_count # passing
    data << auth_data
  end
  data
end

.run_failures(run_id:) ⇒ 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



120
121
122
123
# File 'app/models/qa_server/scenario_run_history.rb', line 120

def self.run_failures(run_id:)
  return [] unless run_id
  QaServer::ScenarioRunHistory.where(scenario_run_registry_id: run_id).where.not(status: :good).to_a
end

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

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



88
89
90
91
92
93
94
95
96
# File 'app/models/qa_server/scenario_run_history.rb', line 88

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:) ⇒ Object

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

Examples:

{ run_id: 14,
  failing_count: 3,
  passing_count: 156,
  total_count: 159,
  authority_count: 22,
  failing_authority_count: 1 }

Parameters:



43
44
45
46
47
48
49
50
51
52
# File 'app/models/qa_server/scenario_run_history.rb', line 43

def self.run_summary(scenario_run:)
  return nil unless scenario_run&.id
  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

.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