Majorly has three parts:
- config : Env specific configurations with
COMMAND_DICT
incommon.py
which is a map of expected of commands - parking_system : Parking system package with core parking logic and required mappings
- constants.py : All constants related to parking system
- driver.py : Driver class with age attribute
- exceptions.py : Custom execptions related to parking system
- main.py :
RunParkingSystem
class to run logics according to input commands. Basically a pythonic switch-case - parking_system.py : Singleton design pattern based parking system class. Includes all the logics required to park or leave a car. Car assignment is done with min-heap data structure
- utils.py : Utility class for helper methods
- vehicles.py : Vehicle base class and its sub classes
- run.py : Script to run the parking system algorithm
- Clone the project and
cd parking_system/
- Requirements :
Python3.6+
run.sh
: Executes user command and run parking system algorithm- Configure
PARKING_SYSTEM_ENV
according to required environment. Default isproduction
- To trace more detailed logs configure
PARKING_SYSTEM_ENV
todevelopment
orpre-production
- Configure
- Give permissions :
sudo chmod +x run.sh
- Run from filepath :
./run.sh filepath=./files/input.txt
. Change filepath for your requirement - Run interactively on terminal
./run.sh interactive
- Default environment :
development
- Run from filepath :
python run.py --filepath=./files/input.txt
. Change filepath for your requirement - Run interactively on terminal:
python run.py --interactive
- Used singleton design pattern for ParkingSystem class. Only one instance of ParkingSystem will be available all the time. I chose not to raise exception and exit the system because may be real-world scenario that is not feasible rather I recreate instance with with new params on same address.
- For car parking logics used min-heap data structure
LOG_LEVEL
isINFO
and for pre-production/development asDEBUG
. To change the envexport PARKING_SYSTEM_ENV=xxxx
. - Created Vehicle base class and extends car from it so that the system can be scaled in future for other vehicle types as well
- Kept checks on input command outside
parking_system
package.helper.py
verifies the command validity and number of params for a particular command andmain.py
gives the interface between input command and parking system package