Class: PipelineWorkInProgressController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PipelineWorkInProgressController
- Defined in:
- app/controllers/pipeline_work_in_progress_controller.rb
Overview
Controller for swimlane style view of work in progress for a pipeline
Instance Method Summary collapse
-
#arrange_labware_records(ordered_purposes, from_date) ⇒ Object
Split out requests for the last purpose and the rest of the purposes so that the labware for the last purpose can be filtered by those that have ancestors including at least one purpose from the rest.
- #decide_state(labware) ⇒ Object
-
#filter_labware_records_by_ancestor_purpose_names(labware_records, purpose_names_list) ⇒ Object
Filter a list of labware records such that we only keep those that have at least one ancestor with a purpose from the given allow list.
- #from_date(params) ⇒ Object
-
#mould_data_for_view(purposes, labware_records) ⇒ Object
Returns following structure (example):.
-
#retrieve_labware(page_size, from_date, purposes) ⇒ Object
Retrieves labware through the Sequencescape V2 API Combines pages into one list Returns a list of Sequencescape::Api::V2::Labware.
-
#show ⇒ Object
Retrieves data from Sequencescape and populates variables to be used in the UI.
Instance Method Details
#arrange_labware_records(ordered_purposes, from_date) ⇒ Object
Split out requests for the last purpose and the rest of the purposes so that the labware for the last purpose can be filtered by those that have ancestors including at least one purpose from the rest.
26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/pipeline_work_in_progress_controller.rb', line 26 def arrange_labware_records(ordered_purposes, from_date) page_size = 500 specific_purposes = ordered_purposes.first(ordered_purposes.count - 1) specific_labware_records = retrieve_labware(page_size, from_date, specific_purposes) general_labware_records = retrieve_labware(page_size, from_date, ordered_purposes.last) specific_labware_records + filter_labware_records_by_ancestor_purpose_names(general_labware_records, specific_purposes) end |
#decide_state(labware) ⇒ Object
92 93 94 |
# File 'app/controllers/pipeline_work_in_progress_controller.rb', line 92 def decide_state(labware) labware.state_changes&.max_by(&:id)&.target_state || 'pending' end |
#filter_labware_records_by_ancestor_purpose_names(labware_records, purpose_names_list) ⇒ Object
Filter a list of labware records such that we only keep those that have at least one ancestor with a purpose from the given allow list.
39 40 41 42 43 44 |
# File 'app/controllers/pipeline_work_in_progress_controller.rb', line 39 def filter_labware_records_by_ancestor_purpose_names(labware_records, purpose_names_list) labware_records.select do |labware| ancestor_purpose_names = labware.ancestors.map { |ancestor| ancestor.purpose.name } ancestor_purpose_names.any? { |purpose_name| purpose_names_list.include?(purpose_name) } end end |
#from_date(params) ⇒ Object
19 20 21 |
# File 'app/controllers/pipeline_work_in_progress_controller.rb', line 19 def from_date(params) params[:date]&.to_date || Time.zone.today.prev_month end |
#mould_data_for_view(purposes, labware_records) ⇒ Object
Returns following structure (example):
{
"LTHR Cherrypick" => [
{
:record => #<Sequencescape::Api::V2::Labware...>,
:state => "pending"
}
],
"LTHR-384 PCR 1" => [{}]
}
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/pipeline_work_in_progress_controller.rb', line 76 def mould_data_for_view(purposes, labware_records) {}.tap do |output| # Make sure there's an entry for each of the purposes, even if no records purposes.each { |p| output[p] = [] } labware_records.each do |rec| next unless rec.purpose state = decide_state(rec) next if state == 'cancelled' output[rec.purpose.name] << { record: rec, state: state } end end end |
#retrieve_labware(page_size, from_date, purposes) ⇒ Object
Retrieves labware through the Sequencescape V2 API Combines pages into one list Returns a list of Sequencescape::Api::V2::Labware
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/pipeline_work_in_progress_controller.rb', line 49 def retrieve_labware(page_size, from_date, purposes) labware_query = Sequencescape::Api::V2::Labware .select( { plates: %w[uuid purpose labware_barcode state_changes updated_at ancestors] }, { tubes: %w[uuid purpose labware_barcode state_changes updated_at ancestors] }, { purposes: 'name' } ) .includes(:state_changes, :purpose, 'ancestors.purpose') .where(without_children: true, purpose_name: purposes, updated_at_gt: from_date) .order(:updated_at) .per(page_size) Sequencescape::Api::V2.merge_page_results(labware_query) end |
#show ⇒ Object
Retrieves data from Sequencescape and populates variables to be used in the UI
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/pipeline_work_in_progress_controller.rb', line 6 def show @pipeline_group_name = params[:id] # Group related pipelines together pipelines_for_group = Settings.pipelines.retrieve_pipeline_config_for_group(@pipeline_group_name) @ordered_purpose_list = Settings.pipelines.combine_and_order_pipelines(pipelines_for_group) labware_records = arrange_labware_records(@ordered_purpose_list, from_date(params)) @grouped = mould_data_for_view(@ordered_purpose_list, labware_records) end |