Fix assignment
This commit is contained in:
Vendored
+15
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -40,12 +40,15 @@ class Truck:
|
|||||||
|
|
||||||
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
|
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
|
pkg = self.packages[i]
|
||||||
self.packages[i].status = deliveryStatus.DELIVERED # Mark as delivered
|
if pkg.address in self.current_location: # Check if the package is at the correct address
|
||||||
self.packages[i].timeEnd = self.getTimeOfDay() # Mark the delivered time
|
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
|
self.deliveryCounter += 1 # Incriment the delivery counter
|
||||||
self.packages[i].deliveryNumber = self.deliveryCounter # Mark the package number
|
pkg.deliveryNumber = self.deliveryCounter # Mark the package number
|
||||||
self.packages.remove(self.packages[i]) # Remove the package from the truck
|
self.packages.pop(i)
|
||||||
|
|
||||||
def getMatrixIndex(self, address_string: str) -> int: # Helper function to get x or y offset in the distance table
|
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
|
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
|
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
|
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
|
# deal with priority
|
||||||
priorityPkgs = [] # set the packages we currently want to look for
|
priorityPkgs = [] # set the packages we currently want to look for
|
||||||
for cur in self.packages: # loop thorugh looking for priority matches
|
for cur in self.packages: # loop thorugh looking for priority matches
|
||||||
if priority.getItem(cur.id):
|
if priority.getItem(cur.id):
|
||||||
priorityPkgs.append(cur) # if a priority matches add it to the list
|
priorityPkgs.append(cur) # if a priority matches add it to the list
|
||||||
if not priorityPkgs: # if no priority matches just use the normal
|
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
|
# get the next closest
|
||||||
shortest_dist = float('inf') # Start with a very long distance to work backwards from
|
shortest_dist = float('inf') # Start with a very long distance to work backwards from
|
||||||
next_pkg = None # Keep track of the closest pkg
|
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
|
current_idx = self.getMatrixIndex(self.current_location) # Get the trucks xyIndex
|
||||||
for pkg in priorityPkgs: # Loop through the packages
|
for pkg in priorityPkgs: # Loop through the packages
|
||||||
dest_idx = self.getMatrixIndex(pkg.address) # Get the package xyIndex
|
dest_idx = self.getMatrixIndex(pkg.address) # Get the package xyIndex
|
||||||
@@ -88,4 +97,3 @@ class Truck:
|
|||||||
self.deliverPkgs() # deliver packages at this location
|
self.deliverPkgs() # deliver packages at this location
|
||||||
if len(self.packages) == 0: # if there is no packages
|
if len(self.packages) == 0: # if there is no packages
|
||||||
self.hasLoad = False # Set the load to empty
|
self.hasLoad = False # Set the load to empty
|
||||||
return len(self.packages) # return packages left to deliver
|
|
||||||
@@ -35,7 +35,7 @@ class DataUI:
|
|||||||
endTime = "Pending"
|
endTime = "Pending"
|
||||||
if v.startTime != None:
|
if v.startTime != None:
|
||||||
startTime = v.startTime.strftime('%H:%M')
|
startTime = v.startTime.strftime('%H:%M')
|
||||||
if v.packages.count == 0:
|
if len(v.packages) == 0:
|
||||||
endTime = v.getTimeOfDay().strftime('%H:%M')
|
endTime = v.getTimeOfDay().strftime('%H:%M')
|
||||||
|
|
||||||
print(f"Truck [{v.id}] | "
|
print(f"Truck [{v.id}] | "
|
||||||
@@ -50,9 +50,12 @@ class DataUI:
|
|||||||
selection = self.selectionChooser(package_hash)
|
selection = self.selectionChooser(package_hash)
|
||||||
print("")
|
print("")
|
||||||
for i,v in enumerate(selection):
|
for i,v in enumerate(selection):
|
||||||
|
truckID = v.truckId
|
||||||
|
if truckID == -1:
|
||||||
|
truckID = "None"
|
||||||
print(f"[{v.id:2}] | "
|
print(f"[{v.id:2}] | "
|
||||||
f"[DeliveryNumber]: {v.deliveryNumber:2} | "
|
f"[DeliveryNumber]: {v.deliveryNumber:2} | "
|
||||||
f"[onTruck]: {v.truckId:2} | "
|
f"[onTruck]: {truckID:4} | "
|
||||||
f"[Address]: {v.address[:20]:20} | "
|
f"[Address]: {v.address[:20]:20} | "
|
||||||
f"[Status]: {v.status:10} | "
|
f"[Status]: {v.status:10} | "
|
||||||
f"[Note]: {v.notes:10}")
|
f"[Note]: {v.notes:10}")
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -68,6 +68,10 @@ def main():
|
|||||||
truck3LoadDebounce = True
|
truck3LoadDebounce = True
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
# check for pause time
|
||||||
|
if globalTime >= pauseTime:
|
||||||
|
pauseTime = UserUI.TimePrompt(globalTime, truck1, truck2, truck3, package_hash)
|
||||||
|
|
||||||
# update global time
|
# update global time
|
||||||
if globalTime >= datetime.time(10, 20): # If the time is correct for update
|
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
|
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))
|
truck2.addPkg(package_hash.getItem(pkg_id))
|
||||||
|
|
||||||
# load packages for truck 3
|
# load packages for truck 3
|
||||||
|
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
|
if globalTime >= truck3.startTime and debounce3: # If its time to laod the packages, run once
|
||||||
debounce3 = False # set debounce for only one run
|
debounce3 = False # set debounce for only one run
|
||||||
truck2.hasLoad = True # Set the truck load variable
|
truck3.hasLoad = True # Set the truck load variable
|
||||||
for pkg_id in t2_load: # Load the packages in truck 2
|
for pkg_id in t3_load: # Load the packages in truck 2
|
||||||
truck2.addPkg(package_hash.getItem(pkg_id))
|
truck3.addPkg(package_hash.getItem(pkg_id))
|
||||||
|
|
||||||
# deliver packages for truck 1
|
# deliver packages for truck 1
|
||||||
if truck1.hasLoad and globalTime >= truck1.getTimeOfDay(): # if there is more packages and the time has passed
|
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
|
truck1.driveNextClosest(priority_hash) # deliver the next set of packages
|
||||||
if packagesLeft == 0 and truck3LoadDebounce: # if all the packages are delivered
|
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
|
truck3LoadDebounce = False # set the debouce
|
||||||
truck3.startTime = truck1.getTimeOfDay() # set truck3 start time
|
truck3.startTime = truck1.getTimeOfDay() # set truck3 start time
|
||||||
|
|
||||||
# deliver packages for truck 2
|
# deliver packages for truck 2
|
||||||
if truck2.hasLoad and globalTime >= truck2.getTimeOfDay(): # if there is more packages and the time has passed
|
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
|
truck2.driveNextClosest(priority_hash) # deliver the next set of packages
|
||||||
if packagesLeft == 0 and truck3LoadDebounce: # if all the packages are delivered
|
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
|
truck3LoadDebounce = False # set the debouce
|
||||||
truck3.startTime = truck1.getTimeOfDay() # set truck3 start time
|
truck3.startTime = truck1.getTimeOfDay() # set truck3 start time
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user