项目作者: wilfriedroset

项目描述 :
Compute commute distance and duration using waze api
高级语言: Python
项目地址: git://github.com/wilfriedroset/waze-commute.git
创建时间: 2019-06-23T16:16:18Z
项目社区:https://github.com/wilfriedroset/waze-commute

开源协议:MIT License

下载


Waze Commute

This is a quick script to poll Waze API to compute commute (both ways) from one
or more addresses to a point of interest. The purpose of this script is to be
used as an exec
plugin

for telegraf. This would allow a user
to have metrics to graph traffic evolution.

The idea came from a personal project to have usable data to see if it is wise
or not to live farther away from the city center to save money.

Install dependencies

  1. $ git clone https://github.com/wilfriedroset/waze-commute; cd waze-commute
  2. $ pip install -r requirements.txt
  1. $ python waze-commute.py -h
  2. usage: waze-commute.py [-h] --addresses-file ADDRESSES_FILE
  3. [--region {EU,US,IL,AU}] --destination DESTINATION
  4. [--destination-alias DESTINATION_ALIAS]
  5. [--departure-alias DEPARTURE_ALIAS] [--no-real-time]
  6. optional arguments:
  7. -h, --help show this help message and exit
  8. --addresses-file ADDRESSES_FILE
  9. path to addresses file
  10. --region {EU,US,IL,AU}
  11. Region is used for address searching
  12. --destination DESTINATION
  13. destination address for which to compute from/to
  14. routing
  15. --destination-alias DESTINATION_ALIAS
  16. alias of destination address
  17. --departure-alias DEPARTURE_ALIAS
  18. alias of departure addresses
  19. --no-real-time get the time estimate not including current conditions

Credit goes to kovacsbalu for
WazeRouteCalculator

Configuration

Point of interest address can be define on the command line as there is only
address supported as point of interest. Departure addresses are defined in a
YAML (or JSON) configuration file.

  1. ---
  2. addresses:
  3. - address: Pessac, Gironde, France
  4. - address: Merignac, Gironde, France
  5. - address: Saint-Emillion, Gironde, France

You can add as many key as you want, they will be used as tags. You can add for
example geographic coordinate (latitude/longitude), average m2 price, neighbour
name…

  1. ---
  2. addresses:
  3. - address: Pessac, Gironde, France
  4. river_side: gauche
  5. - address: Merignac, Gironde, France
  6. river_side: gauche
  7. - address: Saint-Emillion, Gironde, France
  8. river_side: droite

Example

  1. $ python waze-commute.py --addresses-file addresses.example.yaml --destination "Bordeaux, Gironde, France"
  2. [
  3. {
  4. "duration": 1500,
  5. "distance": 19362,
  6. "from": "Pessac, Gironde, France",
  7. "to": "Bordeaux, Gironde, France",
  8. "source": "waze",
  9. "way": "home->office",
  10. "with_traffic": true,
  11. "river_side": "gauche"
  12. },
  13. {
  14. "duration": 2521,
  15. "distance": 44344,
  16. "from": "Saint-Emillion, Gironde, France",
  17. "to": "Bordeaux, Gironde, France",
  18. "source": "waze",
  19. "way": "home->office",
  20. "with_traffic": true,
  21. "river_side": "droite"
  22. },
  23. {
  24. "duration": 1440,
  25. "distance": 19214,
  26. "from": "Bordeaux, Gironde, France",
  27. "to": "Pessac, Gironde, France",
  28. "source": "waze",
  29. "way": "office->home",
  30. "with_traffic": true,
  31. "river_side": "gauche"
  32. },
  33. {
  34. "duration": 1261,
  35. "distance": 8881,
  36. "from": "Merignac, Gironde, France",
  37. "to": "Bordeaux, Gironde, France",
  38. "source": "waze",
  39. "way": "home->office",
  40. "with_traffic": true,
  41. "river_side": "gauche"
  42. },
  43. {
  44. "duration": 1321,
  45. "distance": 8897,
  46. "from": "Bordeaux, Gironde, France",
  47. "to": "Merignac, Gironde, France",
  48. "source": "waze",
  49. "way": "office->home",
  50. "with_traffic": true,
  51. "river_side": "gauche"
  52. },
  53. {
  54. "duration": 2520,
  55. "distance": 43901,
  56. "from": "Bordeaux, Gironde, France",
  57. "to": "Saint-Emillion, Gironde, France",
  58. "source": "waze",
  59. "way": "office->home",
  60. "with_traffic": true,
  61. "river_side": "droite"
  62. }
  63. ]

Duration is in seconds and distance is in meters.

Running with Telegraf

You can use telegraf plugin
exec
to
run the script periodically and write the points in the back-end of you choice. I
would suggest influxdb as back-end.

Here is an example of telegraf configuration

  1. [[inputs.exec]]
  2. commands = ["python /absolute/path/to/waze-commute.py --addresses-file /absolute/path/to/addresses.example.yaml --destination 'Bordeaux, Gironde, France'"]
  3. name_override = "commute"
  4. timeout = "4m"
  5. interval = "5m"
  6. data_format = "json"
  7. tag_keys = ["way", "from", "to", "river_side", "source", "with_traffic"]
  8. tagdrop = ["host"]

Running with docker

Build the image using the provide docker file.

  1. $ docker build -t waze-commute .

Then execute, use it like telegraf image

Bonus: Spawn your influxdb & grafana with docker

  1. version: '3'
  2. services:
  3. influxdb:
  4. image: "influxdb:latest"
  5. volumes:
  6. - ./data/influxdb:/var/lib/influxdb
  7. ports:
  8. - "8086:8086"
  9. networks:
  10. - tsdb
  11. grafana:
  12. image: "grafana/grafana:latest"
  13. ports:
  14. - "3000:3000"
  15. volumes:
  16. - ./data/grafana:/var/lib/grafana
  17. networks:
  18. - tsdb
  19. user: "1000"
  20. telegraf:
  21. build:
  22. context: ./waze-commute
  23. dockerfile: Dockerfile-telegraf
  24. command: ["telegraf", "--config-directory", "/etc/telegraf/telegraf.d/"]
  25. volumes:
  26. - ./data/telegraf:/etc/telegraf:ro
  27. networks:
  28. - tsdb
  29. networks:
  30. tsdb: