Ejemplo n.º 1
0
    def test_area(self):
        area = Area(50, 60, 10, 20)
        self.assertEqual('area', area.isa)
        self.assertEqual(50, area.x)
        self.assertEqual(60, area.y)
        self.assertEqual(10, area.w)
        self.assertEqual(20, area.h)
        self.assertEqual(45, area.x1)
        self.assertEqual(55, area.x2)
        self.assertEqual(50, area.y1)
        self.assertEqual(70, area.y2)

        area.resize(50, 50)
        self.assertEqual(25, area.x1)
        self.assertEqual(75, area.x2)
        self.assertEqual(35, area.y1)
        self.assertEqual(85, area.y2)
        area.resize(10, 20)

        self.assertTrue(area.contains(Location(50, 60)))
        self.assertTrue(area.contains(Location(45, 50)))
        self.assertTrue(area.contains(Location(55, 70)))
        self.assertFalse(area.contains(Location(44, 50)))
        self.assertFalse(area.contains(Location(56, 70)))
        self.assertFalse(area.contains(Location(45, 49)))
        self.assertFalse(area.contains(Location(55, 71)))

        self.assertAlmostEqual(
            10, area.approach_width_from(Location(0, 60)), 2)
        self.assertAlmostEqual(
            20, area.approach_width_from(Location(50, 0)), 2)
Ejemplo n.º 2
0
    def test_location(self):
        loc = Location(10, 20)
        self.assertEqual('location', loc.isa)
        self.assertEqual(10, loc.x)
        self.assertEqual(20, loc.y)
        loc.move(50, 60)
        self.assertEqual(50, loc.x)
        self.assertEqual(60, loc.y)

        loc2 = Location(30, 40, 'loc')
        self.assertEqual('loc', loc2.get('isa'))
        self.assertAlmostEqual(28.28, loc2.distance_to(loc), 2)
Ejemplo n.º 3
0
 def __init__(self, agent):
     super().__init__('eyes', agent)
     self.vision = None
     self.loc = Location(0, 0)
     self.last_prep_cancel = None
     self.fixate_fns = []
     self.enc_time_f = .001
     self.enc_time_exp = .4
     self.prep_time = .150
     self.exec_time_base = .070
     self.exec_time_inc = .002
Ejemplo n.º 4
0
 def __init__(self, hands, vision):
     super().__init__("mouse", hands.agent)
     self.hands = hands
     self.vision = vision
     self.worker = hands.worker
     self.loc = Location(0, 0)
     self.move_fns = []
     self.click_fns = []
     self.init_time = .050
     self.burst_time = .050
     self.fitts_coeff = .100
     self.min_fitts_time = .100
Ejemplo n.º 5
0
 def __init__(self, agent, vision, env, pos=None):
     super().__init__('motor', agent)
     self.vision = vision
     self.display = env.display
     self.keyboard = env.keyboard
     self.mouse = env.mouse
     self.pos = pos or Motor.ON_KEYBOARD
     self.worker = Worker('motor', self)
     self.wpm(Motor.DEFAULT_TYPING_WPM)
     self.mouse_loc = Location(0, 0)
     self.mouse_init_time = .050
     self.mouse_burst_time = .050
     self.mouse_fitts_coeff = .100
     self.mouse_min_fitts_time = .100
Ejemplo n.º 6
0
 def __init__(self, agent, display, eyes=None):
     super().__init__('vision', agent)
     self.display = display.set_vision(self)
     self.eyes = eyes
     if eyes is not None:
         eyes.set_vision(self)
     self.find_buffer = Buffer('vision.find', self)
     self.encode_buffer = Buffer('vision.encode', self)
     self.encode_loc = Location(0, 0)
     self.wait_for_query = None
     self.last_encode_cancel = None
     self.attend_fns = []
     self.encode_fns = []
     self.find_time = .000
     self.default_enc_time = .135
Ejemplo n.º 7
0
    def prepare(self, visual, enc_start, enc_dur):
        if self.last_prep_cancel is not None:
            self.last_prep_cancel.try_cancel()
        sd = .1 * \
            self.vision.display.degrees_to_pixels(
                self._compute_eccentricity(visual))
        new_loc = Location(visual.x + random.gauss(0, sd),
                           visual.y + random.gauss(0, sd))
        self.log('prepare {}'.format(new_loc))
        duration = self._rand_time(self.prep_time)

        def fn():
            self.move(visual, new_loc, enc_start, enc_dur)

        self.last_prep_cancel = self.run_thread_can_cancel(fn, duration)
Ejemplo n.º 8
0
 def __init__(self, agent, eyes=None, display=Display()):
     super().__init__("vision", agent)
     self.display = display
     self.eyes = eyes
     if eyes is not None:
         eyes.set_vision(self)
     self.visuals = {}
     self.find_buffer = Buffer("vision.find", self)
     self.encode_buffer = Buffer("vision.encode", self)
     self.encode_loc = Location(0, 0)
     self.wait_for_query = None
     self.last_encode_cancel = None
     self.attend_fns = []
     self.encode_fns = []
     self.find_time = .000
     self.default_enc_time = .135
Ejemplo n.º 9
0
 def move_to(self, x, y):
     self.loc = Location(x, y)