Skip to content

Commit e241eaa

Browse files
Tool to compare travel times between TravelTime and Google APIs
0 parents  commit e241eaa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+18221
-0
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Unit Tests
5+
6+
on:
7+
push:
8+
branches: [master]
9+
pull_request: {}
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
max-parallel: 1
17+
matrix:
18+
python-version:
19+
- "3.8"
20+
- "3.9"
21+
- "3.10"
22+
- "3.11"
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
- name: Install Package with dependencies
30+
run: |
31+
pip install -e ".[test]"
32+
- name: Test with pytest
33+
run: |
34+
pytest

.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
.idea/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 TravelTime
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# TravelTime/Google comparison tool
2+
3+
This tool is designed to compare the travel times fetched from
4+
[Google Maps Directions API](https://developers.google.com/maps/documentation/directions/get-directions)
5+
and [TravelTime Routes API](https://docs.traveltime.com/api/reference/routes).
6+
7+
## Features
8+
9+
- Fetch travel times from Google Maps and TravelTime in parallel, for provided origin/destination pairs and a set
10+
of departure times.
11+
- Departure times are calculated based on user provided start time, end time and interval.
12+
- Analyze the differences between the results and print out the average error percentage.
13+
14+
## Prerequisites
15+
16+
The tool requires Python 3.8+ installed on your system. You can download it from [here](https://www.python.org/downloads/).
17+
18+
## Installation
19+
20+
Clone the repository:
21+
```bash
22+
git clone https://github.com/traveltime-dev/google-travel-time-comparison.git
23+
cd google-travel-time-comparison
24+
```
25+
26+
Create a new virtual environment with a chosen name (here, we'll name it venv):
27+
```bash
28+
python -m venv venv
29+
```
30+
31+
Activate the virtual environment:
32+
```bash
33+
source env/bin/activate
34+
```
35+
36+
Install the project and its dependencies:
37+
```bash
38+
pip install -e .
39+
```
40+
41+
## Setup
42+
Set up environment variables for the APIs.
43+
44+
For Google Maps API:
45+
46+
```bash
47+
export GOOGLE_API_KEY=[Your Google Maps API Key]
48+
```
49+
50+
For TravelTime API:
51+
```bash
52+
export TRAVELTIME_APP_ID=[Your TravelTime App ID]
53+
export TRAVELTIME_API_KEY=[Your TravelTime API Key]
54+
```
55+
56+
## Usage
57+
Run the tool:
58+
```bash
59+
traveltime_google_comparison --input [Input CSV file path] --output [Output CSV file path] \
60+
--date [Date (YYYY-MM-DD)] --start-time [Start time (HH:MM)] --end-time [End time (HH:MM)] \
61+
--interval [Interval in minutes] --time-zone-id [Time zone ID]
62+
```
63+
Required arguments:
64+
- `--input [Input CSV file path]`: Path to the input file. Input file is required to have a header row and at least one
65+
row with data, with two columns: `origin` and `destination`.
66+
The values in the columns must be latitude and longitude pairs, separated
67+
by comma and enclosed in double quotes. For example: `"51.5074,-0.1278"`. Columns must be separated by comma as well.
68+
Look at the `examples` directory for examples. You can find more pre-prepared routes in the `inputs` directory.
69+
- `--output [Output CSV file path]`: Path to the output file. It will contain the gathered travel times.
70+
See the details in the [Output section](#output)
71+
- `--date [Date (YYYY-MM-DD)]`: date on which the travel times are gathered. Use a future date, as Google API returns
72+
errors for past dates (and times). Take into account the time needed to collect the data for provided input.
73+
- `--start-time [Start time (HH:MM)]`: start time in `HH:MM` format, used for calculation of departure times.
74+
See [Calculating departure times](#calculating-departure-times)
75+
- `--end-time [End time (HH:MM)]`: end time in `HH:MM` format, used for calculation of departure times.
76+
See [Calculating departure times](#calculating-departure-times)
77+
- `--interval [Interval in minutes]`: interval in minutes, used for calculation of departure times.
78+
See [Calculating departure times](#calculating-departure-times)
79+
- `--time-zone-id [Time zone ID]`: non-abbreviated time zone identifier in which the time values are specified.
80+
For example: `Europe/London`. For more information, see [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
81+
82+
83+
84+
Optional arguments:
85+
- `--google-max-rpm [int]`: Set max number of parallel requests sent to Google API per minute. Default is 60.
86+
It is enforced on per-second basis, to avoid bursts.
87+
- `--traveltime-max-rpm [int]`: Set max number of parallel requests sent to TravelTime API per minute. Default is 60.
88+
It is enforced on per-second basis, to avoid bursts.
89+
90+
Example:
91+
92+
```bash
93+
traveltime_google_comparison --input examples/uk.csv --output output.csv --date 2023-09-20 \
94+
--start-time 07:00 --end-time 20:00 --interval 180 --time-zone-id "Europe/London"
95+
```
96+
97+
## Calculating departure times
98+
Script will collect travel times on the given day for departure times between provided start-time and end-time, with the
99+
given interval. The start-time and end-time are in principle inclusive, however if the time window is not exactly divisible by the
100+
given interval, the end-time will not be included. For example, if you set the start-time to 08:00, end-time to 20:00
101+
and interval to 240, the script will sample both APIs for departure times 08:00, 12:00, 16:00 and 20:00 (end-time
102+
included). But for interval equal to 300, the script will sample APIs for departure times 08:00, 13:00 and 18:00 (end-time
103+
is not included).
104+
105+
## Output
106+
The output file will contain the `origin` and `destination` columns from input file, with additional 4 columns:
107+
- `departure_time`: departure time in `YYYY-MM-DD HH:MM:SS±HHMM` format, calculated from the start-time, end-time and interval.
108+
It includes date, time and timezone offset.
109+
- `google_travel_time`: travel time gathered from Google Directions API in seconds
110+
- `tt_travel_time`: travel time gathered from TravelTime API in seconds
111+
- `error_percentage`: relative error between Google and TravelTime travel times in percent, relative to Google result.
112+
113+
### Sample output
114+
```csv
115+
origin,destination,departure_time,google_travel_time,tt_travel_time,error_percentage
116+
"52.1849867903527, 0.1809343829904072","52.202817030086266, 0.10935651695330152",2024-05-28 06:00:00+0100,718.0,1050.0,46
117+
"52.1849867903527, 0.1809343829904072","52.202817030086266, 0.10935651695330152",2024-05-28 09:00:00+0100,1427.0,1262.0,11
118+
"52.1849867903527, 0.1809343829904072","52.202817030086266, 0.10935651695330152",2024-05-28 12:00:00+0100,1064.0,1165.0,9
119+
"52.1849867903527, 0.1809343829904072","52.202817030086266, 0.10935651695330152",2024-05-28 15:00:00+0100,1240.0,1287.0,3
120+
"52.1849867903527, 0.1809343829904072","52.202817030086266, 0.10935651695330152",2024-05-28 18:00:00+0100,1312.0,1223.0,6
121+
"52.18553917820687, 0.12702050752253252","52.22715259892737, 0.14811674226050345",2024-05-28 06:00:00+0100,749.0,903.0,20
122+
```
123+
124+
## License
125+
This project is licensed under MIT License. For more details, see the LICENSE file.

examples/uk.csv

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
origin,destination
2+
"52.200400622501455, 0.1082577055247136","52.21614536733819, 0.15782831362961777"
3+
"52.19955457615636, 0.14441594364147523","52.21415066769657, 0.10114394769473968"
4+
"52.20500056589587, 0.10571539456157826","52.21029241660101, 0.14185873315312617"
5+
"52.22882726984348, 0.14728797368635727","52.19561323699487, 0.17099789436366608"
6+
"52.1849867903527, 0.1809343829904072","52.202817030086266, 0.10935651695330152"
7+
"52.18553917820687, 0.12702050752253252","52.22715259892737, 0.14811674226050345"
8+
"52.1911754037976, 0.14041445274919132","52.22566574308535, 0.11184453400134588"
9+
"52.20277048260601, 0.10858010326192653","52.18347963956372, 0.1534139650034901"
10+
"52.194893392655146, 0.10402490752892674","52.22669872510864, 0.14422440177424492"
11+
"52.188688628469045, 0.14011830341238343","52.22299210114997, 0.11999475596901812"
12+
"52.20974662536545, 0.10091635126109569","52.216306645483634, 0.16558508485276094"
13+
"52.18408238205764, 0.156369748250724","52.22441717665956, 0.12095393079204605"
14+
"52.21626218557039, 0.11096249374810913","52.17923545178305, 0.13583723313588303"
15+
"52.18328265122799, 0.12210601890895814","52.21895534832237, 0.14567620275439855"
16+
"52.21244434732635, 0.1490801688337803","52.196818204381266, 0.10553792182809701"
17+
"52.22303492190802, 0.1376354069349121","52.19862883527227, 0.09467242831119727"
18+
"52.22659244034883, 0.11177488679704915","52.18759556009445, 0.14774128039064668"
19+
"52.21528301045289, 0.16849365942532463","52.19681415397812, 0.10496032907463528"
20+
"52.21332401389602, 0.11188729564324532","52.18113462044644, 0.14974251178839748"
21+
"52.22768095118171, 0.13664867096038763","52.17710320087023, 0.11325036191882086"
22+
"52.63417137699556, 1.2333972289812105","52.66211644639584, 1.2944318457291342"
23+
"52.619067547836124, 1.2692200800653644","52.65222487740718, 1.329956859989728"
24+
"52.629563721921706, 1.261053798867691","52.62995375184875, 1.3412873898017135"
25+
"52.64761032604721, 1.3096485714544877","52.652899673444864, 1.2297839585861077"
26+
"52.63911155059366, 1.31441776191871","52.65397321157309, 1.2396490952049417"
27+
"52.62685977086623, 1.331150688809777","52.66912823400231, 1.2620061131481515"
28+
"52.617006709465166, 1.2480633672417472","52.68551056150943, 1.2906997198667902"

0 commit comments

Comments
 (0)