door2door service collects the live position of all vehicles in its fleet in real-time via a GPS sensor in each vehicle. To manage the service, door2door needs to be able to visualize the location and bearing of all vehicles in real-time.
- Create an API to register a vehicle
- Create an API to collect vehicle location details
- Create an API to de-register a vehicle
- Store and update vehicle data in a database table
- Call the endpoint to register the vehicle
- Call the endpoint to start updating vehicle location data
- Plot the location coordinates on a map for the visualization
- Derive the routes by calling update enpoint for updating vehicle location data
- Call the endpoint to de-register the vehicle after the destination is reached
- Test the solution with vehicle.json file which contains all the vehicle location data
- Visualize the cluster map with vehicle locations
- Python 3.7
- AWS
This software will register all the vehicles, collects the live position and updates the location to the system and also de-registers the vehicle as and when the location updates are completed. The solution of this software is expected to visualize all the registered vehicle's real-time location data on Google Maps.
There are 2 types of solutions in this repository:
- Module --> "D2D_Vehicle_Location_API"
- Module --> "D2D_Vehicle_Location_Tracker"
-
Register API (POST /vehicles)
- Registers a vehicle and stores in DynamoDB table with the registered status set to "True"
- This vehicle is eligible to start emitting location updates
-
Location Update API (POST /vehicles/:id/locations)
- Checks if vehicle is registered to send location updates
- If registered, it verifies if the vehicle is sending updates no more than once every 3secs
- If registered and the requests are once every 3secs, then vehicle latitude, longitude coordinates are stored in DynamoDB table
- It plots the map according to the coordinates of the vehicle
- Saves the map in an S3 bucket for the visualization
-
De-Register API (DELETE /vehicles/:id)
- De-Register's the vehicle and the registered status is set to "False" in DynamoDB table
- Map is updated by removing the de-registered vehicle from the plot
- Saves the updated map in S3 bucket for the visualization
- lambda_function.py -- Main function for "D2D_Vehicle_Location_API" workflow
- requirements.txt -- Requirements file which contains the project dependencies
- api_creds.yml -- API key credentials to call REST APIs
- vehicle_data.csv -- An extract of Vehicle's valid position data stored in DynamoDB table for future analysis
- Python 3.7 or Python 3.8
- AWS Lambda with Layers
- Amazon API Gateway
- Amazon DynamoDB
- Amazon S3
- Register -- https://03fc0pnobj.execute-api.us-east-1.amazonaws.com/visualize-location/vehicles (POST)
- Location Update -- https://03fc0pnobj.execute-api.us-east-1.amazonaws.com/visualize-location/vehicles/{id}/locations (POST)
- De-Register -- https://03fc0pnobj.execute-api.us-east-1.amazonaws.com/visualize-location/vehicles/{id} (DELETE)
- Table Name - Vehicle_Data
- Primary Key - Vehicle_Number
- Attributes - latitude, longitude, Registered, requested_ts, timestamp
Visualize the location of all the vehicles on a map (in any browser) by clicking the below web URL.
URL --> https://vehicle-visual-map.s3.amazonaws.com/map/visual_map.html
** NOTE: To register a new vehicle and start sending location updates, call the REST endpoints and view the result by clicking on the same website URL **
PS: DEMO screenshots available in D2D_Vehicle_Location_API/README.md
-
folium -- A python package for visualizing maps that makes it easy to visualize data that's been manipulated in Python on an interactive leaflet map. It enables both the binding of data to a map for choropleth visualizations as well as passing rich vector/raster/HTML visualizations as markers on the map.
-
requests -- A python package to call REST APIs securely and easily
-
geopy -- A python client for several popular geocoding web services which makes it easy to locate the coordinates of addresses, cities, countries, and landmarks across the globe using third-party geocoders and other data sources.
-
boto3 -- An AWS SDK Client used to call different AWS resources via APIs
-
unittest -- An unit test library used to mock test scenarios and validate assertions
-
moto -- A mocking framework used in test functions to mock AWS resources such as DynamoDB, S3 etc..
-
Register API (POST /vehicles)
- Registers a vehicle and stores in DynamoDB table with the registered status set to "True"
- This vehicle is eligible to start emitting location updates
-
Location Update API (POST /vehicles/:id/locations)
- Updates the location on map until the destination is reached (nodes provided in vehicle.json file)
- Gets the nodes to update each step from the JSON file
- Calculates vehicle's distance if it is within 3.5km radius (as per requirement)
- Plots all the nodes and forms a cluster within the boundaries
- Saves the map in an HTML file for the visualization
-
De-Register API (DELETE /vehicles/:id)
- De-Register's the vehicle and the registered status is set to "False" in DynamoDB table
- Map is updated by removing the de-registered vehicle from the plot
- Saves the updated map in an HTML file for the visualization
- src/main.py -- Main function for "D2D_Vehicle_Location_Tracker" workflow
- src/vehicle_location_mapping.py -- Function which updates the vehicle's location by calculating the distance
- src/api_url.py -- File which contains all the endpoints
- src/load_json_file.py -- Generic file which loads JSON file and returns the data
- src/vehicle.json -- JSON file which contains vehicle data
- src/visual_map.html -- HTML file for the map visualization
- src/tests/vehicle_location_test.py -- Test file where all the unit test cases related to the project are written
- src/lambda_api/Vehicle_Registration.py -- API lambda to register the vehicle
- src/lambda_api/Vehicle_Location_Update.py -- API lambda to update the location coordinates of the vehicle
- src/lambda_api/Vehicle_DeRegistration.py -- API lambda to de-register the vehicle
- src/screenshots -- Screenshots of the visual map
- src/requirements.txt -- Requirements file which contains the project dependencies
- Python 3.7 or Python 3.8
- AWS Lambda
- Amazon API Gateway
- Amazon DynamoDB
- Register -- https://vpoe02xgyh.execute-api.us-east-1.amazonaws.com/dev/vehicles (POST)
- Location Update -- https://hgge3eylqg.execute-api.us-east-1.amazonaws.com/dev/vehicles (POST)
- De-Register -- https://245um5jz9c.execute-api.us-east-1.amazonaws.com/dev/vehicles(DELETE)
- Table Name - Vehicle_Tracker
- Primary Key - Vehicle_Number
- Attributes - latitude, longitude, Registered, requested_ts, timestamp
To visualize all the vehicle nodes as a cluster within the city boundaries on a map, run "main.py" file and open "visual_map.html" to view the result
PS: DEMO screenshots available in D2D_Vehicle_Location_Tracker/src/screenshots/README.md