-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdriver_matching_strategy.py
More file actions
26 lines (22 loc) · 1.13 KB
/
driver_matching_strategy.py
File metadata and controls
26 lines (22 loc) · 1.13 KB
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
from abc import ABC, abstractmethod
from typing import List
from driver import Driver
from location import Location
from enums import DriverStatus, RideType
class DriverMatchingStrategy(ABC):
@abstractmethod
def find_drivers(self, all_drivers: List[Driver], pickup_location: Location, ride_type: RideType) -> List[Driver]:
pass
class NearestDriverMatchingStrategy(DriverMatchingStrategy):
MAX_DISTANCE_KM = 5.0 # Max distance to consider a driver "nearby"
def find_drivers(self, all_drivers: List[Driver], pickup_location: Location, ride_type: RideType) -> List[Driver]:
print(f"Finding nearest drivers for ride type: {ride_type.value}")
available_drivers = [
driver for driver in all_drivers
if (driver.get_status() == DriverStatus.ONLINE and
driver.get_vehicle().get_type() == ride_type and
pickup_location.distance_to(driver.get_current_location()) <= self.MAX_DISTANCE_KM)
]
# Sort by distance
available_drivers.sort(key=lambda d: pickup_location.distance_to(d.get_current_location()))
return available_drivers