Class: Roi

Inherits:
Object show all
Includes:
CanHaveSpecialMethods
Defined in:
lib/roi/roi.rb

Direct Known Subclasses

BlackRoi, ColorRoi, ImageRoi, TextRoi, VideoRoi

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CanHaveSpecialMethods

included

Constructor Details

#initialize(dut, args = {}) ⇒ Roi

Public: Initializes a base Roi.

dut - Platform (or subclass) instance to which this Roi belongs. x - Integer x coordinate (default: nil). y - Integer y coordinate (default: nil). width - Integer width (default: nil). height - Integer height (default: nil). rectangle - Hash defining rectangle with keys :x, :y, :width, :height (default: nil). element - Hash same as rectangle (default: nil). ref_img - String path to reference image (default: nil).

Returns nothing.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/roi/roi.rb', line 23

def initialize(dut, args={})
  @name = nil
  # Determine ROI name. This will be the first method that calls `new'.

  stack = caller
  last_end = stack.each_index.select do |i|
    stack[i].end_with?("in `new'")
  end.last
  unless last_end.nil?
    match = stack[last_end + 1].match(/`(\w+)'/)
    unless match.nil?
      @name = match[1] unless match[1] == 'run'  # ignore dynamic ROIs

    end
  end
  if args.include?(:element)
    self.rectangle=args[:element]
  else
    self.rectangle=(args.fetch(:rectangle, args))  # Get x, y, width, and height from rectangle (if provided) or args

  end
  @ref_img = args.fetch(:ref_img, '')
  @dut = dut
  # These are declared without the convenience methods (TMC monkey patching) so as not to break syntax evaluation.

  @priorities = {
      :critical => 0.01,
      :high => 0.1,
      :normal => 1,
      :low => 10,
      :background => 60
  }
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



8
9
10
# File 'lib/roi/roi.rb', line 8

def height
  @height
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/roi/roi.rb', line 9

def name
  @name
end

#ref_imgObject

Returns the value of attribute ref_img.



8
9
10
# File 'lib/roi/roi.rb', line 8

def ref_img
  @ref_img
end

#widthObject

Returns the value of attribute width.



8
9
10
# File 'lib/roi/roi.rb', line 8

def width
  @width
end

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/roi/roi.rb', line 8

def x
  @x
end

#yObject

Returns the value of attribute y.



8
9
10
# File 'lib/roi/roi.rb', line 8

def y
  @y
end

Instance Method Details

#displayed?(*args) ⇒ Boolean

Public: Placeholder for displayed?, which must be implemented by each Roi type.

Returns:

  • (Boolean)


80
81
82
# File 'lib/roi/roi.rb', line 80

def displayed?(*args)
  raise "#{self.class.name} does not implement special method `displayed?'"
end

#find_frame_displayed(frames, start_time, args = {}) ⇒ Object

Public: Finds the frame in which the given Roi verifies.

Corresponds to: api_find_<ROI TYPE>_frame

frames - Array of frames to search, each being a Hash with the following keys:

:filename   - String full path to the frame on the server.
:capturedAt - Time at which the frame was captured.
:keep       - Boolean indicating whether to keep the frame if cleanup is true. Initializes false.

start_time - Time at which frame capture began. starting_frame - Integer index of frame at which to start evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, all frames will be searched.

scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

verifies_for - Integer total milliseconds for which the ROI must continuously verify in order to be counted

successful (default: 0).
If default, the ROI must only verify once.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: false).

Returns the Integer index of the matching frame.



578
579
580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/roi/roi.rb', line 578

def find_frame_displayed(frames, start_time, args={})
  logger.info("Finding frame where #{self.class.name} is displayed")
  args[:with_last_frame] = true
  args[:report] = false
  if frames.count < 2
    default_timeout = 30.sec
  else
    default_timeout = test_case.get_time_delta(frames.first[:capturedAt], frames.last[:capturedAt])
  end
  args[:timeout] ||= default_timeout
  frame(frames, start_time, args) do |frame, last_frame|
    displayed?(:frame => frame, :last_frame => last_frame, :set_roi_options => args)
  end
end

#find_frame_not_displayed(frames, start_time, args = {}) ⇒ Object

Public: Finds the frame in which the given Roi does not verify.

Corresponds to: api_find_non_<ROI TYPE>_frame

frames - Array of frames to search, each being a Hash with the following keys:

:filename   - String full path to the frame on the server.
:capturedAt - Time at which the frame was captured.
:keep       - Boolean indicating whether to keep the frame if cleanup is true. Initializes false.

start_time - Time at which frame capture began. starting_frame - Integer index of frame at which to start evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, all frames will be searched.

scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

verifies_for - Integer total milliseconds for which the ROI must continuously verify in order to be counted

successful (default: 0).
If default, the ROI must only verify once.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: false).

Returns the Integer index of the matching frame.



620
621
622
623
624
625
626
627
628
# File 'lib/roi/roi.rb', line 620

def find_frame_not_displayed(frames, start_time, args={})
  logger.info("Finding frame where #{self.class.name} is not displayed")
  args[:with_last_frame] = true
  args[:expected] = false
  args[:report] = false
  frame(frames, start_time, args) do |frame, last_frame|
    displayed?(:frame => frame, :last_frame => last_frame, :set_roi_options => args)
  end
end

#infoObject

Public: Gets Roi info.

Returns a tidy String with Roi info.



75
76
77
# File 'lib/roi/roi.rb', line 75

def info
  "#{self.class.name}: X=#{@x} Y=#{@y} Width=#{@width} Height=#{@height} Ref.Image=#{@ref_img}"
end

#precise_time_to_change(args = {}) ⇒ Object

Public: Measures the precise time for the given Roi to change.

Corresponds to: api_hp_time_to_<ROI TYPE>_change

key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, timeout will be calculated as [ delay + 5000 ].

scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).

Returns the Float total milliseconds for the Roi to change.



539
540
541
542
543
544
545
546
547
548
549
# File 'lib/roi/roi.rb', line 539

def precise_time_to_change(args={})
  logger.info("Measuring precise time for #{self.class.name} to change")
  args[:precise] = true
  set_roi_options(args)
  values = [retrieve]
  measure(args, values) do |frame, vals|
    value = retrieve(:frame => frame)
    vals << value
    value != vals.first
  end
end

#precise_time_to_disappear(args = {}) ⇒ Object

Public: Measures the precise time for the given Roi to disappear.

Corresponds to: api_hp_time_for_<ROI TYPE>_to_disappear

key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, timeout will be calculated as [ delay + 5000 ].

scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).

Returns the Float total milliseconds for the Roi to disappear.



363
364
365
366
367
368
369
370
# File 'lib/roi/roi.rb', line 363

def precise_time_to_disappear(args={})
  logger.info("Measuring precise time for #{self.class.name} to disappear")
  args[:precise] = true
  args[:with_last_frame] = true
  measure(args) do |frame, last_frame|
    displayed?(:frame => frame, :last_frame => last_frame, :expected => false, :set_roi_options => args)
  end
end

#precise_time_to_display(args = {}) ⇒ Object

Public: Measures the precise time for the given Roi to be displayed.

Corresponds to: api_hp_time_to_display_<ROI TYPE>

key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, timeout will be calculated as [ delay + 5000 ].

scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).

Returns the Float total milliseconds for the Roi to be displayed.



215
216
217
218
219
220
221
222
# File 'lib/roi/roi.rb', line 215

def precise_time_to_display(args={})
  logger.info("Measuring precise time to display #{self.class.name}")
  args[:precise] = true
  args[:with_last_frame] = true
  measure(args) do |frame, last_frame|
    displayed?(:frame => frame, :last_frame => last_frame, :set_roi_options => args)
  end
end

#precise_time_to_match_dut(other_dut, timeout, args = {}) ⇒ Object

Public: Measures the precise time for the given Roi to match on the specified DUT.

other_dut - Platform (or subclass) instance of DUT to match. timeout - Integer total milliseconds to allow before timing out. key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). report - Boolean indicating whether to report measurements to ITMS (default: true). NOT YET IMPLEMENTED.

Returns the Float total milliseconds for the Roi to disappear.



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/roi/roi.rb', line 235

def precise_time_to_match_dut(other_dut, timeout, args={})
  #TODO: this probably needs some work for the new EE

  msg = "Measuring precise time for #{info} to match DUT #{other_dut.model}:#{other_dut.slot}"
  logger.roi(self, args.merge(:message => msg, :screenshot => false))
  key = args[:key]
  delay = args.fetch(:delay, 0)
  other_roi = args[:other_roi]
  left_frames = []
  right_frames = []
  test_case.add_teardown('Cleaning up captured frames') do
    json = get_json_for_test.merge(files: (left_frames + right_frames).map {|frm| frm['path']})
    test_case.send(:tmc_delete, '/api/images', json: json )
  end
  # Press key if specified

  unless key.nil?
    do_trigger(key, :duts => [dut, other_dut])
  end
  # Delay if specified

  if delay > 0
    sleep(delay / 1000.0)  # this is native sleep

  end
  # Capture frames for the duration

  json1 = get_json_for_iter.merge(durationMs: timeout)
  threads = [
      Thread.new do
        resp = test_case.send(:tmc_post, "/api/images/record/#{dut.slot}", json: json1)
        left_frames += resp.fetch('images')
      end,
      Thread.new do
        resp = test_case.send(:tmc_post, "/api/images/record/#{other_dut.slot}", json: json1)
        right_frames += resp.fetch('images')
      end
  ]
  threads.each { |thr| thr.join }  # wait all threads

  if left_frames.empty? || right_frames.empty?
    raise 'Not enough images captured for analysis!'
  end
  # Send frames for processing

  if other_roi.nil?
    right_roi = rectangle
  else
    right_roi = other_roi.rectangle
  end
  right_roi.update(:threshold => threshold) unless right_roi.nil?
  json2 = get_json_for_compare_2(rectangle, right_roi, left_frames: left_frames, right_frames: right_frames)
  result = test_case.send(:tmc_post, '/api/roi/video/actions', json: json2)['value']
  # TODO: figure out which frame(s) and display them

  logger.roi(self, args.merge(message: "#{result.nil? ? 'no ' : ''}matching frames found".capitalize,
                              screenshot: false))
  logger.duration(result, message: 'Time to match') unless result.nil?
  result
end

#precise_time_to_transition(args = {}) ⇒ Object

Public: Measures the precise time for the given Roi to transition from false to true to false.

Corresponds to: api_hp_time_for_<ROI TYPE>_transition

key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, timeout will be calculated as [ delay + 5000 ].

expected - Array of expected transition values (default: [true, false]). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).

Returns the Float total milliseconds for the Roi to transition.



451
452
453
454
455
456
457
458
# File 'lib/roi/roi.rb', line 451

def precise_time_to_transition(args={})
  logger.info("Measuring precise time for #{self.class.name} to transition")
  args[:expected] ||= [true, false]
  args[:precise] = true
  measure(args) do |frame|
    displayed?(:frame => frame, :set_roi_options => args)
  end
end

#press_key_until_displayed?(key, args = {}) ⇒ Boolean

Public: Presses a key until the given Roi is displayed.

Corresponds to api_press_key_till_<ROI TYPE>_displayed?

key - String name of key to press. presses - Integer maximum number of times to press the key (default: nil). timeout - Integer total milliseconds to allow before timing out (default: 30000). delay - Integer total milliseconds to delay before starting evaluation (default: 0). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

try_every - Integer total milliseconds to delay between key presses (default: 3000). try_timeout - Integer total milliseconds to allow after each key press before timing out (default: nil). verifies_for - Integer total milliseconds for which the ROI must verify in order to succeed (default: 0).

If default, the ROI must only verify once.

priority - Symbol representing evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 milliseconds between intensive tasks (should be used sparingly).
:high       - Sleep 100 milliseconds between intensive tasks.
:normal     - Sleep 1 second between intensive tasks (default).
:low        - Sleep 10 seconds between intensive tasks.
:background - Sleep 1 minute between intensive tasks (should be used sparingly).

log_every - Integer interval in milliseconds between logs (default: 1000). message - String message to log instead of the default (default: nil).

Default logs a tailored message.

Returns Boolean true if displayed before the timeout, otherwise false.

Returns:

  • (Boolean)


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/roi/roi.rb', line 142

def press_key_until_displayed?(key, args={})
  logger.info("Pressing key #{key.inspect} until #{self.class.name} is displayed")
  timeout_s = args.fetch(:timeout, 30.sec) / 1.sec
  args[:timeout] = args[:try_timeout]
  key_delay = args.fetch(:try_every, 3.sec)
  presses = args[:presses]
  press_count = 0
  start_time = Time.now
  displayed = false
  loop do
    displayed = displayed?(args)
    break if displayed
    if presses.nil?
      break if (Time.now - start_time) > timeout_s
    elsif press_count == presses
      break
    end
    @dut.press_key(key, :sleep_time => key_delay)
    press_count += 1
  end
  displayed
end

#rectangleObject

Public: Gets Roi rectangle.

Returns Roi rectangle as a Hash with keys :x, :y, :width, :height.



56
57
58
# File 'lib/roi/roi.rb', line 56

def rectangle
  {:x => @x, :y => @y, :width => @width, :height => @height}
end

#rectangle=(rectangle) ⇒ Object

Public: Sets Roi rectangle.

rectangle - Hash with keys :x, :y, :width, and :height from which to set Roi rectangle.

Returns nothing.



65
66
67
68
69
70
# File 'lib/roi/roi.rb', line 65

def rectangle=(rectangle)
  @x = rectangle[:x]
  @y = rectangle[:y]
  @width = rectangle[:width]
  @height = rectangle[:height]
end

#retrieve(*args) ⇒ Object

Public: Placeholder for retrieve, which must be implemented by each Roi type.



85
86
87
# File 'lib/roi/roi.rb', line 85

def retrieve(*args)
  raise "#{self.class.name} does not implement special method `retrieve'"
end

#time_to_change(args = {}) ⇒ Object

Public: Measures the approximate time for the given Roi to change.

Corresponds to: api_time_to_<ROI TYPE>_change

key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, timeout will be calculated as [ delay + 5000 ].

scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).

Returns the Float total milliseconds for the Roi to change.



509
510
511
512
513
514
515
516
# File 'lib/roi/roi.rb', line 509

def time_to_change(args={})
  logger.info("Measuring time for #{self.class.name} to change")
  set_roi_options(args)
  first = retrieve
  measure(args) do
    retrieve != first
  end
end

#time_to_disappear(args = {}) ⇒ Object

Public: Measures the approximate time for the given Roi to disappear.

Corresponds to: api_time_for_<ROI TYPE>_to_disappear

key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, timeout will be calculated as [ delay + 5000 ].

scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).

Returns the Float total milliseconds for the ROI to disappear.



335
336
337
338
339
340
# File 'lib/roi/roi.rb', line 335

def time_to_disappear(args={})
  logger.info("Measuring time for #{self.class.name} to disappear")
  measure(args) do
    displayed?(:expected => false, :set_roi_options => args)
  end
end

#time_to_display(args = {}) ⇒ Object

Public: Measures the approximate time for the given Roi to be displayed.

Corresponds to: api_time_to_display_<ROI TYPE>

key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, timeout will be calculated as [ delay + 5000 ].

scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

expected - Boolean expected result of evaluation or Array of expected transition values (default: true). priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).

Returns the Float total milliseconds for the ROI to be displayed.



187
188
189
190
191
192
# File 'lib/roi/roi.rb', line 187

def time_to_display(args={})
  logger.info("Measuring time to display #{self.class.name}")
  measure(args) do
    displayed?(:set_roi_options => args)
  end
end

#time_to_transition(args = {}) ⇒ Object

Public: Measures the approximate time for the given Roi to transition from false to true to false.

Corresponds to: api_time_for_<ROI TYPE>_transition

key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).

If default, timeout will be calculated as [ delay + 5000 ].

expected - Array of expected transition values (default: [true, false]). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).

Returns the Float total milliseconds for the ROI to transition.



421
422
423
424
425
426
427
# File 'lib/roi/roi.rb', line 421

def time_to_transition(args={})
  logger.info("Measuring time for #{self.class.name} to transition")
  args[:expected] ||= [true, false]
  measure(args) do
    displayed?(:set_roi_options => args)
  end
end

#wait_for_change?(timeout, args = {}) ⇒ Boolean

Public: Returns true if the given Roi changes before the specified timeout.

timeout - Integer total milliseconds to allow before timing out. key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000).

Returns a Boolean true if the Roi changed before the timeout, otherwise false.

Returns:

  • (Boolean)


478
479
480
481
482
483
484
485
486
# File 'lib/roi/roi.rb', line 478

def wait_for_change?(timeout, args={})
  logger.info("Waiting #{timeout} ms for #{self.class.name} to change")
  args[:timeout] = timeout
  set_roi_options(args)
  first = retrieve
  verify(args) do
    retrieve != first
  end
end

#wait_for_transition?(timeout, args = {}) ⇒ Boolean

Public: Returns true if the given Roi transitions before the specified timeout from false to true to false.

Corresponds to: api_wait_for_<ROI TYPE>_transition?

timeout - Integer total milliseconds to allow before timing out. key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). expected - Array of expected transition values (default: [true, false]). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000).

Returns a Boolean true if the Roi transitioned before the timeout, otherwise false.

Returns:

  • (Boolean)


392
393
394
395
396
397
# File 'lib/roi/roi.rb', line 392

def wait_for_transition?(timeout, args={})
  logger.info("Waiting #{timeout} ms for #{self.class.name} transition")
  args[:timeout] = timeout
  args[:expected] ||= [true, false]
  displayed?(args)
end

#wait_until_displayed?(timeout, args = {}) ⇒ Boolean

Public: Waits until the given ROI is displayed.

Corresponds to api_wait_till_<ROI TYPE>_displayed?

timeout - Integer total milliseconds to allow before timing out. key - String name of key to press to trigger evaluation (default: nil).

If default, no keys will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

verifies_for - Integer total milliseconds for which the ROI must verify in order to succeed (default: 0).

If default, the ROI must only verify once.

priority - Symbol representing evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 milliseconds between intensive tasks (should be used sparingly).
:high       - Sleep 100 milliseconds between intensive tasks.
:normal     - Sleep 1 second between intensive tasks (default).
:low        - Sleep 10 seconds between intensive tasks.
:background - Sleep 1 minute between intensive tasks (should be used sparingly).

log_every - Integer interval in milliseconds between logs (default: 1000). message - String message to log instead of the default (default: nil).

Default logs a tailored message.

Returns Boolean true if displayed before the timeout, otherwise false.

Returns:

  • (Boolean)


111
112
113
114
115
# File 'lib/roi/roi.rb', line 111

def wait_until_displayed?(timeout, args={})
  logger.info("Waiting #{timeout} ms until #{self.class.name} is displayed")
  args[:timeout] = timeout
  displayed?(args)
end

#wait_until_not_displayed?(timeout, args = {}) ⇒ Boolean

Public: Returns true if the given Roi disappears within the given time.

api_wait_till_<ROI TYPE>_not_displayed?

timeout - Integer total milliseconds to allow before timing out. key - String key press to trigger evaluation (default: nil).

If default, no key will be pressed.

delay - Integer total milliseconds to delay before starting evaluation (default: 0). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).

Applies to image ROIs only.

priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):

:critical   - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high       - Sleep 100 ms between intensive tasks
:normal     - Sleep 1 second between intensive tasks
:low        - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)

log_every - Integer total milliseconds between logs (default: 1000).

Returns a Boolean true if the Roi disappears before the timeout, otherwise false.

Returns:

  • (Boolean)


307
308
309
310
311
312
# File 'lib/roi/roi.rb', line 307

def wait_until_not_displayed?(timeout, args={})
  logger.info("Waiting #{timeout} ms until #{self.class.name} is not displayed")
  args[:timeout] = timeout
  args[:expected] = false
  displayed?(args)
end