Class: BlackRoi
- Includes:
- CanHaveSpecialMethods
- Defined in:
- lib/roi/black/black_roi.rb
Overview
The BlackRoi class defines a black Roi and its methods
Instance Attribute Summary collapse
-
#blackness ⇒ Object
Returns the value of attribute blackness.
Attributes inherited from Roi
#height, #name, #ref_img, #width, #x, #y
Instance Method Summary collapse
-
#displayed?(args = {}) ⇒ Boolean
Public: Checks if screen exceeds the black threshold as defined in the given ROI.
-
#info ⇒ Object
Public: Gets black Roi info.
-
#initialize(dut, args = {}) ⇒ BlackRoi
constructor
Public: Initializes a black Roi.
-
#level ⇒ Object
Public: Gets the blackness level.
-
#retrieve(args = {}) ⇒ Object
Public: Gets the blackness of the region defined in the Roi.
Methods included from CanHaveSpecialMethods
Methods inherited from Roi
#find_frame_displayed, #find_frame_not_displayed, #precise_time_to_change, #precise_time_to_disappear, #precise_time_to_display, #precise_time_to_match_dut, #precise_time_to_transition, #press_key_until_displayed?, #rectangle, #rectangle=, #time_to_change, #time_to_disappear, #time_to_display, #time_to_transition, #wait_for_change?, #wait_for_transition?, #wait_until_displayed?, #wait_until_not_displayed?
Constructor Details
#initialize(dut, args = {}) ⇒ BlackRoi
Public: Initializes a black 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). blackness - Integer blackness percent 0 - 100 (default: 80). ref_img - String path to reference image (default: nil).
Returns nothing.
24 25 26 27 28 29 30 |
# File 'lib/roi/black/black_roi.rb', line 24 def initialize(dut, args={}) super(dut, args) @blackness = args.fetch(:blackness, 80) @similarity = @blackness @dsl_black_roi = nil @max_lvl = 255.0 end |
Instance Attribute Details
#blackness ⇒ Object
Returns the value of attribute blackness.
9 10 11 |
# File 'lib/roi/black/black_roi.rb', line 9 def blackness @blackness end |
Instance Method Details
#displayed?(args = {}) ⇒ Boolean
Public: Checks if screen exceeds the black threshold as defined in the given ROI.
Corresponds to: api_is_screen_black?
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). timeout - Integer total milliseconds to allow before timing out (default: 0). 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).
Returns a Boolean true if the screen is black before the timeout, otherwise false.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/roi/black/black_roi.rb', line 67 def displayed?(args={}) logger.info('Checking if black is displayed') frame = args[:frame] verify(args) do if frame.nil? # Check blackness on the screen json = get_json_for_match result = test_case.send(:tmc_post, "/api/roi/black/actions/#{dut.slot}", json: json)['value'] logger.roi(self, args.merge(message: "Screen is#{result ? '' : ' not'} at least #{blackness}% black", use_last_image: true)) else # Check blackness in the frame json = get_json_for_match(frame: frame) result = test_case.send(:tmc_post, '/api/roi/black/actions', json: json)['value'] logger.roi(self, args.merge(message: "Frame is#{result ? '' : ' not'} at least #{blackness}% black", screenshot: false)) end result end end |
#info ⇒ Object
Public: Gets black Roi info.
Returns a tidy String with black Roi info.
45 46 47 |
# File 'lib/roi/black/black_roi.rb', line 45 def info "#{super} Blackness=#{@blackness}" end |
#level ⇒ Object
Public: Gets the blackness level.
Returns the Integer blackness level (0 - 255).
35 36 37 38 39 40 |
# File 'lib/roi/black/black_roi.rb', line 35 def level lvl = @max_lvl - ((@blackness / 100.0) * @max_lvl) ret = lvl.to_i ret += 1 if lvl > ret # always round up ret end |
#retrieve(args = {}) ⇒ Object
Public: Gets the blackness of the region defined in the Roi.
Returns the Integer blackness level (0 - 255) of the Roi region.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/roi/black/black_roi.rb', line 92 def retrieve(args={}) logger.info('Retrieving blackness') frame = args[:frame] value(args) do if frame.nil? # Get blackness from the screen json = get_json_for_get lvl = test_case.send(:tmc_post, "/api/roi/black/actions/#{dut.slot}", json: json)['value'] else # Get blackness from the frame json = get_json_for_get(frame: frame) lvl = test_case.send(:tmc_post, '/api/roi/black/actions', json: json)['value'] end blk = level2blackness(lvl) logger.roi(self, args.merge(message: "Retrieved blackness: #{blk}%", use_last_image: frame.nil?, screenshot: frame.nil?)) blk end end |