-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpricing_strategy.py
More file actions
27 lines (22 loc) · 925 Bytes
/
pricing_strategy.py
File metadata and controls
27 lines (22 loc) · 925 Bytes
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
from abc import ABC, abstractmethod
from location import Location
from enums import RideType
class PricingStrategy(ABC):
@abstractmethod
def calculate_fare(self, pickup: Location, dropoff: Location, ride_type: RideType) -> float:
pass
class FlatRatePricingStrategy(PricingStrategy):
BASE_FARE = 5.0
FLAT_RATE = 1.5
def calculate_fare(self, pickup: Location, dropoff: Location, ride_type: RideType) -> float:
distance = pickup.distance_to(dropoff)
return self.BASE_FARE + distance * self.FLAT_RATE
class VehicleBasedPricingStrategy(PricingStrategy):
BASE_FARE = 2.50
RATE_PER_KM = {
RideType.SEDAN: 1.50,
RideType.SUV: 2.00,
RideType.AUTO: 1.00
}
def calculate_fare(self, pickup: Location, dropoff: Location, ride_type: RideType) -> float:
return self.BASE_FARE + self.RATE_PER_KM[ride_type] * pickup.distance_to(dropoff)