Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'csv'
- require 'ruport'
- #require 'ruport/util'
- files = Array.new
- folders = Array.new
- def numeric?(object)
- true if Float(object) rescue false
- end
- def readcsvdata(file)
- data = Hash.new()
- CSV.foreach(file, :quote_char => '"', :col_sep =>',', :row_sep =>:auto) do |row|
- if not numeric?(row[0])
- next
- end
- data[row[0].to_f] = row[1].to_f
- end
- return data
- end
- #sampleId = RegEx.new(/AD\d\d\d\d/)
- #runNumber = RegEx.new(/\d[\d]/)
- ARGV.each do|a|
- folders.push a
- end
- failWarningNeeded = false
- folders.sort.each do |folder|
- sampleId = folder.match(/AD\d\d\d\d/).to_s.match(/\d\d\d\d/)
- puts "Sample AD#{sampleId}"
- dataTable = Ruport::Data::Table.new( :column_names => ["Sample", "Peel Extension (mm)", "Force Per Sample Width (N)", "Pass?"] ).sort_rows_by{["Sample"]}
- if File.directory?(folder)
- #puts "#{folder} is a Directory!"
- Dir.foreach(folder) do |file|
- next if file == '.' or file == '..' or file.match(/Specimen_RawData_\d+\.csv/) == nil
- #Parse File Name
- #runNumber = "%02d" % file.match(/\d+\.csv/).to_s.match(/\d+/).to_s.to_i
- runNumber = file.match(/\d+\.csv/).to_s.match(/\d+/).to_s.to_i
- data = readcsvdata(folder+"\\"+file) #returns a hash of {distance => force}
- firstDistPoint = data.keys.first #get starting distance
- minForce = data.select{ |k,v| k > (data.keys.first + 5)}.values.min #new hash of data after first 5 mm
- if minForce < 10
- pass = "-"
- failWarningNeeded = true
- else
- pass = "+"
- end
- dataTable << [runNumber, data.key(minForce)+firstDistPoint, minForce, pass ]
- #puts "Weakest Point for #{runNumber}\n Peel Extension #{minHash[0]}\n Force Per Area: #{minHash[1]}" #find lowest value of
- #Note: This does not check for a negative spike that the standard ignores.
- end
- else
- puts "Error: #{folder} is not a Directory!"
- end
- puts dataTable.sort_rows_by { |r| r.Sample }.to_html
- puts "\n\n"
- end
- puts "Possible Filure!\nOne or more of the samples failed, however this program does not check for a negative spike less than 1 mm in width that the standard ignores nor does it make sure that the sample is taught. You should double check any failure results." if failWarningNeeded == true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement