Skip to content

Instantly share code, notes, and snippets.

@remomueller
Last active December 9, 2016 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remomueller/99d94cc374cd9506e1aea987cf42d0eb to your computer and use it in GitHub Desktop.
Save remomueller/99d94cc374cd9506e1aea987cf42d0eb to your computer and use it in GitHub Desktop.
Check EDFs for signal labels that include a dash
# gem install edfize --no-document
# ruby check_signal_contains_dash.rb
require 'rubygems'
require 'edfize'
VALID_LABELS = [
'C-Pres'
]
def strings_match?(a, b)
a.casecmp(b).zero?
end
def dash_in_signal_label?(signal)
return false if VALID_LABELS.count { |label| strings_match?(label, signal.label) } > 0
!(/-/ =~ signal.label).nil?
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|
if dash_in_signal_label?(signal)
puts "\n\n" if bad_found == false
bad_found = true
puts "BAD".colorize(:red) + " #{signal.label}"
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