How to use the ai2thor.server.Event function in ai2thor

To help you get started, we’ve selected a few ai2thor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github allenai / ai2thor / tests / test_controller.py View on Github external
def test_failure():
    fake_event = Event(dict(screenWidth=300, screenHeight=300, colors=[], lastActionSuccess=False, errorCode='NotOpen'))
    c = ai2thor.controller.Controller()
    c.last_event = fake_event
    action1 = dict(action='MoveAhead')
    c.request_queue = FakeQueue()
    c.request_queue.put_nowait(fake_event)
    e = c.step(action1)
    assert c.last_action == action1
    assert not e.metadata['lastActionSuccess']
github allenai / ai2thor / tests / test_controller.py View on Github external
def test_last_action():
    fake_event = Event(dict(screenWidth=300, screenHeight=300, colors=[], lastActionSuccess=True))
    c = ai2thor.controller.Controller()
    c.last_event = fake_event
    action1 = dict(action='RotateRight')
    c.request_queue = FakeQueue()
    c.request_queue.put_nowait(fake_event)
    e = c.step(action1)
    assert c.last_action == action1
    assert e.metadata['lastActionSuccess']

    c = ai2thor.controller.Controller()
    c.last_event = fake_event
    action2 = dict(action='RotateLeft')
    c.request_queue = FakeQueue()
    c.request_queue.put_nowait(fake_event)
    e = c.step(action2)
    assert c.last_action == action2
github allenai / ai2thor / tests / test_controller.py View on Github external
def test_raise_for_failure():
    fake_event = Event(dict(screenWidth=300, screenHeight=300, colors=[], lastActionSuccess=False, errorCode='NotOpen'))
    c = ai2thor.controller.Controller()
    c.last_event = fake_event
    action1 = dict(action='MoveAhead')
    c.request_queue = FakeQueue()
    c.request_queue.put_nowait(fake_event)

    with pytest.raises(AssertionError):
        c.step(action1, raise_for_failure=True)
github allenai / ai2thor / tests / test_controller.py View on Github external
def test_fix_visibility_distance_env():
    os.environ['AI2THOR_VISIBILITY_DISTANCE'] = '2.0'
    fake_event = Event(dict(screenWidth=300, screenHeight=300, colors=[], lastActionSuccess=True))
    c = ai2thor.controller.Controller()
    c.last_event = fake_event
    action1 = dict(action='Initialize', gridSize=0.25)
    c.request_queue = FakeQueue()
    c.request_queue.put_nowait(fake_event)
    c.step(action1)
    filtered_action = c.response_queue.get()
    print(filtered_action)
    assert filtered_action == {'action': 'Initialize', 'gridSize': 0.25, 'visibilityDistance':2.0}
    del(os.environ['AI2THOR_VISIBILITY_DISTANCE'])
github allenai / ai2thor / tests / test_controller.py View on Github external
def test_invalid_action():
    fake_event = Event(dict(screenWidth=300, screenHeight=300, colors=[], lastActionSuccess=False, errorCode='InvalidAction', errorMessage='Invalid method: moveaheadbadmethod'))
    c = ai2thor.controller.Controller()
    c.last_event = fake_event
    action1 = dict(action='MoveaheadbadMethod')
    c.request_queue = FakeQueue()
    c.request_queue.put_nowait(fake_event)

    with pytest.raises(ValueError) as excinfo:
        c.step(action1, raise_for_failure=True)
    assert excinfo.value.args == ('Invalid method: moveaheadbadmethod',)
github allenai / ai2thor / tests / test_event.py View on Github external
def event_complex():
    return Event(metadata_complex)
github allenai / ai2thor / tests / test_event.py View on Github external
def event():
    return Event(metadata_simple)
github allenai / ai2thor / ai2thor / server.py View on Github external
abort(403)

            if self.frame_counter % self.debug_frames_per_interval == 0:
                now = time.time()
                # rate = self.debug_frames_per_interval / float(now - self.last_rate_timestamp)
                self.last_rate_timestamp = now
                # import datetime
                # print("%s %s/s" % (datetime.datetime.now().isoformat(), rate))

            if metadata['sequenceId'] != self.sequence_id:
                raise ValueError("Sequence id mismatch: %s vs %s" % (
                    metadata['sequenceId'], self.sequence_id))

            events = []
            for i, a in enumerate(metadata['agents']):
                e = Event(a)
                image_mapping = dict(
                    image=e.add_image,
                    image_depth=e.add_image_depth,
                    image_ids=e.add_image_ids,
                    image_classes=e.add_image_classes,
                    image_normals=e.add_image_normals,
                    image_flows=e.add_image_flows
                )

                for key in image_mapping.keys():
                    if key in form.files:
                        image_mapping[key](form.files[key][i])

                third_party_image_mapping = dict(
                    image=e.add_image,
                    image_thirdParty_depth=e.add_third_party_image_depth,
github allenai / ai2thor / ai2thor / robot_controller.py View on Github external
action["renderImage"] = False

        action['sequenceId'] = self.sequence_id
        action['agentId'] = self.agent_id

        self.last_action = action

        rotation = action.get('rotation')
        if rotation is not None and type(rotation) != dict:
            action['rotation'] = {}
            action['rotation']['y'] = rotation

        payload = self._post_event('step', action)
        events = []
        for i, agent_metadata in enumerate(payload['metadata']['agents']):
            event = Event(agent_metadata)
            image_mapping = dict(
                image=lambda x: event.add_image(x, flip_y=False),
                image_depth=lambda x: event.add_image_depth_meters(
                    x, flip_y=False, dtype=np.float64
                )
            )
            for key in image_mapping.keys():
                if key in payload and len(payload[key]) > i:
                    image_mapping[key](payload[key][i])
            events.append(event)

        if len(events) > 1:
            self.last_event = MultiAgentEvent(self.agent_id, events)
        else:
            self.last_event = events[0]