Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jain-aayush1123 committed Aug 10, 2021
1 parent d730d41 commit 40279ef
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
6 changes: 3 additions & 3 deletions here_location_services/config/isoline_routing_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ class OptimisedFor(Bunch):
)


class AvoidFeatures(Bunch):
class IsolineRoutingAvoidFeatures(Bunch):
"""A class to define constant values for features to avoid during isoline calculation."""


#: Use this config for avoid_features of isoline API.
#: Example: for ``tollRoad`` avoid_features use ``AVOID_FEATURES.tollRoad``.
AVOID_FEATURES = AvoidFeatures(
#: Example: for ``tollRoad`` avoid_features use ``ISOLINE_ROUTING_AVOID_FEATURES.tollRoad``.
ISOLINE_ROUTING_AVOID_FEATURES = IsolineRoutingAvoidFeatures(
**{
"tollRoad": "tollRoad",
"controlledAccessHighway": "controlledAccessHighway",
Expand Down
6 changes: 3 additions & 3 deletions here_location_services/isoline_routing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def get_isoline_routing(
"""
path = "v8/isolines"
url = f"{self._base_url}/{path}"
params: Dict[str, str] = {
params: Dict[str, Any] = {
"range[type]": range_type,
"range[values]": range,
"transportMode": transport_mode,
}
if origin:
params["origin"] = (",".join([str(i) for i in origin]),)
params["origin"] = ",".join([str(i) for i in origin])
if destination:
params["destination"] = (",".join([str(i) for i in destination]),)
params["destination"] = ",".join([str(i) for i in destination])
if arrival_time:
params["arrivalTime"] = arrival_time.isoformat(timespec="seconds")
if departure_time:
Expand Down
7 changes: 6 additions & 1 deletion here_location_services/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ class IsolineResponse(ApiResponse):

def __init__(self, **kwargs):
super().__init__()
self._filters = {"departure": None, "isolines": None, "notices": None}
self._filters = {
"departure": None,
"arrival": None,
"isolines": None,
"notices": None,
}
for param, default in self._filters.items():
setattr(self, param, kwargs.get(param, default))

Expand Down
47 changes: 45 additions & 2 deletions tests/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
WayPointOptions,
)
from here_location_services.config.isoline_routing_config import (
ISOLINE_ROUTING_AVOID_FEATURES,
ISOLINE_ROUTING_TRANSPORT_MODE,
RANGE_TYPE,
)
Expand Down Expand Up @@ -108,22 +109,64 @@ def test_ls_reverse_geocoding_exception():
def test_isonline_routing():
"""Test isonline routing api."""
ls = LS(api_key=LS_API_KEY)
place_options = PlaceOptions(
course=ROUTE_COURSE.west,
sideof_street_hint=[52.512149, 13.304076],
match_sideof_street=ROUTE_MATCH_SIDEOF_STREET.always,
radius=10,
min_course_distance=10,
)
assert json.loads(place_options.__str__()) == {
"course": 270,
"sideOfStreetHint": "52.512149,13.304076",
"matchSideOfStreet": "always",
"namehint": None,
"radius": 10,
"minCourseDistance": 10,
}
origin_waypoint_options = WayPointOptions(stop_duration=0)

result = ls.calculate_isoline(
origin=[52.5, 13.4],
range="3000",
range="1000,3000",
range_type=RANGE_TYPE.time,
transport_mode=ISOLINE_ROUTING_TRANSPORT_MODE.car,
departure_time=datetime.now(),
truck=Truck(
shipped_hazardous_goods=[SHIPPED_HAZARDOUS_GOODS.explosive],
gross_weight=100,
weight_per_axle=10,
height=10,
width=10,
length=10,
tunnel_category="B",
axle_count=4,
),
shape_max_points=100,
avoid_features=[ISOLINE_ROUTING_AVOID_FEATURES.tollRoad],
origin_place_options=place_options,
origin_waypoint_options=origin_waypoint_options,
)

assert result.isolines
assert result.departure
coordinates = result.isolines[0]["polygons"][0]["outer"]

assert coordinates
geo_json = result.to_geojson()
assert geo_json.type == "FeatureCollection"

destination_waypoint_options = WayPointOptions(stop_duration=0)
result2 = ls.calculate_isoline(
destination=[52.51578, 13.37749],
range="600",
range_type=RANGE_TYPE.time,
transport_mode=ISOLINE_ROUTING_TRANSPORT_MODE.car,
destination_place_options=place_options,
destination_waypoint_options=destination_waypoint_options,
)
assert result2.isolines
assert result2.arrival

with pytest.raises(ValueError):
ls.calculate_isoline(
destination=[82.8628, 135.00],
Expand Down

0 comments on commit 40279ef

Please sign in to comment.