Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check EDFs for unusual Physical Dimensions
# gem install edfize --no-document
# ruby check_edf_header.rb
require 'rubygems'
require 'edfize'
signals_to_check = [
{ label: 'SAO2', physical_dimension: '%' },
{ label: 'Pulse', physical_dimension: ['bpm', 'bmp'] }
]
def strings_match?(a, b)
a.casecmp(b).zero?
end
def missing_physical_dimension?(signal, label, physical_dimensions)
matching_physical_dimensions = \
[physical_dimensions].flatten.select do |pd|
strings_match?(signal.physical_dimension, pd)
end
strings_match?(signal.label, label) && matching_physical_dimensions.empty?
end
good_count = 0
bad_count = 0
edf_files_count = Edfize.edf_paths.count
Edfize.edfs.each_with_index do |edf, index|
print "\rChecking EDF #{index + 1} of #{edf_files_count}"
bad_found = false
edf.signals.each do |signal|
signals_to_check.each do |hash|
if missing_physical_dimension?(signal, hash[:label], hash[:physical_dimension])
puts "\n\n" if bad_found == false
bad_found = true
puts "BAD".colorize(:red) + " #{signal.label} #{signal.physical_dimension}"
end
end
end
if bad_found
puts " #{edf.filename}\n\n"
bad_count += 1
else
good_count += 1
end
end
puts "\n\n" + good_count.to_s.colorize(good_count > 0 ? :green : nil) + " EDF#{good_count == 1 ? ' ' : 's'} passed"
puts bad_count.to_s.colorize(bad_count > 0 ? :red : nil) + " EDF#{bad_count == 1 ? ' ' : 's'} failed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.