From 83b520d2e2695c74dd8c542f8bf7c3ca13457923 Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Tue, 13 Jan 2026 18:07:01 -0800 Subject: [PATCH] Fix assignment --- .vscode/launch.json | 15 +++++++++++ Truck.py | 30 +++++++++++++-------- UI.py | 7 +++-- __pycache__/AssignmentData.cpython-314.pyc | Bin 9719 -> 9710 bytes __pycache__/DeliveryObject.cpython-314.pyc | Bin 2147 -> 2138 bytes __pycache__/MyHashTable.cpython-314.pyc | Bin 2631 -> 2622 bytes __pycache__/MyLinkedList.cpython-314.pyc | Bin 3543 -> 3534 bytes __pycache__/Truck.cpython-314.pyc | Bin 6370 -> 6809 bytes __pycache__/UI.cpython-314.pyc | Bin 7974 -> 8024 bytes main.py | 25 ++++++++++------- 10 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 .vscode/launch.json 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 38c7ad268a7871142d95c678eee1971963a32da4..4abaeaa83dd46c840f8bfb5ea9621c7142204e2f 100644 GIT binary patch delta 38 scmezF{mz?Pn~#@^0SG4CP20%Lq`+gLpOK%Ns-Kctl$yO+N#QCh0Ncw8tpET3 delta 47 zcmaFo{oR{en~#@^0SI)%6E<=)DTq4ihZd(673-&@7Nurq4dKO;XkRX-)QC^dWYF2uvQLCtn~#@^0SG4CP20#F#K>c+pOK%Ns-Kctl$yP{i18{10K*vzK>z>% delta 47 zcmdlda$JO4n~#@^0SL^##c$*eVidL04=qkDD%MX)ElSPK$j`~iFHfx8oXL2V0{}FQ B4%z?! diff --git a/__pycache__/MyLinkedList.cpython-314.pyc b/__pycache__/MyLinkedList.cpython-314.pyc index 11cf59e74a9f189ca78e2e30e1b5f409c43a9c12..82a9fb704a574bb60a0a64a662870eb1d8411ae7 100644 GIT binary patch delta 38 scmcaEeNLKNn~#@^0SG4CP20#V%gAGneO;Pcn~#@^0SJD@$86-5WfZm74=qkDD%MX)ElSPK$j`~iFHfx8Y{EE;2LL diff --git a/__pycache__/Truck.cpython-314.pyc b/__pycache__/Truck.cpython-314.pyc index d2515eaefde0d0e8f78e1fc1c2c67bc5695fa7a8..51923592c846d787cccfcb88447eae459c4982f1 100644 GIT binary patch delta 1714 zcmaJ>TWk|Y6us;9+v`W{jcr2kD-UM_QHY$Vgn&vKk^;fVERoZKi5g-PEQqt6n2M(Y z>POR`0ve#6T+W9!MbMEzc z?wxbyx3;Stj`a?^6>u#6eK_k2%sGmj(As)rd@R$N&XCN}o6oqo#cIR^9>Ba@L-*SH zJiN@e9SXGTD$J&Da2GsCE%Yk@DfdbqEeKwxE@#tzrv1g56(Xt2 z39GR#E>S~o2z7S*Du)af!RvAk`il_IC4#iu5NPYa4`6`+$hta^^bfHFcqR^#@!V)= zIGrY$iHXp$>_k43-t+J|4#`D7um_vUhTM2QGeH_KopdqS!hp53Y}wwsduOs&?%htB z=(qMr4X=zV5>M8#AeSX!oF`bP8$o_E#VIPv+}&(6-ux83v6ElaK~KZje3 z;m$(1^J35CU8P84F%m08V)Ky>T=$nme^G4uNo<{hq*Ex6!^@i|c244govFXl^@8WmjDnrj0vzq$~tjdwLdA#(V#Y~^;1EK#^ z+cp5ywTX#jQs2&mfFlU~`ziuSRaF?Ke=VvQWSwG6d9+AUr$vTf(^~*(ylZp=?y6<1 z&Z%ncTQ3Kfr*X7zWIW zvHzV)laheWt7rSHGi-R_J%Ho7oMvQ58Y@n8!pn|LMA?HuuZdR9Lr+-(^qkEyS!p6Z zHMJlclaLd&lQFldjy01vkt_4r+~GZhh0Act+_rIZY-6Z9-bZ#IBUKYG3z$YT`JMU9 z7-5Yk5`%sQuX?y_IDBk;I8W*^G(rq4;Q#~H6vE!KGCwwa0wJ3tgKTL} z876t+XL+bgAU*`iuG*g9O+i^uNOqiL^CuHWM<>es$Z=BU-lJEm`%J7;jrbh=QQc`& zokD26w|laB&Gf;`2QPBW{NY>Cx#)t}`G4jwiJ_txEr`(>Zb@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_2YFsY%kNUl+<>p)lhChIWR2c;yY^I265O_Grb4awO%}3*wlVl zV`YWOwG<^Om7bV2PY{wLWRMEFQohn@<_I%1GUyC(sP+eO4;=Ly^lkV28`xFe%Z4mW zvS0*S@Hx00XysLY*JcP_2WsngR$AG7l7anW;-e_pW0See?1Y&hGq4@d+=CXJ#J|wa Hv19uOURbbY delta 718 zcmY+BO-vI(6oBV-yFcA_q0ps8Kq|C>)}jDl=SAw#AssFo6$H^!ofLw`{sLpo87JWYFvxdX)0l7 zd2Bq_x~{DXO#{8BOBOBlW-V$>PZjg|;zDMz@?01Kc#41Q20X?C;yy^@CD90`rIf&?1uNzYE}kqGE?SgoOyVbX7l`;1Y zkNm;YeIs#w7?+%3&Ho^GH}?pZ$G#JY;49~#BoICHs}7$iot3?=gaCawQ-59>;QL~@ zS%0?UAPd>MG;m{Z=o}G_9*zVab*CU+x##{X2vvyTeLV_?@r~}44)Odk{G$88K(%QS z&Q)mBI7lPhCvnR=3bU1<@0)#a+i=~%P*u~JeAybIv`A@+3HEJj`%m$TZjKN~n8Uym zZGK2%q0MB|UbJn1dwVZW@@6`P*V?0S2A{R}i>lc8qXoaVcLZxI?L2>(ga0?`W2h>F Zg<`gxx8igT`~2R9lns*blhhuyvVR@;qR9XN 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