-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.py
177 lines (150 loc) · 5.38 KB
/
package.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import enum
class Package:
"""
Package class to manage packages for simulation
"""
class STATUS(enum.Enum):
at_depot = 0
on_truck = 1
delivered = 2
not_arrived = 3
unknown = 4
def __str__(self):
return self.name
def __init__(self,
package_id=None,
package_mass=0,
package_dest_city="not set",
package_dest_state="not set",
package_expected_delivery_time="None",
package_dest_zipcode="not set",
package_dest_address="not set",
package_deliver_notes=None):
self._delivery_address = package_dest_address
self._id = int(package_id) # package_id has to be an integer for hashtable
self._weight = package_mass
self._delivery_status = Package.STATUS.not_arrived
self._dest_city = package_dest_city
self._dest_deadline = package_expected_delivery_time
self._dest_state = package_dest_state
self._dest_zipcode = package_dest_zipcode
self._delivery_notes = package_deliver_notes
self._arrival_time = 0
self._delivery_truck = None
self._delivery_location = None
self._delivery_time = None
@property
def id(self):
"""O(1) Time O(1) Space
package_id has to be an integer for hashtable"""
return int(self._id)
@property
def weight(self):
"""O(1) Time O(1) Space
return the package weight"""
return self._weight
@property
def status(self) -> STATUS:
"""O(1) Time O(1) Space
return the status of a package"""
return self._delivery_status
@status.setter
def status(self, value):
"""O(1) Time O(1) Space
set the status of the package based on enum STATUS"""
if isinstance(value, self.STATUS):
self._delivery_status = value
else:
raise ValueError
@property
def delivery_address(self):
"""O(1) Time O(1) Space
return the delivery address for the package"""
return self._delivery_address
@delivery_address.setter
def delivery_address(self, value):
"""O(1) Time O(1) Space
set the delivery address for the package"""
self._delivery_address = value
@property
def dest_city(self):
"""O(1) Time O(1) Space
return the destination city for the package """
return self._dest_city
@dest_city.setter
def dest_city(self, value):
"""O(1) Time O(1) Space
set the destination city for the package"""
@property
def delivery_notes(self):
"""O(1) Time O(1) Space
return the delivery notes for the package"""
return self._delivery_notes
@delivery_notes.setter
def delivery_notes(self, value):
"""O(1) Time O(1) Space
set the delivery notes for the package"""
self._delivery_notes = value
@property
def delivery_location(self):
"""O(1) Time O(1) Space
return the delivery location for the package"""
return self._delivery_location
@delivery_location.setter
def delivery_location(self, value):
"""O(1) Time O(1) Space
set the delivery location for the package"""
self._delivery_location = value
@property
def delivery_truck(self):
"""O(1) Time O(1) Space
return the delivery truck the package used"""
return self._delivery_truck
@delivery_truck.setter
def delivery_truck(self, value):
"""O(1) Time O(1) Space
set the delivery truck the package used"""
self._delivery_truck = value
@property
def dest_zipcode(self):
"""O(1) Time O(1) Space
return Destination Zipcode"""
return self._dest_zipcode
@property
def arrival_time(self):
"""O(1) Time O(1) Space
Return the Time the package shows up at the depot in seconds after 8:00AM"""
return self._arrival_time
@arrival_time.setter
def arrival_time(self, value):
"""O(1) Time O(1) Space
Set the Time the package shows up at the depot in seconds after 8:00AM"""
self._arrival_time = value
@property
def delivery_time(self):
"""O(1) Time O(1) Space
Return the time the package was delivered or None of not delivered"""
return self._delivery_time
@delivery_time.setter
def delivery_time(self, value):
"""O(1) Time O(1)
Space set the time the package was delivered or None if not delivered"""
self._delivery_time = value
@property
def deadline(self):
"""O(1) Time O(1) Space When the package should arrive by"""
if self._dest_deadline == "EOD":
return "EOD"
if "10:30" in self._dest_deadline:
return "10:30AM"
if "9:00" in self._dest_deadline:
return "9:00AM"
raise ValueError(f"Didn't expect {self._dest_deadline}")
def __str__(self):
return self.__repr__()
def __repr__(self):
if self.delivery_truck is None:
truck = "None"
else:
truck = self.delivery_truck.truck_info['name']
return f"Package ID: {self.id} Destination Address: {self.delivery_address}, Weight: {str(self.weight)}, Truck: {truck}, Status: {self.status}, Deadline: {self.deadline} Delivered: {self.delivery_time} "