Module: PlatePurpose::Stock

Included in:
IlluminaC::StockPurpose, Input
Defined in:
app/models/plate_purpose/stock.rb

Constant Summary collapse

UNREADY_STATE =
'pending'
READY_STATE =
'passed'

Instance Method Summary collapse

Instance Method Details

#state_of(plate) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/plate_purpose/stock.rb', line 7

def state_of(plate)
  # If there are no wells with aliquots we're pending
  ids_of_wells_with_aliquots = plate.wells.with_aliquots.ids
  return UNREADY_STATE if ids_of_wells_with_aliquots.empty?

  # All of the wells with aliquots must have customer requests for us to consider the plate passed
  well_requests = CustomerRequest.where(asset_id: ids_of_wells_with_aliquots)

  wells_states = well_requests.group_by(&:asset_id).values.map do |requests|
    calculate_state_of_well(requests.map(&:state))
  end

  return UNREADY_STATE unless wells_states.count == ids_of_wells_with_aliquots.count

  calculate_state_of_plate(wells_states)
end