Skip to content

Commit 4392de2

Browse files
committed
Formatting code, addressing readme test
1 parent 41eae6a commit 4392de2

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export TT_APP_ID="your_application_id_here"
2+
export TT_API_KEY="your_api_key_here"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pip3 install -r requirements.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cat input.json | python3 main.py

.nextmv/readme/workflow-configuration.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ apps:
105105
silent: true
106106
- name: 1.sh
107107
silent: true
108+
- name: python-nextroute-traveltime
109+
scripts:
110+
- name: 0.sh
111+
skip: true
112+
- name: 1.sh
113+
skip: true
114+
- name: 2.sh
115+
skip: true
108116
- name: python-ortools-costflow
109117
scripts:
110118
- name: 0.sh

python-nextroute-traveltime/main.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
from nextpipe import FlowSpec, app, needs, step
88
from traveltimepy import Client
9-
from traveltimepy.requests.common import Location, Coordinates, Property
9+
from traveltimepy.requests.common import Coordinates, Location, Property
1010
from traveltimepy.requests.time_filter_fast import TimeFilterFastArrivalSearches, TimeFilterFastOneToMany
1111
from traveltimepy.requests.transportation import TransportationFast
1212

@@ -43,12 +43,7 @@ def build_locations_list(nextroute_input):
4343

4444
# Add stops first
4545
for stop in nextroute_input.stops:
46-
locations.append(
47-
Location(
48-
id=stop.id,
49-
coords=Coordinates(lat=stop.location.lat, lng=stop.location.lon)
50-
)
51-
)
46+
locations.append(Location(id=stop.id, coords=Coordinates(lat=stop.location.lat, lng=stop.location.lon)))
5247

5348
# Add vehicle start/end locations for each vehicle
5449
for vehicle in nextroute_input.vehicles:
@@ -59,8 +54,8 @@ def build_locations_list(nextroute_input):
5954
id=start_id,
6055
coords=Coordinates(
6156
lat=nextroute_input.defaults.vehicles.start_location.lat,
62-
lng=nextroute_input.defaults.vehicles.start_location.lon
63-
)
57+
lng=nextroute_input.defaults.vehicles.start_location.lon,
58+
),
6459
)
6560
)
6661

@@ -71,8 +66,8 @@ def build_locations_list(nextroute_input):
7166
id=end_id,
7267
coords=Coordinates(
7368
lat=nextroute_input.defaults.vehicles.end_location.lat,
74-
lng=nextroute_input.defaults.vehicles.end_location.lon
75-
)
69+
lng=nextroute_input.defaults.vehicles.end_location.lon,
70+
),
7671
)
7772
)
7873

@@ -145,17 +140,14 @@ def sync_part(input_data: dict, client):
145140
arrival_location_ids=destinations,
146141
transportation=TransportationFast.DRIVING,
147142
travel_time=7200, # 2 hours maximum
148-
properties=[Property.TRAVEL_TIME, Property.DISTANCE]
143+
properties=[Property.TRAVEL_TIME, Property.DISTANCE],
149144
)
150145
)
151146

152147
# Execute the API call
153148
results = client.time_filter_fast(
154149
locations=locations,
155-
arrival_searches=TimeFilterFastArrivalSearches(
156-
one_to_many=one_to_many_searches,
157-
many_to_one=[]
158-
)
150+
arrival_searches=TimeFilterFastArrivalSearches(one_to_many=one_to_many_searches, many_to_one=[]),
159151
)
160152

161153
# Build travel matrices from API results
@@ -164,7 +156,7 @@ def sync_part(input_data: dict, client):
164156
return {
165157
"duration_matrix": duration_matrix.tolist(),
166158
"distance_matrix": distance_matrix.tolist(),
167-
"location_ids": location_ids # Include location IDs for reference
159+
"location_ids": location_ids, # Include location IDs for reference
168160
}
169161

170162

0 commit comments

Comments
 (0)