class FlexStationData::ParsePlateReadings
Attributes
plate_data[R]
Public Class Methods
new(plate_data)
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 15 def initialize(plate_data) @plate_data = plate_data end
parse_row(row)
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 61 def parse_row(row) time, temperature, *values = row [ parse_time(time), parse_value(temperature), *values.map(&method(:parse_value)) ] end
parse_time(t)
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 48 def parse_time(t) return if t.blank? h, m, s = t.split(":").map(&:to_i) h * 60.0 + m + s / 60.0 end
parse_value(v)
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 55 def parse_value(v) Float(v) rescue ArgumentError, TypeError v.presence end
Public Instance Methods
call()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 43 def call [ times, temperatures, wells ] end
headers()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 27 def headers @headers ||= plate_data.detect(&method(:header_row?)).reverse.drop_while(&:blank?).reverse end
readings_block()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 19 def readings_block @readings_block ||= plate_data .drop_while { |row| !header_row?(row) } .drop_while { |row| !sample_row?(row) } .take_while { |row| !end_row?(row) } .select { |row| row.any?(&:present?) } end
temperatures()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 35 def temperatures @temperatures ||= matrix.column(1).to_a.compact end
times()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 31 def times @times ||= matrix.column(0).to_a.compact end
wells()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 39 def wells Wells.new(wells_matrix) end
Private Instance Methods
end_row?(row)
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 77 def end_row?(row) row[0].to_s =~ /\A\s*~End\s*\z/i end
header_row?(row)
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 69 def header_row?(row) row[1].to_s =~ /\A\s*Temperature\b/i end
matrix()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 85 def matrix @matrix ||= Matrix[ *readings_block.map { |row| parse_row(row[0...headers.size]) } ] end
sample_row?(row)
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 73 def sample_row?(row) row[0].to_s =~ /\A\s*\d+:\d+:\d+\s*\z/ end
well_values()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 81 def well_values matrix.minor(0..-1, 2..-1) end
wells_matrix()
click to toggle source
# File lib/flex_station_data/services/parse_plate_readings.rb, line 91 def wells_matrix well_row_count = matrix.row_count / times.size Matrix[*well_values.column_vectors.map { |col| col.to_a.each_slice(well_row_count).to_a.transpose }.transpose] end