step 1. goto venv/scripts folder
step 2. activate the virtual environment by activating it.
step 3. Install all requirements.
pip install -r requirements.txt
step 4. run unit tests
python unit_test.py
step 5. run the file main.py
python main.py
step 6. Test the functionality
python basic_Solution_checker.py
You are tasked to implement a simple taxi booking system in a 2D grid world with the following criteria:
- The 2D grid world consists of
xandyaxis that each fit in a 32 bit integer, i.e.-2,147,483,648to2,147,483,647. - There are 3 cars in the system, All three cars should have id
1,2and3respectively and initial start location is at origin(0, 0). Note that you can store the car states in memory and there is no need for persistent storage for this exercise. - A car travels through the grid system will require 1 time unit to move along the
xoryaxis by 1 unit (i.e. Manhattan distance). For example- Car at
(0, 0)will reach(0, 2)in 2 time units. - Car at
(1, 1)will reach(4, 4)in 6 time units. - More than 1 car can be at the same point at any time.
- Car at
Your service should be running on PORT 8080. For simplicity, you
- DO NOT need to implement any form persistent storage. In memory data structures will be sufficient for this exercise.
- DO NOT need to handle concurrent API calls/data races. The APIs will be triggered serially.
There are 3 REST APIs you will need to implement.
Your system should pick the nearest available car to the customer location and return the total time taken to travel from the current car location to customer location then to customer destination.
- Request payload
{
"source": {
"x": x1,
"y": y1
},
"destination": {
"x": x2,
"y": y2
}
}- Response payload
{
"car_id": id,
"total_time": t
}- All car are available initially, and become booked once it is assigned to a customer. It will remain booked until it reaches its destination, and immediately become available again.
- In the event that there are more than one car near the customer location, your service should return the car with the smallest id.
- Only one car be assigned to a customer, and only one customer to a car.
- Cars can occupy the same spot, e.g. car 1 and 2 can be at point (1, 1) at the same time.
- If there is no available car that can satisfy the request, your service should return an empty response, not an error
To facilitate the review of this exercise, your service should expose /api/tick REST endpoint, when called should advance your service time stamp by 1 time unit.
Your service should also provide /api/reset REST endpoint, when called will reset all cars data back to the initial state regardless of cars that are currently booked.
Run the test cases in the file basic_solution_checker.py to check whether your API works correctly
python3 basic_solution_checker.pyYour solution should
- Be implemented using any web framework and/or language of your own choice (e.g. Nodejs, Django, Dropwizard, Play, C#, Go ...etc.)
- Use appropriate algorithms/data structures
- Demonstrate proper software design and engineering practices (i.e. SOLID principles, unit testing ...etc.)
- Be of production quality
- Able to run on Linux
- Contains unit tests and clear instructions on how to build/execute them
- Have clear design/API documentation