Class: StockStamper

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/stock_stamper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = { overage: 1.2 }) ⇒ StockStamper

Returns a new instance of StockStamper.



26
27
28
# File 'app/models/stock_stamper.rb', line 26

def initialize(attributes = { overage: 1.2 })
  super
end

Instance Attribute Details

#destination_plate_barcodeObject

Returns the value of attribute destination_plate_barcode.



5
6
7
# File 'app/models/stock_stamper.rb', line 5

def destination_plate_barcode
  @destination_plate_barcode
end

#destination_plate_type_nameObject

Returns the value of attribute destination_plate_type_name.



11
12
13
# File 'app/models/stock_stamper.rb', line 11

def destination_plate_type_name
  @destination_plate_type_name
end

#file_contentObject

Returns the value of attribute file_content.



5
6
7
# File 'app/models/stock_stamper.rb', line 5

def file_content
  @file_content
end

#overageObject

Returns the value of attribute overage.



5
6
7
# File 'app/models/stock_stamper.rb', line 5

def overage
  @overage
end

#plateObject (readonly)

Returns the value of attribute plate.



11
12
13
# File 'app/models/stock_stamper.rb', line 11

def plate
  @plate
end

#plate_typeObject (readonly)

Returns the value of attribute plate_type.



11
12
13
# File 'app/models/stock_stamper.rb', line 11

def plate_type
  @plate_type
end

#source_plate_barcodeObject

Returns the value of attribute source_plate_barcode.



5
6
7
# File 'app/models/stock_stamper.rb', line 5

def source_plate_barcode
  @source_plate_barcode
end

#source_plate_type_nameObject

Returns the value of attribute source_plate_type_name.



5
6
7
# File 'app/models/stock_stamper.rb', line 5

def source_plate_type_name
  @source_plate_type_name
end

#userObject (readonly)

Returns the value of attribute user.



11
12
13
# File 'app/models/stock_stamper.rb', line 11

def user
  @user
end

#user_barcodeObject

Returns the value of attribute user_barcode.



5
6
7
# File 'app/models/stock_stamper.rb', line 5

def user_barcode
  @user_barcode
end

Instance Method Details

#create_asset_audit_eventObject



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

def create_asset_audit_event
  AssetAudit.create(
    asset_id: plate.id,
    key: 'stamping_of_stock',
    message: "Process 'Stamping of stock' performed",
    created_by: user.
  )
end

#executeObject



30
31
32
33
34
35
36
37
38
# File 'app/models/stock_stamper.rb', line 30

def execute
  generate_tecan_gwl_file_as_text
  create_asset_audit_event
  if wells_with_excess.present?
    message[:error] = "Required volume exceeds the maximum well volume for well(s) #{wells_with_excess.join(', ')}." \
      " Maximum well volume #{plate_type.maximum_volume.to_f} will be used in tecan file"
  end
  message[:notice] = 'You can generate the TECAN file and print label now.'
end

#generate_tecan_dataObject

rubocop:todo Metrics/AbcSize



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/stock_stamper.rb', line 46

def generate_tecan_data # rubocop:todo Metrics/AbcSize
  source_barcode = "#{plate.machine_barcode}_s"
  destination_barcode = "#{plate.machine_barcode}_d"
  data_object = {
    'user' => user.,
    'time' => Time.zone.now,
    'source' => {
      source_barcode => {
        'name' => source_plate_type_name.tr('_', "\s"),
        'plate_size' => plate.size
      }
    },
    'destination' => {
      destination_barcode => {
        'name' => destination_plate_type_name.tr('_', "\s"),
        'plate_size' => plate.size,
        'mapping' => []
      }
    }
  }
  plate.wells.without_blank_samples.each do |well|
    next unless well.get_current_volume

    data_object['destination'][destination_barcode]['mapping'] << {
      'src_well' => [source_barcode, well.map.description],
      'dst_well' => well.map.description,
      'volume' => volume(well),
      'buffer_volume' => well.get_buffer_volume
    }
  end
  data_object
end

#generate_tecan_gwl_file_as_textObject



40
41
42
43
44
# File 'app/models/stock_stamper.rb', line 40

def generate_tecan_gwl_file_as_text
  picking_data = generate_tecan_data
  layout = Robot::Verification::SourceDestBeds.new.layout_data_object(picking_data)
  @file_content = Robot::Generator::Tecan.new(picking_data: picking_data, layout: layout, total_volume: 0).as_text
end

#messageObject



88
89
90
# File 'app/models/stock_stamper.rb', line 88

def message
  @message ||= {}
end

#wells_with_excessObject



92
93
94
# File 'app/models/stock_stamper.rb', line 92

def wells_with_excess
  @wells_with_excess ||= []
end