#!/usr/bin/env ruby #!/usr/bin/env ruby require "flex_station_data/services/load_plates" require "flex_station_data/linear_regression" module FlexStationData class LinearRegressionApp include Concerns::Service attr_reader :args def initialize(*args) @args = args end def files @files ||= args.map { |arg| Pathname(arg) } end def plates @plates ||= files.map do |file| [ file, LoadPlates.call(file) ] end end def call plates.each do |file, file_plates| puts "File: #{file.to_path}" file_plates.each_with_index.map do |plate, plate_index| puts "Plate: #{plate_index + 1}" plate.samples.each do |sample| readings_labels = sample.readings.map(&:label) puts "Sample #{sample.label}" CSV do |out| readings = [*sample.readings, sample.mean] out << ["time", *readings.map(&:label)] plate.times.zip(*readings.map(&:values)).each do |row| out << row end regression_factory = LinearRegression.method(:new).curry(2)[plate.times] regressions = readings.map(&:values).map(®ression_factory) out << ["slope", *regressions.map(&:slope)] out << ["R²", *regressions.map(&:r_squared)] out << [] end end end end end end end FlexStationData::LinearRegressionApp.call(*ARGV)