|
| 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. |
0 commit comments