Skip to content

Commit b936a7b

Browse files
committed
feat: Create sample for routeoptimization
1 parent 5829629 commit b936a7b

File tree

8 files changed

+158
-0
lines changed

8 files changed

+158
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
/video/live-stream/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
9090
/video/stitcher/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
9191
/translate @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-ml-translate-dev
92+
/routeoptimization/**/* @GoogleCloudPlatform/geo-routeoptimization @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
9293

9394
# BEGIN - pending clarification
9495
/memorystore/**/* @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers

.github/blunderbuss.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ assign_prs_by:
258258
- "api: dataplex"
259259
to:
260260
- GoogleCloudPlatform/googleapi-dataplex
261+
- labels:
262+
- "api: routeoptimization"
263+
to:
264+
- GoogleCloudPlatform/geo-routeoptimization
261265
# Self-service individuals
262266
- labels:
263267
- "api: auth"

routeoptimization/snippets/README.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Google Maps Platform: Route Optimization API Examples
2+
3+
## Prerequisites to run locally:
4+
5+
* [pip](https://pypi.python.org/pypi/pip)
6+
7+
Go to the [Google Cloud Console](https://console.cloud.google.com).
8+
9+
Under API Manager, search for the Route Optimization API and enable it.
10+
11+
## Set Up Your Local Dev Environment
12+
13+
To install, run the following commands. If you want to use [virtualenv](https://virtualenv.readthedocs.org/en/latest/)
14+
(recommended), run the commands within a virtualenv.
15+
16+
* pip install -r requirements.txt
17+
18+
## Authentication
19+
20+
Please see the [Google cloud authentication guide](https://cloud.google.com/docs/authentication/).
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Default TEST_CONFIG_OVERRIDE for python repos.
16+
17+
# You can copy this file into your directory, then it will be imported from
18+
# the noxfile.py.
19+
20+
# The source of truth:
21+
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
22+
23+
TEST_CONFIG_OVERRIDE = {
24+
# You can opt out from the test for specific Python versions.
25+
"ignored_versions": ["2.7", "3.7"],
26+
# Old samples are opted out of enforcing Python type hints
27+
# All new samples should feature them
28+
"enforce_type_hints": True,
29+
# An envvar key for determining the project id to use. Change it
30+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
31+
# build specific Cloud project. You can also use your own string
32+
# to use your own Cloud project.
33+
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
34+
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
35+
# If you need to use a specific version of pip,
36+
# change pip_version_override to the string representation
37+
# of the version number, for example, "20.2.4"
38+
"pip_version_override": None,
39+
# A dictionary you want to inject into your test. Don't put any
40+
# secrets here. These values will override predefined values.
41+
"envs": {},
42+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START routeoptimization_optimize_tours_basic]
16+
17+
from google.maps import routeoptimization_v1
18+
19+
20+
def call_optimize_tours(project_id: str) -> routeoptimization_v1.OptimizeToursResponse:
21+
# Use Default Application Credentials for the environment.
22+
client = routeoptimization_v1.RouteOptimizationClient()
23+
24+
response = client.optimize_tours(
25+
request=routeoptimization_v1.OptimizeToursRequest(
26+
parent="projects/" + project_id,
27+
model={
28+
"shipments": [
29+
{
30+
"deliveries": [
31+
{
32+
"arrival_location": {
33+
"latitude": 48.880942,
34+
"longitude": 2.323866,
35+
}
36+
}
37+
]
38+
}
39+
],
40+
"vehicles": [
41+
{
42+
"end_location": {
43+
"latitude": 48.86311,
44+
"longitude": 2.341205,
45+
},
46+
"start_location": {
47+
"latitude": 48.863102,
48+
"longitude": 2.341204,
49+
},
50+
}
51+
],
52+
},
53+
)
54+
)
55+
56+
return response
57+
58+
59+
# [END routeoptimization_optimize_tours_basic]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.api_core.retry import Retry
16+
import google.auth
17+
18+
19+
import optimize_tours
20+
21+
22+
@Retry
23+
def test_call_sync_api() -> None:
24+
_, project_id = google.auth.default()
25+
got = optimize_tours.call_optimize_tours(project_id)
26+
27+
assert len(got.routes) > 0
28+
assert len(got.routes[0].visits) > 0
29+
assert got.metrics is not None
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest==8.2.0
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-maps-routeoptimization==0.1.2

0 commit comments

Comments
 (0)