Module: Request::Statistics

Included in:
Request
Defined in:
app/models/request/statistics.rb

Defined Under Namespace

Classes: Counter, Summary

Instance Method Summary collapse

Instance Method Details

#asset_statistics(wheres) ⇒ Object


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

def asset_statistics(wheres)
  counters = select('asset_id,request_type_id,state, count(*) as total').group('asset_id, request_type_id, state').includes(:request_type).where(wheres)
  tabulated = Hash.new { |h, k| h[k] = Summary.new }
  tabulated.tap do
    counters.each do |asset_request_type_state_count|
      tabulated[asset_request_type_state_count.asset_id.to_i][asset_request_type_state_count.request_type_id.to_i][asset_request_type_state_count.state] = asset_request_type_state_count.total.to_i
    end
  end
end

#progress_statisticsObject

Returns a hash that maps from the RequestType to the information about the number of requests in various states. This is effectively summary data that can be displayed in a tabular format for the user.


78
79
80
81
82
83
84
85
86
# File 'app/models/request/statistics.rb', line 78

def progress_statistics
  counters  = select('request_type_id, state, count(distinct requests.id) as total').group('request_type_id, state').includes(:request_type)
  tabulated = Hash.new { |h, k| h[k] = Counter.new }
  tabulated.tap do
    counters.each do |request_type_state_count|
      tabulated[request_type_state_count.request_type][request_type_state_count.state] = request_type_state_count.total.to_i
    end
  end
end

#sample_statistics_newObject


98
99
100
101
102
103
104
105
106
# File 'app/models/request/statistics.rb', line 98

def sample_statistics_new
  counters = join_asset.select('sample_id,request_type_id,state,count(*) as total').group('sample_id, request_type_id, state').includes(:request_type)
  tabulated = Hash.new { |h, k| h[k] = Summary.new }
  tabulated.tap do
    counters.each do |sample_request_type_state_count|
      tabulated[sample_request_type_state_count.sample_id.to_i][sample_request_type_state_count.request_type_id.to_i][sample_request_type_state_count.state] = sample_request_type_state_count.total.to_i
    end
  end
end