Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add valhalla's time options #1

Open
wants to merge 19 commits into
base: departure-arrival-time
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
cache: pip

- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Install dependencies
run: |
pip install -r requirements_dev.txt

- name: style & lint checks
run: |
pre-commit run --all-files
pre-commit run --all-files --color=always

- name: pytest and coverage
run: |
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.9.1
hooks:
- id: black
language_version: python3
# temp exlude osrm: black fails to reformat for some reason
args: [routingpy, tests, --exclude, routingpy/routers/mapbox_osrm.py]
- repo: https://github.com/pycqa/flake8
rev: 5.0.4 # pick a git hash / tag to point to
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.290
hooks:
- id: flake8
- id: ruff
- repo: https://github.com/pycqa/isort
rev: 5.11.5
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## **Unreleased**

### Fixed

- Fixes taking into account the `preference` parameter when calculating isochrones and matrix with Valhalla ([#120](https://github.com/gis-ops/routingpy/issues/120))
- Google's matrix checks each response element's status code [#122](https://github.com/gis-ops/routingpy/pull/122)

## [v1.3.0](https://pypi.org/project/routingpy/1.3.0/)

### Added
Expand Down
81 changes: 77 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ matplotlib = {version = "^3.4.1", optional = true}
contextily = {version = "^1.1.0", optional = true}
geopandas = {version = "^0.8.2", optional = true}
descartes = {version = "^1.0.0", optional = true}
pytz = "^2023.3"
timezonefinder = "^6.2.0"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for valhalla, which (unfortunately) doesn't return a tz aware date_time string


[tool.poetry.extras]
notebooks = ["shapely", "ipykernel", "geopandas", "contextily", "matplotlib", "descartes"]
Expand Down Expand Up @@ -66,3 +68,44 @@ skip = [
"build",
"dist",
]

[tool.ruff]
# Enable the pycodestyle (`E`) and Pyflakes (`F`) rules by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E", "F"]
ignore = ["E203", "E266", "E501", "F403", "E722", "F405"]

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"__pycache__",
"docs",
"examples",
]
per-file-ignores = {}

line-length = 105

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
certifi==2023.7.22 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
cffi==1.15.1 ; python_version >= "3.8" and python_version < "4"
charset-normalizer==3.2.0 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
h3==3.7.6 ; python_version >= "3.8" and python_version < "4"
idna==3.4 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
numpy==1.24.4 ; python_version >= "3.8" and python_version < "4"
pycparser==2.21 ; python_version >= "3.8" and python_version < "4"
pytz==2023.3 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
requests==2.31.0 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
setuptools==68.0.0 ; python_version >= "3.8" and python_version < "4"
timezonefinder==6.2.0 ; python_version >= "3.8" and python_version < "4"
urllib3==2.0.4 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pluggy==1.2.0 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
pre-commit==2.21.0 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
pygments==2.15.1 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
pytest==7.4.0 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
pytz==2023.3 ; python_full_version >= "3.8.0" and python_version < "3.9"
pytz==2023.3 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
pyyaml==6.0.1 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
requests==2.31.0 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
responses==0.10.16 ; python_full_version >= "3.8.0" and python_full_version < "4.0.0"
Expand Down
23 changes: 23 additions & 0 deletions routingpy/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"""
import datetime

import pytz
from timezonefinder import TimezoneFinder

_TZ_FINDER = TimezoneFinder()


def delimit_list(arg, delimiter=","):
"""Convert list to delimiter-separated string"""
Expand Down Expand Up @@ -108,3 +113,21 @@ def seconds_to_iso8601(seconds):
iso8601_duration += f"{seconds}S"

return iso8601_duration


def timestamp_to_tz_datetime(timestamp: int, timezone: str) -> datetime.datetime:
khamaileon marked this conversation as resolved.
Show resolved Hide resolved
"""
Converts a UTC timestamp (in seconds) and timezone string to a timezone aware
datetime.datetime object

:param timestamp: The UTC timestamp, i.e. UNIX epoch in seconds.
:param timezone: The timezone string, e.g. 'US/Eastern' or 'Europe/Berlin'
:returns: the timezone aware datetime object
"""
dt = datetime.datetime.fromtimestamp(timestamp)
timezone = pytz.timezone(timezone)
return dt.astimezone(timezone)


def lonlat_to_timezone(lon: float, lat: float) -> str:
return _TZ_FINDER.timezone_at(lng=lon, lat=lat)
39 changes: 38 additions & 1 deletion routingpy/direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""
:class:`.Direction` returns directions results.
"""
import datetime
from typing import List, Optional


Expand Down Expand Up @@ -65,7 +66,15 @@ class Direction(object):
Contains a parsed directions' response. Access via properties ``geometry``, ``duration`` and ``distance``.
"""

def __init__(self, geometry=None, duration=None, distance=None, raw=None):
def __init__(
self,
geometry: List[List[float]] = None,
duration: int = None,
distance: int = None,
departure_datetime: datetime.datetime = None,
arrival_datetime: datetime.datetime = None,
raw: dict = None,
):
"""
Initialize a :class:`Direction` object to hold the properties of a directions request.

Expand All @@ -78,13 +87,21 @@ def __init__(self, geometry=None, duration=None, distance=None, raw=None):
:param distance: The distance of the direction in meters.
:type distance: int

:param departure_datetime: The departure date and time (timezone aware) of the direction.
:type departure_datetime: datetime.datetime

:param arrival_datetime: The arrival date and time (timezone aware) of the direction.
:type arrival_datetime: datetime.datetime

:param raw: The raw response of an individual direction (for multiple alternative routes) or the whole direction
response.
:type raw: dict
"""
self._geometry = geometry
self._duration = duration
self._distance = distance
self._departure_datetime = departure_datetime
self._arrival_datetime = arrival_datetime
self._raw = raw

@property
Expand Down Expand Up @@ -114,6 +131,26 @@ def distance(self) -> int:
"""
return self._distance

@property
def departure_datetime(self) -> Optional[datetime.datetime]:
"""
The departure date and time of the direction. Only timezone aware
for the Google provider for now.

:rtype: datetime.datetime or None
"""
return self._departure_datetime

@property
def arrival_datetime(self) -> Optional[datetime.datetime]:
"""
The arrival date and time of the direction. Only timezone aware
for the Google provider for now.

:rtype: datetime.datetime or None
"""
return self._arrival_datetime

@property
def raw(self) -> Optional[dict]:
"""
Expand Down
Loading