コード例 #1
0
def get_score_from_city_name_metric(metric: city_scorer.SuggestionMetric,
                                    city_name: str, partial_name: str):
    city_infos = provider_interface.CityInfos(city_name, [],
                                              IRRELEVANT_CITY_COORDINATES,
                                              IRRELEVANT_POPULATION)
    query = service.CitySuggestionsQuery(partial_name=partial_name)

    return metric.compute_score(city_infos, query)
コード例 #2
0
def test_simple_query():
    app = main_factory.create_application()
    query = service.CitySuggestionsQuery(
        partial_name="Québec",
        latitude=-71.21454,
        longitude=46.81228,
    )
    suggestions_dto = app.get_suggestions(query)
    assert any(suggestion.name == "Québec" for suggestion in suggestions_dto.suggestions)
コード例 #3
0
def get_score_from_population_metric(metric: city_scorer.SuggestionMetric,
                                     city_population: int):
    city_infos = provider_interface.CityInfos(
        IRRELEVANT_CITY_NAME,
        [],
        IRRELEVANT_CITY_COORDINATES,
        city_population,
    )
    query = service.CitySuggestionsQuery(partial_name=IRRELEVANT_CITY_NAME, )

    return metric.compute_score(city_infos, query)
コード例 #4
0
    def suggestions():

        input_query = request.args.get(QUERY_PARAMETER, "")

        try:
            longitude = convert_to_float_if_exists(request.args.get(LONGITUDE_PARAMETER, None))
            latitude = convert_to_float_if_exists(request.args.get(LATITUDE_PARAMETER, None))
        except ValueError:
            return abort(HTTPStatus.BAD_REQUEST)

        query = service.CitySuggestionsQuery(partial_name=input_query, longitude=longitude, latitude=latitude)
        city_suggestions_response = city_suggestions.get_suggestions(query)
        response_dict = convert_city_suggestions_response_to_dict(city_suggestions_response)

        return pretty_jsonify(response_dict)
コード例 #5
0
def get_score_from_coordinates_metric(metric: city_scorer.SuggestionMetric,
                                      city_coordinates_tuple: Tuple,
                                      query_coordinate_tuple: Tuple):
    city_coordinates = provider_interface.CityCoordinates(
        *city_coordinates_tuple)
    city_infos = provider_interface.CityInfos(IRRELEVANT_CITY_NAME, [],
                                              city_coordinates,
                                              IRRELEVANT_POPULATION)
    query = service.CitySuggestionsQuery(
        partial_name=IRRELEVANT_CITY_NAME,
        latitude=query_coordinate_tuple[0],
        longitude=query_coordinate_tuple[1],
    )

    return metric.compute_score(city_infos, query)
コード例 #6
0
def construct_query_from_dict(query_dict):
    return service.CitySuggestionsQuery(
        partial_name=query_dict.get('q'),
        longitude=query_dict.get("longitude", None),
        latitude=query_dict.get("latitude", None),
    )