Skip to content

Commit de31000

Browse files
authored
Merge pull request #27 from route4me/feature/orders_group
Feature/orders group
2 parents 38a1b16 + 21a13b1 commit de31000

22 files changed

+964
-568
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Route4Me_SDK.egg-info/
1212
.venv
1313
docs/html/*
1414
.tox
15+
.DS_Store

VERSION.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
# VERSION.py - MAINTAINER's. Don't edit, if you don't know what are you doing
77
# ==============================================================================
88

9-
VERSION = (0, 1, 5, 0)
10-
RELEASE_SUFFIX = ''
9+
VERSION = (0, 1, 6, 0)
10+
RELEASE_SUFFIX = ""
1111

12-
VERSION_STRING = '.'.join([str(x) for x in VERSION])
12+
VERSION_STRING = ".".join([str(x) for x in VERSION])
1313
RELEASE_STRING = "v{}{}".format(VERSION_STRING, RELEASE_SUFFIX)
1414

15-
PROJECT = 'Route4Me Python SDK'
16-
COPYRIGHT = '2016-2021 © Route4Me Python Team'
17-
AUTHOR = 'Route4Me Python Team (SDK)'
18-
AUTHOR_EMAIL = '[email protected]'
19-
TITLE = 'route4me'
20-
LICENSE = 'ISC'
21-
BUILD = None # TRAVIS_COMMIT
15+
PROJECT = "Route4Me Python SDK"
16+
COPYRIGHT = "2016-2021 © Route4Me Python Team"
17+
AUTHOR = "Route4Me Python Team (SDK)"
18+
AUTHOR_EMAIL = "[email protected]"
19+
TITLE = "route4me"
20+
LICENSE = "ISC"
21+
BUILD = None # TRAVIS_COMMIT
2222
COMMIT = None # TRAVIS_BUILD_NUMBER

examples/.DS_Store

-10 KB
Binary file not shown.
Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# Route4Me Java SDK
2-
3-
[![Build Status](https://travis-ci.org/route4me/route4me-java-sdk.svg?branch=master)](https://travis-ci.org/route4me/route4me-java-sdk)
4-
[![codebeat badge](https://codebeat.co/badges/088f1145-147e-438e-aa03-9fc5323ff235)](https://codebeat.co/projects/github-com-route4me-route4me-java-sdk)
5-
1+
# Route4Me Python SDK
62

73
## Examples Description:
84

@@ -16,7 +12,7 @@ TEST CASE: Some addresses without Tags
1612

1713
### AdvancedConstraints3
1814

19-
TEST CASE: Driver's Shift
15+
TEST CASE: Driver's Shift
2016

2117
### AdvancedConstraints4
2218

@@ -26,39 +22,39 @@ TEST CASE: Driver's Skills
2622

2723
TEST CASE: Drivers Schedules with Territories
2824

29-
- 10 Drivers
30-
- 3 Schedules
31-
- 3 Territories
25+
- 10 Drivers
26+
- 3 Schedules
27+
- 3 Territories
3228

3329
### AdvancedConstraints6
3430

3531
TEST CASE: Drivers Schedules with Territories
3632

37-
- 2000 stops
38-
- 30 Schedules
39-
- 3 Territories
33+
- 2000 stops
34+
- 30 Schedules
35+
- 3 Territories
4036

4137
### AdvancedConstraints7
4238

43-
TEST CASE: Drivers Schedules with Territories
39+
TEST CASE: Drivers Schedules with Territories
4440

45-
- 2000 stops
46-
- 30 Schedules
47-
- 5 Territories
41+
- 2000 stops
42+
- 30 Schedules
43+
- 5 Territories
4844

4945
### AdvancedConstraints8
5046

5147
TEST CASE: Drivers Schedules with Territories
5248

53-
- 2000 Stops
54-
- 50 Drivers
55-
- 50 Schedules
49+
- 2000 Stops
50+
- 50 Drivers
51+
- 50 Schedules
5652

5753
### AdvancedConstraints9
5854

5955
TEST CASE: Retail Location based of address position id
6056

61-
- Depots Section
57+
- Depots Section
6258

6359
### AdvancedConstraints10
6460

@@ -72,14 +68,14 @@ TEST CASE: Retail Location - setting the address in the advanced constraints
7268

7369
TEST CASE: Drivers Schedules with Territories and Retail Location
7470

75-
- 2000 Stops
76-
- 30 Schedules
77-
- 3 Territories
78-
- Retail Location
71+
- 2000 Stops
72+
- 30 Schedules
73+
- 3 Territories
74+
- Retail Location
7975

8076
### AdvancedConstraints13
8177

8278
TEST CASE: Drivers Schedules with Address from Territories created in Route4Me
8379

84-
- 3 Territories
85-
- 3 Schedules
80+
- 3 Territories
81+
- 3 Schedules

examples/order/create_order.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,35 @@ def main(api_key):
1212
order = route4me.order
1313
url = "http://www.bk.com/restaurants/ny/new-york/106-fulton-st-17871.html"
1414
data = {
15-
'address_1': '106 Fulton St, Farmingdale, NY 11735, USA',
16-
'cached_lat': 40.730730,
17-
'cached_lng': -73.459283,
18-
'address_alias': 'BK Restaurant #: 17871',
19-
'EXT_FIELD_phone': '(212) 566-5132',
20-
'day_scheduled_for_YYMMDD': '2016-07-01',
21-
'EXT_FIELD_custom_data': {
22-
'url': url
23-
}
15+
"address_1": "106 Fulton St, Farmingdale, NY 11735, USA",
16+
"cached_lat": 40.730730,
17+
"cached_lng": -73.459283,
18+
"address_alias": "BK Restaurant #: 17871",
19+
"EXT_FIELD_phone": "(212) 566-5132",
20+
"day_scheduled_for_YYMMDD": "2016-07-01",
21+
"EXT_FIELD_custom_data": {"url": url},
2422
}
2523
response = order.create_order(**data)
26-
if isinstance(response, dict) and 'errors' in response.keys():
27-
print('. '.join(response['errors']))
24+
if isinstance(response, dict) and "errors" in response.keys():
25+
print(". ".join(response["errors"]))
2826
else:
29-
print('Member ID:\t{0}'.format(response.get('member_id')))
30-
print('Order ID:\t{0}'.format(response.get('order_id')))
31-
print('Order Status ID:\t{0}'.format(response.get('order_status_id')))
32-
print('In Route Count:\t{0}'.format(response.get('in_route_count')))
33-
print('Day Added:\t{0}'.format(response.get('day_added_YYMMDD')))
34-
print('Is Pending:\t{0}'.format(response.get('is_pending')))
35-
print('Is Accepted:\t{0}'.format(response.get('is_accepted')))
36-
print('Is Started:\t{0}'.format(response.get('is_started')))
37-
print('Is Validated:\t{0}'.format(response.get('is_validated')))
38-
print('Is Completed:\t{0}'.format(response.get('is_completed')))
39-
40-
41-
if __name__ == '__main__':
42-
parser = argparse.ArgumentParser(description='Create an Order')
43-
parser.add_argument('--api_key', dest='api_key', help='Route4Me API KEY',
44-
type=str, required=True)
27+
print("Member ID:\t{0}".format(response.get("member_id")))
28+
print("Order ID:\t{0}".format(response.get("order_id")))
29+
print("Order Status ID:\t{0}".format(response.get("order_status_id")))
30+
print("In Route Count:\t{0}".format(response.get("in_route_count")))
31+
print("Day Added:\t{0}".format(response.get("day_added_YYMMDD")))
32+
print("Is Pending:\t{0}".format(response.get("is_pending")))
33+
print("Is Accepted:\t{0}".format(response.get("is_accepted")))
34+
print("Is Started:\t{0}".format(response.get("is_started")))
35+
print("Is Validated:\t{0}".format(response.get("is_validated")))
36+
print("Is Completed:\t{0}".format(response.get("is_completed")))
37+
38+
39+
if __name__ == "__main__":
40+
parser = argparse.ArgumentParser(description="Create an Order")
41+
parser.add_argument(
42+
"--api_key", dest="api_key", help="Route4Me API KEY", type=str, required=True
43+
)
4544
args = parser.parse_args()
4645
main(args.api_key)
4746

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# codebeat:disable[ABC]
3+
4+
import argparse
5+
6+
from route4me import Route4Me
7+
8+
9+
def main(api_key):
10+
r4m = Route4Me(api_key)
11+
orders_groups = r4m.orders_group
12+
13+
group_id = "ACE8FFFFFFFFFFFFFCCCCCCCCCCCCC"
14+
optimization_profile_id = "00000000-1111-1111-1111-000000000000"
15+
data = orders_groups.assign_optimization_profile(optimization_profile_id, group_id)
16+
print(data)
17+
18+
19+
if __name__ == "__main__":
20+
parser = argparse.ArgumentParser(description="Assign Optimization Profile")
21+
parser.add_argument(
22+
"--api_key", dest="api_key", help="Route4Me API KEY", type=str, required=True
23+
)
24+
args = parser.parse_args()
25+
main(args.api_key)
26+
27+
# codebeat:enable[ABC]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
# codebeat:disable[ABC]
3+
4+
import argparse
5+
6+
from route4me import Route4Me
7+
8+
9+
def main(api_key):
10+
r4m = Route4Me(api_key)
11+
optimization_profiles = r4m.optimization_profiles
12+
13+
print("\nGetting Optimization Profiles:\n")
14+
profiles = optimization_profiles.get_optimization_profiles()
15+
16+
for profile in profiles.get("items", []):
17+
print(
18+
" - ".join(
19+
[
20+
f"ID: {profile['optimization_profile_id']}",
21+
f"ProfileName: {profile['profile_name']}",
22+
f"isDefault: {profile['is_default']}",
23+
]
24+
)
25+
)
26+
27+
28+
if __name__ == "__main__":
29+
parser = argparse.ArgumentParser(description="Get Optimizations Profile")
30+
parser.add_argument(
31+
"--api_key", dest="api_key", help="Route4Me API KEY", type=str, required=True
32+
)
33+
args = parser.parse_args()
34+
main(args.api_key)
35+
36+
# codebeat:enable[ABC]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
# codebeat:disable[ABC]
3+
4+
import argparse
5+
6+
from route4me import Route4Me
7+
from route4me.constants import ORDER_STATUS
8+
9+
10+
def _print_groups(groups):
11+
for g in groups:
12+
print(
13+
" - ".join(
14+
[
15+
f"GroupID: {g['group_id']}",
16+
f"OptimizationProfileID: {g['optimization_profile_id']}",
17+
f" GroupColumn: {g['group_column']}",
18+
f"GroupValue: {g['group_value']}",
19+
f"OrdersCount: {g['orders_count']}",
20+
]
21+
)
22+
)
23+
24+
25+
def main(api_key):
26+
r4m = Route4Me(api_key)
27+
orders_groups = r4m.orders_group
28+
29+
scheduled_for_range = [
30+
"2024-06-01",
31+
"2024-06-10",
32+
]
33+
34+
statuses = [
35+
ORDER_STATUS.SCHEDULED,
36+
]
37+
print("\nGetting Orders Groups:\n")
38+
groups = orders_groups.get_orders_group(scheduled_for_range, statuses)
39+
_print_groups(groups)
40+
41+
42+
if __name__ == "__main__":
43+
parser = argparse.ArgumentParser(description="Get Orders Group")
44+
parser.add_argument(
45+
"--api_key", dest="api_key", help="Route4Me API KEY", type=str, required=True
46+
)
47+
args = parser.parse_args()
48+
main(args.api_key)
49+
50+
# codebeat:enable[ABC]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# -*- coding: utf-8 -*-
2+
# codebeat:disable[ABC]
3+
4+
import argparse
5+
6+
from route4me import Route4Me
7+
from route4me.constants import ORDER_STATUS
8+
9+
10+
def _print_groups(groups):
11+
for g in groups:
12+
print(
13+
" - ".join(
14+
[
15+
f"GroupID: {g['group_id']}",
16+
f"OptimizationProfileID: {g['optimization_profile_id']}",
17+
f" GroupColumn: {g['group_column']}",
18+
f"GroupValue: {g['group_value']}",
19+
f"OrdersCount: {g['orders_count']}",
20+
]
21+
)
22+
)
23+
24+
25+
def main(api_key):
26+
r4m = Route4Me(api_key)
27+
orders_groups = r4m.orders_group
28+
29+
scheduled_for_range = [
30+
"2024-06-01",
31+
"2024-06-10",
32+
]
33+
34+
statuses = [
35+
ORDER_STATUS.SCHEDULED,
36+
]
37+
print("\nGetting Orders Groups:\n")
38+
groups = orders_groups.get_orders_group(scheduled_for_range, statuses)
39+
selected_groups = []
40+
_print_groups(groups)
41+
for g in groups:
42+
if g["orders_count"] > 0:
43+
selected_groups.append(g)
44+
print("\nSelected Groups:\n")
45+
_print_groups(selected_groups)
46+
47+
if selected_groups:
48+
print("\nCreating Optimization with selected Groups:\n")
49+
optimization = r4m.optimization
50+
51+
aggregations_id = []
52+
aggregation_profile_overrides = {}
53+
for g in selected_groups:
54+
aggregations_id.append(g["group_id"])
55+
aggregation_profile_overrides.update(
56+
{g["group_id"]: g["optimization_profile_id"]}
57+
)
58+
optimization.set_order_aggregation_groups(
59+
scheduled_for_range,
60+
aggregations_id,
61+
statuses,
62+
aggregation_profile_overrides,
63+
)
64+
optimization.route_start_date_local("2024-06-10")
65+
66+
response = r4m.run_optimization()
67+
print("Optimization Link: {}".format(response["links"]["view"]))
68+
for i, route in enumerate(response["routes"]):
69+
print("\t{0}\tRoute Link: {1}".format(i + 1, route["links"]["route"]))
70+
for address in route["addresses"]:
71+
print("\t\t\tAddress: {0}".format(address["address"]))
72+
else:
73+
print("No matching orders found in the selected aggregations")
74+
75+
76+
if __name__ == "__main__":
77+
parser = argparse.ArgumentParser(description="Get Orders Group")
78+
parser.add_argument(
79+
"--api_key", dest="api_key", help="Route4Me API KEY", type=str, required=True
80+
)
81+
args = parser.parse_args()
82+
main(args.api_key)
83+
84+
# codebeat:enable[ABC]

0 commit comments

Comments
 (0)