-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehiclePricingDecision.py
90 lines (75 loc) · 3.54 KB
/
vehiclePricingDecision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from datetime import datetime
from vehicleDatabaseParser import VehicleDatabaseParser
from vehicle import Vehicle
from resultCodes import *
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class VehiclePricingDecision:
def __init__(self):
pass
def decisionMaker(self, vehicle, currentWeight):
''' The method that makes the decision whether or not to open the toll for a given vehicle. '''
# Check vehicle details first
if not self.__checkRcStatus(vehicle):
# TODO : Add logging debug statements and change return type based on action to be taken
return VEHICLE_RC_NOT_ACTIVE
# True if Registration has not expired
if not self.__checkRegistrationExpiry(vehicle):
# TODO : Add logging debug statements and change return type based on action to be taken
return VEHICLE_REGISTRATION_EXPIRED
# True if not expired
if not self.__checkInsuranceExpiry(vehicle):
# TODO : Add logging debug statements and change return type based on action to be taken
return VEHICLE_INSURANCE_EXPIRED
# Check weight if vehicle is within the allowed maximum weight
if not self.__checkOverload(vehicle, currentWeight):
# TODO : Add logging debug statements and change return type based on action to be taken
return VEHICLE_OVERLOADED
# If vehicle is legal and allowed, proceed for calculation of toll price
tollPrice = self.__calculateTollPrice(currentWeight)
return tollPrice
def __calculateTollPrice(self, currentWeight):
''' Pricing of the allowed vehicles '''
print("Calculating your toll price...")
return currentWeight//12
def __checkRcStatus(self, vehicle):
print("Checking your Vehicle RC Status...")
if vehicle.rcStatus == 'ACTIVE':
print('DONE.')
return True
else:
return False
def __checkRegistrationExpiry(self, vehicle):
print("Checking your Vehicle Registration validity...")
expiryDate = datetime.strptime(vehicle.registrationExpiryDate, '%d-%b-%Y').date()
if expiryDate > datetime.today().date():
print("DONE.")
return True
else:
return False
def __checkInsuranceExpiry(self, vehicle):
print("Checking your Vehicle Insurance Validity...")
expiryDate = datetime.strptime(vehicle.insuranceExpiryDate, '%d-%b-%Y').date()
if expiryDate > datetime.today().date():
print("DONE.")
return True
else:
print("Vehicle Insurance Validity Date:", vehicle.insuranceExpiryDate)
print("Todays date:", datetime.today().date())
return False
def __checkOverload(self, vehicle, currentWeight):
print("Checking the weight of vehicle for overload...")
if currentWeight >= vehicle.vehicleGvwr:
print("Current Weight of the vehicle =", currentWeight)
print("Maximum allowed weight for your vehicle =", vehicle.vehicleGvwr)
return False
else:
print("DONE.")
return True
if __name__ == "__main__":
# Following used for debugging
vehicleDatabaseParser = VehicleDatabaseParser('VehicleDatabase.db')
vehicle = Vehicle(vehicleDatabaseParser.getAsListVehicleDetails('KA02JK2930'))
vehiclePricingDecision = VehiclePricingDecision()
vehiclePricingDecision.decisionMaker(vehicle, currentWeight=150)