-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Models refactor + compute delivery time + display time
- Loading branch information
Showing
17 changed files
with
485 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from datetime import datetime, timedelta | ||
|
||
|
||
class Config: | ||
INITIAL_DEPART_TIME = datetime(year=1, month=1, day=1, hour=8) | ||
"""Time when the delivery driver starts his tour from the warehouse. | ||
""" | ||
|
||
TIME_WINDOW_SIZE = timedelta(hours=1) | ||
"""Time window size. | ||
""" | ||
|
||
TRAVELING_SPEED = 15 | ||
"""Speed at which the delivery driver travels between two points in km/h. | ||
""" | ||
|
||
DELIVERY_TIME = timedelta(minutes=5) | ||
"""Time it takes to deliver a package. | ||
""" | ||
|
||
KMH_TO_MS = 3.6 | ||
"""Conversion factor from km/h to m/s. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import uuid | ||
from dataclasses import dataclass, field | ||
from typing import List | ||
from uuid import UUID, uuid4 | ||
|
||
|
||
@dataclass | ||
class DeliveryMan: | ||
name: str | ||
availabilities: List[int] | ||
id: str = field(default_factory=lambda: str(uuid.uuid4())) | ||
id: UUID = field(default_factory=uuid4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
from src.models.tour.computed_delivery import ComputedDelivery | ||
from src.models.tour.computed_tour import ComputedTour | ||
from src.models.tour.delivery import ( | ||
ComputedDelivery, | ||
Delivery, | ||
DeliveryID, | ||
DeliveryRequest, | ||
) | ||
from src.models.tour.delivery_location import DeliveryLocation | ||
from src.models.tour.delivery_request import DeliveryRequest | ||
from src.models.tour.tour_request import TourRequest | ||
from src.models.tour.tour import ComputedTour, Tour, TourID, TourRequest |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from dataclasses import dataclass, field | ||
from datetime import time | ||
|
||
from src.models.delivery_man.delivery_man import DeliveryMan | ||
from src.models.tour.delivery_location import DeliveryLocation | ||
|
||
DeliveryID = int | ||
"""Type alias for a delivery ID | ||
""" | ||
|
||
|
||
@dataclass | ||
class Delivery: | ||
"""Base class for a delivery. This represent a delivery that can be requested or computed which has a location.""" | ||
|
||
location: DeliveryLocation | ||
"""Location of the delivery | ||
""" | ||
|
||
@property | ||
def id(self) -> DeliveryID: | ||
"""ID of the delivery that is unique for a DeliveryLocation | ||
Returns: | ||
DeliveryID: ID of the delivery | ||
""" | ||
return hash(f"{self.location.segment.id}{self.location.positionOnSegment}") | ||
|
||
|
||
@dataclass | ||
class DeliveryRequest(Delivery): | ||
"""Represents a delivery request that has a location and a time window.""" | ||
|
||
time_window: int | ||
"""Time window of the request. This number represent the hour of the time window. | ||
For example, time_window=8 means that the time window if from 8h to 9h. | ||
""" | ||
|
||
|
||
@dataclass | ||
class ComputedDelivery(Delivery): | ||
"""Represent a computed delivery that has a location and a time.""" | ||
|
||
time: time | ||
"""Computed time of the delivery | ||
""" | ||
|
||
@staticmethod | ||
def create_from_request( | ||
delivery_request: DeliveryRequest, time: time | ||
) -> "ComputedDelivery": | ||
"""Creates an instance of ComputedDelivery from a DeliveryRequest and a time. | ||
Args: | ||
delivery_request (DeliveryRequest): Delivery request to create the computed delivery from | ||
time (time): Computed time of the delivery | ||
Returns: | ||
ComputedDelivery: Created instance | ||
""" | ||
return ComputedDelivery( | ||
location=delivery_request.location, | ||
time=time, | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Dict, List | ||
from uuid import UUID | ||
|
||
from src.models.delivery_man.delivery_man import DeliveryMan | ||
from src.models.map import Segment | ||
from src.models.tour.delivery import ( | ||
ComputedDelivery, | ||
Delivery, | ||
DeliveryID, | ||
DeliveryRequest, | ||
) | ||
|
||
TourID = UUID | ||
"""Type alias for Tour ID | ||
""" | ||
|
||
|
||
@dataclass | ||
class Tour: | ||
"""Base class for tour. This represent a tour that can be request or computed.""" | ||
|
||
id: TourID | ||
"""ID of the tour. This ID is the same as its DeliveryMan ID. | ||
""" | ||
|
||
deliveries: Dict[DeliveryID, Delivery] | ||
"""Map of deliveries of the tour identified by their ID | ||
""" | ||
|
||
delivery_man: DeliveryMan | ||
"""Delivery man completing the tour | ||
""" | ||
|
||
color: str | ||
"""Color to use to display the tour | ||
""" | ||
|
||
|
||
@dataclass | ||
class TourRequest(Tour): | ||
"""Represents a tour request that has a list of delivery requests.""" | ||
|
||
deliveries: Dict[DeliveryID, DeliveryRequest] | ||
"""Map of delivery requests of the tour identified by their ID | ||
""" | ||
|
||
|
||
@dataclass | ||
class ComputedTour(Tour): | ||
"""Represents a computed tour that has a list of computed deliveries and a route.""" | ||
|
||
deliveries: Dict[DeliveryID, ComputedDelivery] | ||
"""Map of computed deliveries of the tour identified by their ID | ||
""" | ||
|
||
route: List[Segment] | ||
"""List of segments of the route | ||
""" | ||
|
||
@staticmethod | ||
def create_from_request( | ||
tour_request: TourRequest, | ||
deliveries: Dict[DeliveryID, ComputedDelivery], | ||
route: List[Segment], | ||
) -> "ComputedTour": | ||
"""Creates an instance of ComputedTour from a TourRequest, a list of computed deliveries and a route. | ||
Args: | ||
tour_request (TourRequest): Tour request to create the computed tour from | ||
deliveries (Dict[DeliveryID, ComputedDelivery]): Map of computed deliveries of the tour identified by their ID | ||
route (List[Segment]): List of segments of the route | ||
Returns: | ||
ComputedTour: Created instance | ||
""" | ||
|
||
return ComputedTour( | ||
id=tour_request.id, | ||
deliveries=deliveries, | ||
delivery_man=tour_request.delivery_man, | ||
route=route, | ||
color=tour_request.color, | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 22 additions & 11 deletions
33
src/services/command/commands/remove_delivery_request_command.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
from src.models.delivery_man.delivery_man import DeliveryMan | ||
from src.models.tour import DeliveryRequest | ||
from typing import Optional | ||
|
||
from src.models.tour import DeliveryRequest, TourID | ||
from src.services.command.abstract_command import AbstractCommand | ||
from src.services.tour.tour_service import TourService | ||
|
||
|
||
class RemoveDeliveryRequestCommand(AbstractCommand): | ||
__delivery_request: DeliveryRequest | ||
__delivery_man: DeliveryMan | ||
__delivery_request_id: TourID | ||
__tour_id: Optional[TourID] = None | ||
__delivery_request: Optional[DeliveryRequest] = None | ||
|
||
def __init__( | ||
self, delivery_request: DeliveryRequest, delivery_man: DeliveryMan | ||
self, delivery_request_id: TourID, tour_id: Optional[TourID] = None | ||
) -> None: | ||
""" | ||
Args: | ||
delivery_request_id (TourID): ID of the delivery request to remove | ||
tour_id (Optional[TourID], optional): ID of the tour to remove the delivery from (same as DeliveryMan ID). Defaults to None. | ||
""" | ||
super().__init__("Retrait d'une demande de livraison") | ||
self.__delivery_request = delivery_request | ||
self.__delivery_man = delivery_man | ||
self.__delivery_request_id = delivery_request_id | ||
self.__tour_id = tour_id | ||
|
||
def execute(self) -> None: | ||
TourService.instance().remove_delivery_request( | ||
self.__delivery_request, self.__delivery_man | ||
self.__delivery_request = TourService.instance().remove_delivery_request( | ||
delivery_request_id=self.__delivery_request_id, tour_id=self.__tour_id | ||
) | ||
|
||
def undo(self) -> None: | ||
if not self.__delivery_request: | ||
raise Exception("No delivery request to undo") | ||
|
||
TourService.instance().add_delivery_request( | ||
position=self.__delivery_request.location.segment.origin, | ||
delivery_man=self.__delivery_man, | ||
time_window=self.__delivery_request.timeWindow, | ||
tour_id=self.__tour_id, | ||
time_window=self.__delivery_request.time_window, | ||
) | ||
self.__delivery_request = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.