ruby_marks 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -423,10 +423,12 @@ end
423
423
  ```ruby
424
424
  # Will execute your custom code if didn't a group isn't found, or it have a line count different than expected,
425
425
  # or in one or more lines the options marks found are different of the specified in marks options.
426
- # It returns the recognizer object, a boolean value to incorrect expected lines count, and a boolean value
427
- # to incorrect bubble line found, and a boolean value to bubbles adjusted or not.
426
+ # It returns the recognizer object, a boolean value to incorrect expected lines count, and a hash with the
427
+ # incorrect bubble lines found, and a hash with the coordinates of bubbles adjusted.
428
+ # Pay attention on incorrect_expected_lines and incorrect_bubble_line_found, because if some of this variables
429
+ # becomes present, then your document may have an incorrect result scan...
428
430
 
429
- recognizer.add_watcher :clock_mark_difference_watcher do |recognizer, incorrect_expected_lines, incorrect_bubble_line_found, bubbles_adjusted|
431
+ recognizer.add_watcher :incorrect_group_watcher do |recognizer, incorrect_expected_lines, incorrect_bubble_line_found, bubbles_adjusted|
430
432
  # place your custom code
431
433
  end
432
434
  ```
@@ -6,11 +6,10 @@ module RubyMarks
6
6
  attr_accessor :mark_width, :mark_height, :marks_options, :coordinates, :expected_coordinates,
7
7
  :mark_width_tolerance, :mark_height_tolerance, :marks, :distance_between_marks
8
8
 
9
-
10
9
  def initialize(label, recognizer)
11
10
  @label = label
12
11
  @recognizer = recognizer
13
-
12
+
14
13
  @mark_width = @recognizer.config.default_mark_width
15
14
  @mark_height = @recognizer.config.default_mark_height
16
15
 
@@ -4,7 +4,7 @@ module RubyMarks
4
4
  class Recognizer
5
5
 
6
6
  attr_reader :file, :raised_watchers, :groups, :watchers, :file_str, :original_file_str
7
- attr_accessor :config
7
+ attr_accessor :config, :groups_detected
8
8
 
9
9
 
10
10
  def initialize
@@ -23,6 +23,7 @@ module RubyMarks
23
23
  @file = @file.threshold(@config.calculated_threshold_level)
24
24
  @original_file = @file
25
25
  @file = @file.edge(@config.edge_level)
26
+ @groups_detected = false
26
27
 
27
28
  @groups.each_pair do |label, group|
28
29
  group.marks = Hash.new { |hash, key| hash[key] = [] }
@@ -84,7 +85,7 @@ module RubyMarks
84
85
  result = Hash.new { |hash, key| hash[key] = [] }
85
86
  result.tap do |result|
86
87
 
87
- self.detect_groups
88
+ self.detect_groups unless @groups_detected
88
89
 
89
90
  @groups.each_pair do |label, group|
90
91
  marks = Hash.new { |hash, key| hash[key] = [] }
@@ -92,14 +93,12 @@ module RubyMarks
92
93
  value.each do |mark|
93
94
  marks[line] << mark.value if mark.marked?
94
95
  end
96
+
97
+ multiple_marked_found = true if marks[line].size > 1
98
+ unmarked_group_found = true if marks[line].empty?
95
99
  end
96
-
97
- if marks.any?
98
- result[group.label.to_sym] = marks
99
- multiple_marked_found = true if marks.size > 1
100
- else
101
- unmarked_group_found = true
102
- end
100
+ marks.delete_if { |line, value| value.empty? }
101
+ result[group.label.to_sym] = marks if marks.any?
103
102
  end
104
103
 
105
104
  raise_watcher :scan_unmarked_watcher, result if unmarked_group_found
@@ -112,8 +111,8 @@ module RubyMarks
112
111
  def detect_groups
113
112
  file_str = RubyMarks::ImageUtils.export_file_to_str(@file)
114
113
  original_file_str = RubyMarks::ImageUtils.export_file_to_str(@original_file)
115
- incorrect_bubble_line_found = false
116
- bubbles_adjusted = false
114
+ incorrect_bubble_line_found = Hash.new { |hash, key| hash[key] = [] }
115
+ bubbles_adjusted = []
117
116
  incorrect_expected_lines = false
118
117
  @groups.each_pair do |label, group|
119
118
  next unless group.expected_coordinates.any?
@@ -185,8 +184,6 @@ module RubyMarks
185
184
  first_position += marks.first.coordinates[:x1]
186
185
 
187
186
  elements_position_count += 1
188
- else
189
- incorrect_bubble_line_found = true
190
187
  end
191
188
  end
192
189
 
@@ -204,7 +201,7 @@ module RubyMarks
204
201
 
205
202
  group.marks[line].delete(current_mark)
206
203
  reprocess = true
207
- bubbles_adjusted = true
204
+ bubbles_adjusted << current_mark.coordinates
208
205
  break
209
206
 
210
207
  else
@@ -248,7 +245,7 @@ module RubyMarks
248
245
  group.marks[line] << current_mark
249
246
  group.marks[line].sort! { |a, b| a.coordinates[:x1] <=> b.coordinates[:x1] }
250
247
  reprocess = true
251
- bubbles_adjusted = true
248
+ bubbles_adjusted << current_mark.coordinates
252
249
  break
253
250
  end
254
251
  end
@@ -261,11 +258,16 @@ module RubyMarks
261
258
  end
262
259
  end
263
260
 
261
+ group.marks.each_pair do |line, marks|
262
+ if marks.count != group.marks_options.count
263
+ incorrect_bubble_line_found[group.label.to_sym] << line
264
+ end
265
+ end
264
266
  end
265
267
  end
266
-
267
- if incorrect_bubble_line_found || bubbles_adjusted || incorrect_expected_lines
268
- raise_watcher :incorrect_group_watcher, incorrect_expected_lines, incorrect_bubble_line_found, bubbles_adjusted
268
+ @groups_detected = true
269
+ if incorrect_bubble_line_found.any? || bubbles_adjusted.any? || incorrect_expected_lines
270
+ raise_watcher :incorrect_group_watcher, incorrect_expected_lines, incorrect_bubble_line_found, bubbles_adjusted.flatten
269
271
  end
270
272
  end
271
273
 
@@ -370,7 +372,7 @@ module RubyMarks
370
372
 
371
373
  file.tap do |file|
372
374
 
373
- self.detect_groups
375
+ self.detect_groups unless @groups_detected
374
376
 
375
377
  @groups.each_pair do |label, group|
376
378
 
@@ -1,3 +1,3 @@
1
1
  module RubyMarks
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
@@ -138,7 +138,7 @@ class RubyMarks::RecognizerTest < Test::Unit::TestCase
138
138
  @file = 'assets/sheet_demo1_invalid.png'
139
139
  @recognizer.file = @file
140
140
 
141
- @recognizer.add_watcher :incorrect_group_watcher
141
+ @recognizer.add_watcher :incorrect_group_watcher
142
142
 
143
143
  @recognizer.scan
144
144
  assert @recognizer.raised_watchers.include?(:incorrect_group_watcher)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_marks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: