Skip to main content

Compare travel times obtained from TravelTime API other API providers

Project description

TravelTime Drive Time Comparisons tool

This tool compares the travel times obtained from TravelTime Routes API, Google Maps Directions API, TomTom Routing API, HERE Routing API, Mapbox Directions API, OpenRoutes API, OSRM Routes API, and Valhalla Routes API. Source code is available on GitHub.

Features

  • Get travel times from TravelTime API, Google Maps API, TomTom API, HERE API, Mapbox API, OSRM API and Valhalla API in parallel, for provided origin/destination pairs and a set of departure times.
  • Departure times are calculated based on user provided start time, end time and interval.
  • Analyze the differences between the results and print out an accuracy comparison, also the average error percentage when compared to TravelTime.

Prerequisites

The tool requires Python 3.8+ installed on your system. You can download it from here.

Installation

Create a new virtual environment with a chosen name (here, we'll name it 'env'):

python -m venv env

Activate the virtual environment:

source env/bin/activate

Install the project and its dependencies:

pip install traveltime-drive-time-comparisons

Setup

Provide credentials and desired max requests per minute for the APIs inside the config.json file. You can also disable unwanted APIs by changing the enabled value to false.

{
  "traveltime": {
    "app-id": "<your-app-id>",
    "api-key": "<your-api-key>",
    "max-rpm": "60"
  },
  "api-providers": [
    {
      "name": "google",
      "enabled": true,
      "api-key": "<your-api-key>",
      "max-rpm": "60"
    },
    ...other providers
  ]
}

Usage

Run the tool:

traveltime_drive_time_comparisons --input [Input CSV file path] --output [Output CSV file path] \
    --date [Date (YYYY-MM-DD)] --start-time [Start time (HH:MM)] --end-time [End time (HH:MM)] \
    --interval [Interval in minutes] --time-zone-id [Time zone ID] 

Required arguments:

  • --input [Input CSV file path]: Path to the input file. Input file is required to have a header row and at least one row with data, with two columns: origin and destination. The values in the columns must be latitude and longitude pairs, separated by comma and enclosed in double quotes. For example: "51.5074,-0.1278". Columns must be separated by comma as well. Check out the project's repository for examples in the examples directory and more pre-prepared routes in the inputs directory.
  • --output [Output CSV file path]: Path to the output file. It will contain the gathered travel times. See the details in the Output section
  • --date [Date (YYYY-MM-DD)]: date on which the travel times are gathered. Use a future date, as Google API returns errors for past dates (and times). Take into account the time needed to collect the data for provided input.
  • --start-time [Start time (HH:MM)]: start time in HH:MM format, used for calculation of departure times. See Calculating departure times
  • --end-time [End time (HH:MM)]: end time in HH:MM format, used for calculation of departure times. See Calculating departure times
  • --interval [Interval in minutes]: interval in minutes, used for calculation of departure times. See Calculating departure times
  • --time-zone-id [Time zone ID]: non-abbreviated time zone identifier in which the time values are specified. For example: Europe/London. For more information, see here.

Optional arguments:

  • --config [Config file path]: Path to the config file. Default - ./config.json

Example:

traveltime_drive_time_comparisons --input examples/uk.csv --output output.csv --date 2023-09-20 \
    --start-time 07:00 --end-time 20:00 --interval 180 --time-zone-id "Europe/London"

Calculating departure times

Script will collect travel times on the given day for departure times between provided start-time and end-time, with the given interval. The start-time and end-time are in principle inclusive, however if the time window is not exactly divisible by the 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 and interval to 240, the script will sample both APIs for departure times 08:00, 12:00, 16:00 and 20:00 (end-time included). But for interval equal to 300, the script will sample APIs for departure times 08:00, 13:00 and 18:00 (end-time is not included).

Console output

The console output contains results from the cross-validation. These results are calculated by comparing one provider's results with the average of all competitors. This process is repeated for all providers

2025-01-24 15:30:00 | INFO | Provider cross-validation results: 
     Provider  Accuracy %
0  TravelTime   90.717912
1      Google   82.346109
2      TomTom   75.481112

It also contains more detailed comparisons with each API

2025-06-11 13:23:36 | INFO | Comparing TravelTime to other providers:
2025-06-11 13:23:36 | INFO | 	Mean relative error compared to Google API: 12.91%
2025-06-11 13:23:36 | INFO | 	90% of TravelTime results differ from Google API by less than 32%
2025-06-11 13:23:36 | INFO | 	Mean relative error compared to TomTom API: 26.50%
2025-06-11 13:23:36 | INFO | 	90% of TravelTime results differ from TomTom API by less than 48%
2025-06-11 13:23:36 | INFO | Comparing Google to other providers:
2025-06-11 13:23:36 | INFO | 	Mean relative error compared to TravelTime API: 17.11%
2025-06-11 13:23:36 | INFO | 	90% of Google results differ from TravelTime API by less than 48%
2025-06-11 13:23:36 | INFO | 	Mean relative error compared to TomTom API: 33.21%
2025-06-11 13:23:36 | INFO | 	90% of Google results differ from TomTom API by less than 40%
2025-06-11 13:23:36 | INFO | Comparing TomTom to other providers:
2025-06-11 13:23:36 | INFO | 	Mean relative error compared to TravelTime API: 19.58%
2025-06-11 13:23:36 | INFO | 	90% of TomTom results differ from TravelTime API by less than 32%
2025-06-11 13:23:36 | INFO | 	Mean relative error compared to Google API: 24.60%
2025-06-11 13:23:36 | INFO | 	90% of TomTom results differ from Google API by less than 29%

File output

The output file will contain the origin and destination columns from input file, with some additional columns:

  • departure_time: departure time in YYYY-MM-DD HH:MM:SS±HHMM format, calculated from the start-time, end-time and interval. It includes date, time and timezone offset.
  • *_travel_time: travel time gathered from alternative provider API in seconds
  • tt_travel_time: travel time gathered from TravelTime API in seconds
  • error_percentage_*: relative error between provider and TravelTime travel times in percent, relative to provider result.

Sample output with 3 providers - TravelTime, Google and TomTom

origin,destination,departure_time,tt_travel_time,google_travel_time,tomtom_travel_time,error_percentage_traveltime_to_google,error_percentage_traveltime_to_tomtom,error_percentage_google_to_traveltime,error_percentage_google_to_tomtom,error_percentage_tomtom_to_traveltime,error_percentage_tomtom_to_google
"33.05187660000014 , -117.1350031999999","33.14408130000009 , -117.02942509999977",2025-06-20 13:00:00-0700,1970.0,2224.0,1869.0,11,5,12,18,5,15
"33.05187660000014 , -117.1350031999999","33.14408130000009 , -117.02942509999977",2025-06-20 16:00:00-0700,2052.0,3042.0,2274.0,32,9,48,33,10,25
"37.36713689999986 , -122.09885940000017","37.35365440000001 , -122.21751989999996",2025-06-20 13:00:00-0700,1868.0,1832.0,1317.0,1,41,1,39,29,28
"37.36713689999986 , -122.09885940000017","37.35365440000001 , -122.21751989999996",2025-06-20 16:00:00-0700,2004.0,1896.0,1345.0,5,48,5,40,32,29

License

This project is licensed under MIT License. For more details, see the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

traveltime_drive_time_comparisons-1.2.3.tar.gz (2.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file traveltime_drive_time_comparisons-1.2.3.tar.gz.

File metadata

File hashes

Hashes for traveltime_drive_time_comparisons-1.2.3.tar.gz
Algorithm Hash digest
SHA256 2413e85eae5fc4ea1d24b09e315f6c316bc41a1100d67cf35684cdaa7e475edb
MD5 f6038e521aa239ceb13e60809ac0caac
BLAKE2b-256 3ff4d6687ee5805b7e69c5f4b0c526d22f37f2a3692cd1ea33c3be643a62164d

See more details on using hashes here.

File details

Details for the file traveltime_drive_time_comparisons-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for traveltime_drive_time_comparisons-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 19f1106411eeda8f6c0ab41ff8b84cad9ce797d1fd9076eab0a7c3e21588bf78
MD5 cc5331475b214887f72fae57a7af9622
BLAKE2b-256 21cdc0321369ec47a9f84f6067c001dbef8d651b015a1e96c788e232bde436f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page