Class: QaServer::PerformanceCalculatorService

Inherits:
Object
  • Object
show all
Includes:
PerformanceHistoryDataKeys
Defined in:
app/services/qa_server/performance_calculator_service.rb

Constant Summary

Constants included from PerformanceHistoryDataKeys

QaServer::PerformanceHistoryDataKeys::ALL_ACTIONS, QaServer::PerformanceHistoryDataKeys::ALL_AUTH, QaServer::PerformanceHistoryDataKeys::AVG_ACTN, QaServer::PerformanceHistoryDataKeys::AVG_FULL, QaServer::PerformanceHistoryDataKeys::AVG_GRPH, QaServer::PerformanceHistoryDataKeys::AVG_LOAD, QaServer::PerformanceHistoryDataKeys::AVG_NORM, QaServer::PerformanceHistoryDataKeys::AVG_RETR, QaServer::PerformanceHistoryDataKeys::BY_DAY, QaServer::PerformanceHistoryDataKeys::BY_HOUR, QaServer::PerformanceHistoryDataKeys::BY_MONTH, QaServer::PerformanceHistoryDataKeys::FETCH, QaServer::PerformanceHistoryDataKeys::FOR_DATATABLE, QaServer::PerformanceHistoryDataKeys::FOR_DAY, QaServer::PerformanceHistoryDataKeys::FOR_MONTH, QaServer::PerformanceHistoryDataKeys::FOR_YEAR, QaServer::PerformanceHistoryDataKeys::HIGH_ACTN, QaServer::PerformanceHistoryDataKeys::HIGH_FULL, QaServer::PerformanceHistoryDataKeys::HIGH_GRPH, QaServer::PerformanceHistoryDataKeys::HIGH_LOAD, QaServer::PerformanceHistoryDataKeys::HIGH_NORM, QaServer::PerformanceHistoryDataKeys::HIGH_RETR, QaServer::PerformanceHistoryDataKeys::LOW_ACTN, QaServer::PerformanceHistoryDataKeys::LOW_FULL, QaServer::PerformanceHistoryDataKeys::LOW_GRPH, QaServer::PerformanceHistoryDataKeys::LOW_LOAD, QaServer::PerformanceHistoryDataKeys::LOW_NORM, QaServer::PerformanceHistoryDataKeys::LOW_RETR, QaServer::PerformanceHistoryDataKeys::SEARCH, QaServer::PerformanceHistoryDataKeys::STATS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records, action: nil) ⇒ PerformanceCalculatorService

Returns a new instance of PerformanceCalculatorService.

Parameters:

  • records (Array <Qa::PerformanceHistory>)

    set of records used to calculate the statistics



11
12
13
14
15
# File 'app/services/qa_server/performance_calculator_service.rb', line 11

def initialize(records, action: nil)
  @records = records
  @action = [:search, :fetch].include?(action) ? action : nil
  @stats = {}
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



8
9
10
# File 'app/services/qa_server/performance_calculator_service.rb', line 8

def action
  @action
end

#recordsObject (readonly)

Returns the value of attribute records.



8
9
10
# File 'app/services/qa_server/performance_calculator_service.rb', line 8

def records
  @records
end

#statsObject (readonly)

Returns the value of attribute stats.



8
9
10
# File 'app/services/qa_server/performance_calculator_service.rb', line 8

def stats
  @stats
end

Instance Method Details

#calculate_stats(avg: false, low: false, high: false, load: true, norm: true, full: true) ⇒ Hash

Calculate performance statistics for a set of PerformanceHistory records. Min is at the 10th percentile. Max is at the 90th percentile.

Examples:

{ retrieve_avg_ms: 12.3, graph_load_avg_ms: 2.1, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5,
  retrieve_10th_ms: 12.3, graph_load_10th_ms: 12.3, normalization_10th_ms: 4.2, full_request_10th_ms: 16.5,
  retrieve_90th_ms: 12.3, graph_load_90th_ms: 12.3, normalization_90th_ms: 4.2, full_request_90th_ms: 16.5 }

Returns:

  • (Hash)

    hash of the statistics



23
24
25
26
27
28
29
30
# File 'app/services/qa_server/performance_calculator_service.rb', line 23

def calculate_stats(avg: false, low: false, high: false, load: true, norm: true, full: true) # rubocop:disable Metrics/ParameterLists
  calculate_load_stats(avg, low, high) if load
  calculate_retrieve_stats(avg, low, high) if load
  calculate_graph_load_stats(avg, low, high) if load
  calculate_normalization_stats(avg, low, high) if norm
  calculate_action_stats(avg, low, high) if full
  stats
end