def FaceRecognitionFactory():
    """ Generates a 'upgrade-face-samples' message which will be processed by
    UpgradeFaceSamples PDU.

    Example:
    {
    'head_image': {
                   'image': 'AAAAA',
                   'width':640,
                   'height': 480,
                   },
    'session_id': 'daq-04_1_0123456789ABCDEF',
    'created_at': 1366974699,
    }
    """
    user_id = 1
    sensor_type = choice(SENSOR_TYPES)
    session_id = "{sensor_id}_{user_id}_{hash}".format(sensor_id=choice(SENSOR_IDS[sensor_type]),
                                                       user_id=user_id,
                                                       hash=utils.get_random_hash(16))

    return {'head_image': {
                           'image': utils.get_random_image(IMAGE_WIDTH / 10,
                                                           IMAGE_HEIGHT / 10),
                           'width': IMAGE_WIDTH / 10,
                           'height': IMAGE_HEIGHT / 10},
            'session_id': session_id,
            'created_at': int(time.time())}
Beispiel #2
0
    def test_routes_to_experiments(self, active_experiments_mock, send_to_mock):
        """Assert that a message is forwarded 'recorder' if Router receives a
        message when there are active experiments going on.
        """
        router = Router()
        messages = [RouterFactory('image_rgb') for _ in range(3)]
        active_experiments_mock.return_value = messages

        for m in messages:
            m.update({'id': utils.get_random_hash(1)})
            router.process_message(m)

        for m in messages:
            send_to_mock.assert_any_call(Matcher('recorder', lambda o: o),
                                         Matcher(m['id'], lambda o: o['id']))
Beispiel #3
0
def RouterFactory(message_type):
    """ Generates a 'measurements' message which can be processed by Router PDU.

    Example:
    {
        'context': 'default',       // context's name - used by Mr. Vladutu for
                                    // e.g. "standing_down", etc.
        'sensor_type': 'kinect',    // can also be 'arduino', 'sony360ptz'
        'sensor_id': '23',          // unique id of device -hardcoded currently
                                    // (will be command param)
        'sensor_position': {
            'x': 23, 'y': 42, 'z': 87
        },
        'type': {'skeleton'}        // can also be: 'image_depth', 'image_rgb'
        'image_rgb': {              // base64-encoded array of 3*width*height bytes
            'image': 'AAAA',
            'width': 640,
            'height': 480
        },
        'image_depth': {            // base64-encoded array of 3*width*height bytes
            'image': 'BBBB',
            'width': 640,
            'height': 480
        },
        'skeleton_2D': {            // JSON with skeleton coordinates. Kinect-specific field
            'head': { 'x': 23, 'y': 42 },
            'neck': { 'x': 27, 'y': 55  },
            ...
        },
        'skeleton_3D': {            // JSON with skeleton coordinates. Kinect-specific field
            'head': { 'x': 23, 'y': 42, 'z': 87 },
            'neck': { 'x': 27, 'y': 55, 'z': 87 },
            ...
    }
    """
    sensor_type = choice(SENSOR_TYPES)
    sensor_id = choice(SENSOR_IDS[sensor_type])

    user_id = 1
    session_id = "{sensor_id}_{user_id}_{hash}".format(sensor_id=sensor_id,
                                                       user_id=user_id,
                                                       hash=utils.get_random_hash(16))

    created_at = int(time.time())
    inserted_at = int(time.time())

    context = "default"

    router_message = {'sensor_id': sensor_id,
                      'sensor_type': sensor_type,
                      'session_id': session_id,
                      'inserted_at': inserted_at,
                      'created_at': created_at,
                      'type': message_type,
                      'context': context,
                      'sensor_position': utils.get_random_sensor_position()
                      }

    if message_type == 'image_rgb':
        router_message.update({'image_rgb': {'image': utils.get_random_image(IMAGE_WIDTH, IMAGE_HEIGHT),
                                             'width': IMAGE_WIDTH,
                                             'height': IMAGE_HEIGHT}})
    elif message_type == 'skeleton':
        router_message.update({'skeleton_2D': utils.get_random_2D_skeleton(),
                               'skeleton_3D': utils.get_random_3D_skeleton()})

    return router_message