edfize 0.2.0 → 0.3.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b82a603335cdafd99e0c4661b2224c33f9430fe
4
- data.tar.gz: 0c61be32124471148d108fd367e2535a2ab6391f
3
+ metadata.gz: d66122964586be58ce465e8b40c8a9bd5b9cbacc
4
+ data.tar.gz: 690f94d0574fbc563fa8f0dd154dcdaaa9210bfb
5
5
  SHA512:
6
- metadata.gz: 5754f8f4f4d71c0f2b6d10fd3e00e138ec05948bbabd2524f97e5f97304baf35c8ee1854182b0a713e83082d296fc37d6202c5836cb2300364fab75a7e26a24d
7
- data.tar.gz: 135eb30a80bdf44511520090054695b8766a0f23c8277b049d84e0c3c19f856cecf91c2a65b4f0df6d54ae3076e3b14888912784d9cb29ed787e5e5777a9e0ea
6
+ metadata.gz: 14babae1e4a88344a373071784076b3eb12010504a1f1acbbe3aa4c2232b2d2b60efc91a6e3b1ae6f5cff5443a92f603ca4c1c6aa4baf413e9b0eec504dbc429
7
+ data.tar.gz: 650ec8d719d3e34e59fdd6721a95728d4084ade204679a4782021bc1004afe146f937ee3d3e0be96475dea91bd13a88e73512ade0112e9e8957a72cc25f8befc
data/CHANGELOG.md CHANGED
@@ -1,7 +1,25 @@
1
+ ## 0.3.0
2
+
3
+ ### Enhancements
4
+ - **Test Changes**
5
+ - Added a test to make sure date in EDF and EDF+ formats are valid
6
+ - The EDF header date is checked in the following manner: (a) Is the EDF+
7
+ header (29-FEB-2100) a valid date, if (yes) check that the EDF header date
8
+ (29.02.00) matches the EDF+ date, if (no) check that the EDF header date
9
+ (29.02.00) is a valid date. The EDF+ header date is checked first since
10
+ (29-FEB-2100) is NOT a valid date as leap years only occur in a century
11
+ years divisible by 400, while the truncated EDF date would be (02.29.00)
12
+ which would be incorrectly seen as valid since 2000 is a leap year.
13
+ - **Gem Changes**
14
+ - Updated to Ruby 2.3.0
15
+ - Updated to colorize 0.7.7
16
+ - Updated simplecov to 0.11.2
17
+
1
18
  ## 0.2.0 (March 12, 2015)
2
19
 
3
20
  ### Enhancements
4
- - EDFs can now be partially loaded by specifying the epoch number and epoch size in seconds
21
+ - EDFs can now be partially loaded by specifying the epoch number and epoch size
22
+ in seconds
5
23
  - Use of Ruby 2.2.1 is now recommended
6
24
 
7
25
  ### Testing
@@ -10,21 +28,24 @@
10
28
  ## 0.1.0 (May 28, 2014)
11
29
  - Initial EDF class to load headers and signals into Ruby objects
12
30
  - `edfize` command has the following actions:
13
- - `test`: Validates EDFs in the current directory and subdirectories for errors
31
+ - `test`: Validates EDFs in the current directory and subdirectories for
32
+ errors
14
33
  - To only show failing tests, add the flag `--failing`
15
34
  - `edfize test --failing`
16
35
  - To suppress descriptive test failures, add the flag `--quiet`
17
36
  - `edfize test --quiet`
18
37
  - Both flags can be used together
19
38
  - `edfize test --failing --quiet`
20
- - `run`: Prints out the headers of all edfs in the current directory and subdirectories
21
- - `help`: Displays information about `edfize` along with all available commands
39
+ - `run`: Prints out the headers of all EDFs in the current directory and
40
+ subdirectories
41
+ - `help`: Displays information about `edfize` along with all available
42
+ commands
22
43
  - `version`: Displays the current `edfize` version
23
44
  - `edfize test` checks for the following:
24
45
  - Expected Length Check: The expected total size is computed from the (`number
25
- of data records` * `total samples across all signals`) + `size of header` and
26
- this is compared to the actual file size.
27
- - Reserved Area Checks: The header and the individual header reserved areas are
28
- checked to validate that they are blank. Non-blank areas are a sign that the
29
- edf header is corrupt and that data from the signal data block have leaked into
30
- the header itself.
46
+ of data records` * `total samples across all signals`) + `size of header`
47
+ and this is compared to the actual file size.
48
+ - Reserved Area Checks: The header and the individual header reserved areas
49
+ are checked to validate that they are blank. Non-blank areas are a sign that
50
+ the EDF header is corrupt and that data from the signal data block have
51
+ leaked into the header itself.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Division of Medicine Program of Sleep Medicine Epidemiology
1
+ Copyright (c) 2016 Division of Sleep and Circadian Disorders
2
2
  https://github.com/sleepepi
3
3
 
4
4
 
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/sleepepi/edfize.svg?branch=master)](https://travis-ci.org/sleepepi/edfize)
4
4
  [![Dependency Status](https://gemnasium.com/sleepepi/edfize.svg)](https://gemnasium.com/sleepepi/edfize)
5
- [![Code Climate](https://codeclimate.com/github/sleepepi/edfize.png)](https://codeclimate.com/github/sleepepi/edfize)
5
+ [![Code Climate](https://codeclimate.com/github/sleepepi/edfize/badges/gpa.svg)](https://codeclimate.com/github/sleepepi/edfize)
6
6
 
7
- Ruby gem used to load, validate, and parse European Data Format files. Used for batch testing EDFs for errors. Ruby 2.0+ compatible.
7
+ Ruby gem used to load, validate, and parse European Data Format files. Used for batch testing EDFs for errors. Ruby 2.2+ compatible.
8
8
 
9
9
  ## Installation
10
10
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  require 'rake/testtask'
@@ -6,6 +8,7 @@ Rake::TestTask.new(:test) do |t|
6
8
  t.libs << 'lib'
7
9
  t.libs << 'test'
8
10
  t.pattern = 'test/**/*_test.rb'
11
+ t.warning = false
9
12
  t.verbose = false
10
13
  end
11
14
 
data/bin/edfize CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path('../../lib/edfize', __FILE__)
4
5
 
data/edfize.gemspec CHANGED
@@ -1,3 +1,6 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  # Compiling the Gem
2
5
  # gem build edfize.gemspec
3
6
  # gem install ./edfize-x.x.x.gem --no-ri --no-rdoc --local
@@ -6,28 +9,28 @@
6
9
  # gem list -r edfize
7
10
  # gem install edfize
8
11
 
9
- # coding: utf-8
10
12
  lib = File.expand_path('../lib', __FILE__)
11
13
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
12
14
  require 'edfize/version'
13
15
 
14
16
  Gem::Specification.new do |spec|
15
- spec.name = "edfize"
17
+ spec.name = 'edfize'
16
18
  spec.version = Edfize::VERSION::STRING
17
- spec.authors = ["Remo Mueller"]
18
- spec.email = ["remosm@gmail.com"]
19
- spec.summary = %q{Load, validate, and parse European Data Format files. Used for batch testing EDFs for errors.}
20
- spec.description = %q{Load, validate, and parse European Data Format files. Used for batch testing EDFs for errors. Run `edfize` on command line to view full list of options.}
21
- spec.homepage = "https://github.com/sleepepi/edfize"
22
- spec.license = "CC BY-NC-SA 3.0"
19
+ spec.authors = ['Remo Mueller']
20
+ spec.email = ['remosm@gmail.com']
21
+ spec.summary = 'Load, validate, and parse European Data Format files. Used for batch testing EDFs for errors.'
22
+ spec.description = 'Load, validate, and parse European Data Format files. Used for batch testing EDFs for errors. \
23
+ Run `edfize` on command line to view full list of options.'
24
+ spec.homepage = 'https://github.com/sleepepi/edfize'
25
+ spec.license = 'CC BY-NC-SA 3.0'
23
26
 
24
- spec.files = Dir['{bin,lib}/**/*'] + ['CHANGELOG.md', 'LICENSE.txt', 'Rakefile', 'README.md', 'edfize.gemspec']
27
+ spec.files = Dir['{bin,lib}/**/*'] + %w(CHANGELOG.md LICENSE Rakefile README.md edfize.gemspec)
25
28
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
29
  spec.test_files = spec.files.grep(%r{^(test)/})
27
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
28
31
 
29
- spec.add_dependency "colorize", "~> 0.7.5"
32
+ spec.add_dependency 'colorize', '~> 0.7.7'
30
33
 
31
- spec.add_development_dependency "bundler", "~> 1.8"
32
- spec.add_development_dependency "rake"
34
+ spec.add_development_dependency 'bundler', '~> 1.8'
35
+ spec.add_development_dependency 'rake'
33
36
  end
data/lib/edfize/edf.rb CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'edfize/signal'
2
4
 
3
5
  module Edfize
6
+ # Class used to load and manipulate EDFs
4
7
  class Edf
5
8
  # EDF File Path
6
9
  attr_reader :filename
@@ -40,7 +43,7 @@ module Edfize
40
43
  RESERVED_SIZE = HEADER_CONFIG[:reserved][:size]
41
44
 
42
45
  def self.create(filename, &block)
43
- edf = self.new(filename)
46
+ edf = new(filename)
44
47
  yield edf if block_given?
45
48
  edf
46
49
  end
@@ -66,7 +69,7 @@ module Edfize
66
69
  end
67
70
 
68
71
  def size_of_header
69
- HEADER_OFFSET + ns * Signal::SIGNAL_CONFIG.collect{|k,h| h[:size]}.inject(:+)
72
+ HEADER_OFFSET + ns * Signal::SIGNAL_CONFIG.collect { |_k, h| h[:size] }.inject(:+)
70
73
  end
71
74
 
72
75
  def expected_size_of_header
@@ -88,27 +91,25 @@ module Edfize
88
91
  end
89
92
 
90
93
  def section_value_to_string(section)
91
- self.instance_variable_get("@#{section}").to_s
94
+ instance_variable_get("@#{section}").to_s
92
95
  end
93
96
 
94
97
  def section_units(section)
95
98
  units = HEADER_CONFIG[section][:units].to_s
96
- result = if units == ''
99
+ if units == ''
97
100
  ''
98
101
  else
99
- " #{units}" + (self.instance_variable_get("@#{section}") == 1 ? '' : 's')
102
+ " #{units}" + (instance_variable_get("@#{section}") == 1 ? '' : 's')
100
103
  end
101
- result
102
104
  end
103
105
 
104
106
  def section_description(section)
105
107
  description = HEADER_CONFIG[section][:description].to_s
106
- result = if description == ''
108
+ if description == ''
107
109
  ''
108
110
  else
109
111
  " #{description}"
110
112
  end
111
- result
112
113
  end
113
114
 
114
115
  def print_header
@@ -133,6 +134,27 @@ module Edfize
133
134
  puts "Expected Total Size (bytes): #{expected_edf_size}"
134
135
  end
135
136
 
137
+ def start_date
138
+ (dd, mm, yy) = start_date_of_recording.split('.')
139
+ dd = parse_integer(dd)
140
+ mm = parse_integer(mm)
141
+ yy = parse_integer(yy)
142
+ yyyy = if yy && yy >= 85
143
+ yy + 1900
144
+ else
145
+ yy + 2000
146
+ end
147
+ Date.strptime("#{mm}/#{dd}/#{yyyy}", '%m/%d/%Y')
148
+ rescue
149
+ nil
150
+ end
151
+
152
+ def parse_integer(string)
153
+ Integer(format('%g', string))
154
+ rescue
155
+ nil
156
+ end
157
+
136
158
  protected
137
159
 
138
160
  def read_header
data/lib/edfize/signal.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edfize
2
4
  class Signal
3
5
  attr_accessor :label, :transducer_type, :physical_dimension,
@@ -26,7 +28,7 @@ module Edfize
26
28
  end
27
29
 
28
30
  def self.create(&block)
29
- signal = self.new
31
+ signal = new
30
32
  yield signal if block_given?
31
33
  signal
32
34
  end
@@ -45,6 +47,5 @@ module Edfize
45
47
  def samples
46
48
  @physical_values
47
49
  end
48
-
49
50
  end
50
51
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edfize
2
4
  module Tests
3
5
  module CheckLength
@@ -6,7 +8,7 @@ module Edfize
6
8
  def test_expected_length(runner)
7
9
  result = Result.new
8
10
  result.passes = (runner.edf.expected_edf_size == runner.edf.edf_size)
9
- result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize( result.passes ? :green : :red ) + " Expected File Size"
11
+ result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize(result.passes ? :green : :red) + ' Expected File Size'
10
12
  result.expected = " Expected : #{runner.edf.expected_edf_size} bytes"
11
13
  result.actual = " Actual : #{runner.edf.edf_size} bytes"
12
14
  result
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edfize
2
4
  module Tests
5
+ # This test checks that the reserved area in the header is blank
3
6
  module CheckReservedArea
4
- # This test checks that the reserved area in the header is blank
5
7
  def test_reserved_area_blank(runner)
6
8
  result = Result.new
7
9
  result.passes = (runner.edf.reserved == ' ' * Edf::RESERVED_SIZE)
8
- result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize( result.passes ? :green : :red ) + " Reserved Area Blank"
10
+ result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize(result.passes ? :green : :red) + ' Reserved Area Blank'
9
11
  result.expected = " Expected : #{(' ' * Edf::RESERVED_SIZE).inspect}"
10
12
  result.actual = " Actual : #{runner.edf.reserved.to_s.inspect}"
11
13
  result
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edfize
2
4
  module Tests
5
+ # This test checks that the reserved areas in the signal headers are blank
3
6
  module CheckReservedSignalAreas
4
- # This test checks that the reserved areas in the signal headers are blank
5
7
  def test_reserved_signal_areas_blank(runner)
6
8
  reserved_areas = runner.edf.signals.collect(&:reserved_area)
7
9
 
8
10
  result = Result.new
9
11
  result.passes = (reserved_areas.reject{|r| r.to_s.strip == ''}.count == 0)
10
- result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize( result.passes ? :green : :red ) + " Signal Reserved Area Blank"
12
+ result.pass_fail = " #{result.passes ? 'PASS' : 'FAIL'}".colorize(result.passes ? :green : :red) + ' Signal Reserved Area Blank'
11
13
  result.expected = " Expected : #{[''] * runner.edf.signals.count}"
12
14
  result.actual = " Actual : #{reserved_areas}"
13
15
  result
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Edfize
4
+ module Tests
5
+ # This test checks that the date is valid
6
+ module CheckValidDate
7
+ def test_valid_date(runner)
8
+ result = Result.new
9
+ result.passes = !runner.edf.start_date.nil?
10
+ result.pass_fail = pass_fail(result.passes, 'Valid Date')
11
+ result.expected = ' Expected : Valid Date'
12
+ result.actual = " Actual : #{runner.edf.start_date_of_recording}"
13
+ result
14
+ end
15
+
16
+ def pass_fail(passes, message)
17
+ if passes
18
+ ' PASS'.colorize(:green) + " #{message}"
19
+ else
20
+ ' FAIL'.colorize(:red) + " #{message}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edfize
2
4
  module Tests
3
5
  class Result
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edfize
2
4
  module Tests
5
+ # Runs a series of tests on an EDF
3
6
  class Runner
4
7
  attr_reader :tests_run, :tests_failed, :edf, :verbose, :show_passing
5
8
 
6
- TESTS = %w( expected_length reserved_area_blank reserved_signal_areas_blank )
9
+ TESTS = %w(expected_length reserved_area_blank reserved_signal_areas_blank valid_date)
7
10
 
8
11
  def initialize(edf, argv)
9
12
  @tests_run = 0
@@ -23,16 +26,16 @@ module Edfize
23
26
  results << result
24
27
  end
25
28
 
26
- puts "\n#{@edf.filename}" if results.reject{|r| r.passes}.count > 0 or @show_passing
29
+ puts "\n#{@edf.filename}" if results.reject(&:passes).count > 0 || @show_passing
27
30
  results.each do |result|
28
31
  print_result(result)
29
32
  end
30
33
  end
31
34
 
32
35
  def print_result(result)
33
- if self.show_passing or !result.passes
36
+ if show_passing || !result.passes
34
37
  puts result.pass_fail
35
- unless result.passes or not self.verbose
38
+ unless result.passes || !verbose
36
39
  puts result.expected
37
40
  puts result.actual
38
41
  end
data/lib/edfize/tests.rb CHANGED
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'edfize/tests/result'
2
4
  require 'edfize/tests/runner'
3
5
  require 'edfize/tests/check_length'
4
6
  require 'edfize/tests/check_reserved_area'
5
7
  require 'edfize/tests/check_reserved_signal_areas'
8
+ require 'edfize/tests/check_valid_date'
6
9
 
7
10
  module Edfize
8
11
  module Tests
9
12
  extend CheckLength
10
13
  extend CheckReservedArea
11
14
  extend CheckReservedSignalAreas
15
+ extend CheckValidDate
12
16
  end
13
17
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edfize
2
4
  module VERSION #:nodoc:
3
5
  MAJOR = 0
4
- MINOR = 2
6
+ MINOR = 3
5
7
  TINY = 0
6
- BUILD = nil
8
+ BUILD = 'beta1'
7
9
 
8
10
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
11
  end
data/lib/edfize.rb CHANGED
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'edfize/edf'
2
4
  require 'edfize/tests'
3
5
  require 'edfize/version'
4
6
 
5
7
  require 'colorize'
6
8
 
9
+ # Loads EDFs, prints information, runs tests
7
10
  module Edfize
8
11
  def self.launch(argv)
9
12
  case argv.first.to_s.scan(/\w/).first
@@ -19,11 +22,11 @@ module Edfize
19
22
  end
20
23
 
21
24
  def self.print_headers
22
- puts "----------------"
25
+ puts '----------------'
23
26
  edfs_in_current_directory_and_subdirectories.each do |edf_file_name|
24
27
  edf = Edfize::Edf.new(edf_file_name)
25
28
  edf.print_header
26
- puts "----------------"
29
+ puts '----------------'
27
30
  end
28
31
  end
29
32
 
@@ -45,7 +48,7 @@ module Edfize
45
48
  failure_count += runner.tests_failed
46
49
  end
47
50
  puts "\nFinished in #{Time.now - test_start_time}s"
48
- puts "#{edf_count} EDF#{'s' unless edf_count == 1}, #{test_count} test#{'s' unless test_count == 1}, " + "#{failure_count} failure#{'s' unless failure_count == 1}".colorize( failure_count == 0 ? :green : :red )
51
+ puts "#{edf_count} EDF#{'s' unless edf_count == 1}, #{test_count} test#{'s' unless test_count == 1}, " + "#{failure_count} failure#{'s' unless failure_count == 1}".colorize(failure_count == 0 ? :green : :red)
49
52
  end
50
53
 
51
54
  def self.help
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edfize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.5
19
+ version: 0.7.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.5
26
+ version: 0.7.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,8 +52,9 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Load, validate, and parse European Data Format files. Used for batch
56
- testing EDFs for errors. Run `edfize` on command line to view full list of options.
55
+ description: |-
56
+ Load, validate, and parse European Data Format files. Used for batch testing EDFs for errors. \
57
+ Run `edfize` on command line to view full list of options.
57
58
  email:
58
59
  - remosm@gmail.com
59
60
  executables:
@@ -62,7 +63,7 @@ extensions: []
62
63
  extra_rdoc_files: []
63
64
  files:
64
65
  - CHANGELOG.md
65
- - LICENSE.txt
66
+ - LICENSE
66
67
  - README.md
67
68
  - Rakefile
68
69
  - bin/edfize
@@ -74,6 +75,7 @@ files:
74
75
  - lib/edfize/tests/check_length.rb
75
76
  - lib/edfize/tests/check_reserved_area.rb
76
77
  - lib/edfize/tests/check_reserved_signal_areas.rb
78
+ - lib/edfize/tests/check_valid_date.rb
77
79
  - lib/edfize/tests/result.rb
78
80
  - lib/edfize/tests/runner.rb
79
81
  - lib/edfize/version.rb
@@ -92,12 +94,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
94
  version: '0'
93
95
  required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  requirements:
95
- - - ">="
97
+ - - ">"
96
98
  - !ruby/object:Gem::Version
97
- version: '0'
99
+ version: 1.3.1
98
100
  requirements: []
99
101
  rubyforge_project:
100
- rubygems_version: 2.4.6
102
+ rubygems_version: 2.6.1
101
103
  signing_key:
102
104
  specification_version: 4
103
105
  summary: Load, validate, and parse European Data Format files. Used for batch testing