diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6b76b4f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/Truck.py b/Truck.py index 6b017f4..b96eba1 100644 --- a/Truck.py +++ b/Truck.py @@ -38,14 +38,17 @@ class Truck: pkgMins = offsetMinutes % 60 # pull minutes back out return datetime.time(pkgHours, pkgMins) # return the time of day - def deliverPkgs(self): # Delivers any packeges that match the current location + def deliverPkgs(self): # Delivers any packeges that match the current location for i in range(len(self.packages) - 1, -1, -1): # Loop backwards so removals dont index shift - if self.packages[i].address in self.current_location: # Check if the package is at the correct address - self.packages[i].status = deliveryStatus.DELIVERED # Mark as delivered - self.packages[i].timeEnd = self.getTimeOfDay() # Mark the delivered time - self.deliveryCounter += 1 # Incriment the delivery counter - self.packages[i].deliveryNumber = self.deliveryCounter # Mark the package number - self.packages.remove(self.packages[i]) # Remove the package from the truck + pkg = self.packages[i] + if pkg.address in self.current_location: # Check if the package is at the correct address + if ("Wrong address listed" not in pkg.notes or + self.getTimeOfDay() >= datetime.time(10, 30)): # Wait for corrected shipping address + pkg.status = deliveryStatus.DELIVERED # Mark as delivered + pkg.timeEnd = self.getTimeOfDay() # Mark the delivered time + self.deliveryCounter += 1 # Incriment the delivery counter + pkg.deliveryNumber = self.deliveryCounter # Mark the package number + self.packages.pop(i) def getMatrixIndex(self, address_string: str) -> int: # Helper function to get x or y offset in the distance table for i, full_name in enumerate(AssignmentData.xyNames2): # Loop through the names in the list @@ -57,19 +60,25 @@ class Truck: print(f"Address {address_string} is not in Full List") # Report items not found in the list return 0 # Default to Hub if not found - def driveNextClosest(self, priority: DerekHashTable) -> int: # The bread and butter of the algorithm + def driveNextClosest(self, priority: DerekHashTable) -> datetime.time: # The bread and butter of the algorithm # deal with priority priorityPkgs = [] # set the packages we currently want to look for for cur in self.packages: # loop thorugh looking for priority matches if priority.getItem(cur.id): priorityPkgs.append(cur) # if a priority matches add it to the list if not priorityPkgs: # if no priority matches just use the normal - priorityPkgs = self.packages + for v in self.packages: + if ("Wrong address listed" not in v.notes or # If the package is marked wrong address + self.getTimeOfDay() >= datetime.time(10, 30)): # Wait for corrected shipping address + priorityPkgs.append(v) # add to the list # get the next closest shortest_dist = float('inf') # Start with a very long distance to work backwards from next_pkg = None # Keep track of the closest pkg + if len(priorityPkgs) == 0: + priorityPkgs.append(DeliveryObject(-1, "HUB", "", "", 0, "10:30 AM", 21),) # Add a blank package in order to get the truck to drive back to HUB + current_idx = self.getMatrixIndex(self.current_location) # Get the trucks xyIndex for pkg in priorityPkgs: # Loop through the packages dest_idx = self.getMatrixIndex(pkg.address) # Get the package xyIndex @@ -87,5 +96,4 @@ class Truck: self.current_location = next_pkg.address # update the location self.deliverPkgs() # deliver packages at this location if len(self.packages) == 0: # if there is no packages - self.hasLoad = False # Set the load to empty - return len(self.packages) # return packages left to deliver \ No newline at end of file + self.hasLoad = False # Set the load to empty \ No newline at end of file diff --git a/UI.py b/UI.py index 2297336..4057b9e 100644 --- a/UI.py +++ b/UI.py @@ -35,7 +35,7 @@ class DataUI: endTime = "Pending" if v.startTime != None: startTime = v.startTime.strftime('%H:%M') - if v.packages.count == 0: + if len(v.packages) == 0: endTime = v.getTimeOfDay().strftime('%H:%M') print(f"Truck [{v.id}] | " @@ -50,9 +50,12 @@ class DataUI: selection = self.selectionChooser(package_hash) print("") for i,v in enumerate(selection): + truckID = v.truckId + if truckID == -1: + truckID = "None" print(f"[{v.id:2}] | " f"[DeliveryNumber]: {v.deliveryNumber:2} | " - f"[onTruck]: {v.truckId:2} | " + f"[onTruck]: {truckID:4} | " f"[Address]: {v.address[:20]:20} | " f"[Status]: {v.status:10} | " f"[Note]: {v.notes:10}") diff --git a/__pycache__/AssignmentData.cpython-314.pyc b/__pycache__/AssignmentData.cpython-314.pyc index 38c7ad2..4abaeaa 100644 Binary files a/__pycache__/AssignmentData.cpython-314.pyc and b/__pycache__/AssignmentData.cpython-314.pyc differ diff --git a/__pycache__/DeliveryObject.cpython-314.pyc b/__pycache__/DeliveryObject.cpython-314.pyc index b4f3658..40f88fb 100644 Binary files a/__pycache__/DeliveryObject.cpython-314.pyc and b/__pycache__/DeliveryObject.cpython-314.pyc differ diff --git a/__pycache__/MyHashTable.cpython-314.pyc b/__pycache__/MyHashTable.cpython-314.pyc index 6e0e9d7..024cd9e 100644 Binary files a/__pycache__/MyHashTable.cpython-314.pyc and b/__pycache__/MyHashTable.cpython-314.pyc differ diff --git a/__pycache__/MyLinkedList.cpython-314.pyc b/__pycache__/MyLinkedList.cpython-314.pyc index 11cf59e..82a9fb7 100644 Binary files a/__pycache__/MyLinkedList.cpython-314.pyc and b/__pycache__/MyLinkedList.cpython-314.pyc differ diff --git a/__pycache__/Truck.cpython-314.pyc b/__pycache__/Truck.cpython-314.pyc index d2515ea..5192359 100644 Binary files a/__pycache__/Truck.cpython-314.pyc and b/__pycache__/Truck.cpython-314.pyc differ diff --git a/__pycache__/UI.cpython-314.pyc b/__pycache__/UI.cpython-314.pyc index 7da7ea7..16a3cf3 100644 Binary files a/__pycache__/UI.cpython-314.pyc and b/__pycache__/UI.cpython-314.pyc differ diff --git a/main.py b/main.py index bc323f6..8697bf8 100755 --- a/main.py +++ b/main.py @@ -68,6 +68,10 @@ def main(): truck3LoadDebounce = True while True: + # check for pause time + if globalTime >= pauseTime: + pauseTime = UserUI.TimePrompt(globalTime, truck1, truck2, truck3, package_hash) + # update global time if globalTime >= datetime.time(10, 20): # If the time is correct for update pkg9 = package_hash.getItem(9) # Handle the Package #9 address correction before Truck 3 starts @@ -88,23 +92,26 @@ def main(): truck2.addPkg(package_hash.getItem(pkg_id)) # load packages for truck 3 - if globalTime >= truck3.startTime and debounce3: # If its time to laod the packages, run once - debounce3 = False # set debounce for only one run - truck2.hasLoad = True # Set the truck load variable - for pkg_id in t2_load: # Load the packages in truck 2 - truck2.addPkg(package_hash.getItem(pkg_id)) + if type(truck3.startTime) is datetime.time: # Verify type corectness + if globalTime >= truck3.startTime and debounce3: # If its time to laod the packages, run once + debounce3 = False # set debounce for only one run + truck3.hasLoad = True # Set the truck load variable + for pkg_id in t3_load: # Load the packages in truck 2 + truck3.addPkg(package_hash.getItem(pkg_id)) # deliver packages for truck 1 if truck1.hasLoad and globalTime >= truck1.getTimeOfDay(): # if there is more packages and the time has passed - packagesLeft = truck1.driveNextClosest(priority_hash) # deliver the next set of packages - if packagesLeft == 0 and truck3LoadDebounce: # if all the packages are delivered + truck1.driveNextClosest(priority_hash) # deliver the next set of packages + if len(truck1.packages) == 0 and truck3LoadDebounce: # if all the packages are delivered + truck1.driveNextClosest(priority_hash) # drive back to the HUB truck3LoadDebounce = False # set the debouce truck3.startTime = truck1.getTimeOfDay() # set truck3 start time # deliver packages for truck 2 if truck2.hasLoad and globalTime >= truck2.getTimeOfDay(): # if there is more packages and the time has passed - packagesLeft = truck2.driveNextClosest(priority_hash) # deliver the next set of packages - if packagesLeft == 0 and truck3LoadDebounce: # if all the packages are delivered + truck2.driveNextClosest(priority_hash) # deliver the next set of packages + if len(truck2.packages) == 0 and truck3LoadDebounce: # if all the packages are delivered + truck2.driveNextClosest(priority_hash) # drive back to the HUB truck3LoadDebounce = False # set the debouce truck3.startTime = truck1.getTimeOfDay() # set truck3 start time