def test_search_by_geo_box_and_annotated_name_and_predicted_name(channel):
    stub = service_pb2_grpc.V2Stub(channel)

    with SetupImage(stub) as input_:
        my_concept_name = input_.data.concepts[0].name
        response = stub.PostSearches(
            service_pb2.PostSearchesRequest(
                query=resources_pb2.Query(ands=[
                    resources_pb2.And(input=resources_pb2.Input(
                        data=resources_pb2.Data(geo=resources_pb2.Geo(geo_box=[
                            resources_pb2.GeoBoxedPoint(
                                geo_point=resources_pb2.GeoPoint(longitude=43,
                                                                 latitude=54)),
                            resources_pb2.GeoBoxedPoint(
                                geo_point=resources_pb2.GeoPoint(longitude=45,
                                                                 latitude=56)),
                        ])))),
                    resources_pb2.And(input=resources_pb2.Input(
                        data=resources_pb2.Data(concepts=[
                            resources_pb2.Concept(name=my_concept_name,
                                                  value=1)
                        ]))),
                    resources_pb2.And(output=resources_pb2.Output(
                        data=resources_pb2.Data(concepts=[
                            resources_pb2.Concept(name="dog", value=1)
                        ]))),
                ]),
                pagination=service_pb2.Pagination(page=1, per_page=1000),
            ),
            metadata=metadata(),
        )
        raise_on_failure(response)
        assert len(response.hits) > 0
        assert input_.id in [hit.input.id for hit in response.hits]
def test_search_by_image_url_and_geo_box(channel):
    stub = service_pb2_grpc.V2Stub(channel)

    with SetupImage(stub) as input_:
        response = stub.PostSearches(
            service_pb2.PostSearchesRequest(
                query=resources_pb2.Query(ands=[
                    resources_pb2.And(output=resources_pb2.Output(
                        input=resources_pb2.Input(data=resources_pb2.Data(
                            image=resources_pb2.Image(url=DOG_IMAGE_URL))))),
                    resources_pb2.And(input=resources_pb2.Input(
                        data=resources_pb2.Data(geo=resources_pb2.Geo(geo_box=[
                            resources_pb2.GeoBoxedPoint(
                                geo_point=resources_pb2.GeoPoint(longitude=43,
                                                                 latitude=54)),
                            resources_pb2.GeoBoxedPoint(
                                geo_point=resources_pb2.GeoPoint(longitude=45,
                                                                 latitude=56)),
                        ])))),
                ]),
                pagination=service_pb2.Pagination(page=1, per_page=1000),
            ),
            metadata=metadata(),
        )
        raise_on_failure(response)
        assert len(response.hits) > 0
        assert input_.id in [hit.input.id for hit in response.hits]
def test_search_by_image_url_and_geo_box(channel):
    stub = service_pb2_grpc.V2Stub(channel)

    with SetupImage(stub) as input_:
        response = stub.PostInputsSearches(
            PostInputsSearchesRequest(
                searches=[
                    Search(query=Query(ranks=[
                        Rank(annotation=Annotation(data=Data(image=Image(
                            url=DOG_IMAGE_URL)))),
                        Rank(annotation=Annotation(data=Data(
                            geo=resources_pb2.Geo(geo_box=[
                                resources_pb2.GeoBoxedPoint(
                                    geo_point=resources_pb2.GeoPoint(
                                        longitude=43, latitude=54)),
                                resources_pb2.GeoBoxedPoint(
                                    geo_point=resources_pb2.GeoPoint(
                                        longitude=45, latitude=56)),
                            ])))),
                    ]))
                ],
                pagination=service_pb2.Pagination(page=1, per_page=1000),
            ),
            metadata=metadata(),
        )
        raise_on_failure(response)
        assert len(response.hits) >= 1
        assert input_.id in [hit.input.id for hit in response.hits]
Example #4
0
    def __enter__(self) -> resources_pb2.Input:
        my_concept_id = "my-concept-id-" + uuid.uuid4().hex
        my_concept_name = "my concept name " + uuid.uuid4().hex

        image_metadata = struct_pb2.Struct()
        image_metadata.update({
            "some-key": "some-value",
            "another-key": {
                "inner-key": "inner-value"
            }
        })

        post_response = self._stub.PostInputs(
            service_pb2.PostInputsRequest(inputs=[
                resources_pb2.Input(data=resources_pb2.Data(
                    image=resources_pb2.Image(url=DOG_IMAGE_URL,
                                              allow_duplicate_url=True),
                    concepts=[
                        resources_pb2.Concept(
                            id=my_concept_id, name=my_concept_name, value=1)
                    ],
                    metadata=image_metadata,
                    geo=resources_pb2.Geo(geo_point=resources_pb2.GeoPoint(
                        longitude=44, latitude=55)),
                ), )
            ]),
            metadata=metadata(),
        )
        raise_on_failure(post_response)
        self._input = post_response.inputs[0]

        wait_for_inputs_upload(self._stub, metadata(), [self._input.id])

        return self._input
def test_search_by_geo_point_and_limit(channel):
    stub = service_pb2_grpc.V2Stub(channel)

    with SetupImage(stub) as input_:
        response = stub.PostSearches(
            service_pb2.PostSearchesRequest(
                query=resources_pb2.Query(ands=[
                    resources_pb2.And(input=resources_pb2.Input(
                        data=resources_pb2.Data(geo=resources_pb2.Geo(
                            geo_point=resources_pb2.GeoPoint(longitude=43,
                                                             latitude=56),
                            geo_limit=resources_pb2.GeoLimit(
                                value=1000, type="withinKilometers"),
                        ))))
                ]),
                pagination=service_pb2.Pagination(page=1, per_page=1000),
            ),
            metadata=metadata(),
        )
        raise_on_failure(response)
        assert len(response.hits) > 0
        assert input_.id in [hit.input.id for hit in response.hits]
Example #6
0
def test_post_patch_get_image_with_id_concepts_geo_and_metadata(channel):
    stub = service_pb2_grpc.V2Stub(channel)

    input_id = uuid.uuid4().hex

    input_metadata = Struct()
    input_metadata.update({
        "key1": 123,
        "key2": {
            "inner-key1": "inner-val1",
            "inner-key2": "inner-val2",
        },
    })

    post_response = stub.PostInputs(
        service_pb2.PostInputsRequest(inputs=[
            resources_pb2.Input(
                id=input_id,
                data=resources_pb2.Data(
                    image=resources_pb2.Image(url=TRUCK_IMAGE_URL,
                                              allow_duplicate_url=True),
                    concepts=[
                        resources_pb2.Concept(id="some-positive-concept",
                                              value=1),
                        resources_pb2.Concept(id="some-negative-concept",
                                              value=0),
                    ],
                    geo=resources_pb2.Geo(geo_point=resources_pb2.GeoPoint(
                        longitude=55.0, latitude=66), ),
                    metadata=input_metadata,
                ),
            )
        ]),
        metadata=metadata(),
    )
    raise_on_failure(post_response)

    wait_for_inputs_upload(stub, metadata(), [input_id])

    get_response = stub.GetInput(
        service_pb2.GetInputRequest(input_id=input_id), metadata=metadata())
    raise_on_failure(get_response)

    inp = get_response.input
    assert inp.id == input_id
    assert inp.data.concepts[0].id == "some-positive-concept"
    assert inp.data.concepts[0].value == 1.0
    assert inp.data.concepts[1].id == "some-negative-concept"
    assert inp.data.concepts[1].value == 0.0
    assert inp.data.metadata["key1"] == 123
    assert inp.data.metadata["key2"]["inner-key1"] == "inner-val1"
    assert inp.data.metadata["key2"]["inner-key2"] == "inner-val2"
    assert inp.data.geo.geo_point.longitude == 55.0
    assert inp.data.geo.geo_point.latitude == 66.0

    new_metadata = Struct()
    new_metadata.update({"new-key": "new-value"})
    patch_response = stub.PatchInputs(
        service_pb2.PatchInputsRequest(
            action="merge",
            inputs=[
                resources_pb2.Input(
                    id=input_id,
                    data=resources_pb2.Data(
                        concepts=[
                            resources_pb2.Concept(
                                id="another-positive-concept", value=1)
                        ],
                        geo=resources_pb2.Geo(geo_point=resources_pb2.GeoPoint(
                            longitude=77.0, latitude=88.0)),
                        metadata=new_metadata,
                    ),
                )
            ],
        ),
        metadata=metadata(),
    )
    raise_on_failure(patch_response)
    inp = patch_response.inputs[0]
    assert inp.data.concepts[2].id == "another-positive-concept"
    assert inp.data.geo.geo_point.longitude == 77.0
    assert inp.data.geo.geo_point.latitude == 88.0
    assert inp.data.metadata["new-key"] == "new-value"
    assert (inp.data.metadata["key1"] == 123
            )  # Since we use the merge action, the old values should remain

    delete_response = stub.DeleteInputs(
        service_pb2.DeleteInputsRequest(ids=[input_id]), metadata=metadata())
    raise_on_failure(delete_response)