-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMedicalVehicle.py
185 lines (140 loc) · 5.82 KB
/
MedicalVehicle.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
178
179
180
181
182
183
184
185
import time
import random
def equal_locations(list_location, tuple_location):
return list_location[0] == tuple_location[0] and list_location[1] == tuple_location[1]
class MedicalVehicle:
def __init__(self, ident, type_vehicle, hospital_base):
self.id = ident
self.type_vehicle = type_vehicle
self.fuel = self.max_fuel = 5000
self.medicine = self.max_medicine = 200
self.status = "Available" # (Available, Assigned, Rest, Replenish)
self.hospital_base = hospital_base
self.location = list(hospital_base.get_location())
self.minMedicine = 30
self.minFuel = 1000
self.emLocation = None
self.emHospital = None
self.work_km = 0
self.max_km = 20000 # can move for 72s straight. "Real" time is 200 hours
self.rest = 4 # stays ~11 seconds in rest. "Real" rest time is ~11 hours
self.help_v = False
self.temp_help = False
def get_id(self):
return self.id
def get_type_vehicle(self):
return self.type_vehicle
def get_fuel(self):
return self.fuel
def get_medicine(self):
return self.medicine
def get_hospital_base(self):
return self.hospital_base
def get_min_medicine(self):
return self.minMedicine
def get_min_fuel(self):
return self.minFuel
def decrease_fuel(self, amount):
self.fuel -= amount
if self.fuel <= self.minFuel:
self.change_status("Replenish")
def get_status(self):
return self.status
def change_status(self, status):
self.status = status
def get_location(self):
return self.location
def get_em_location(self):
return self.emLocation
def get_em_hospital(self):
return self.emHospital
def set_em_location(self, location):
self.emLocation = location
def set_em_hospital(self, hospital):
self.emHospital = hospital
def set_help_v(self, help_v):
self.help_v = help_v
def set_temp_help(self, f):
self.temp_help = f
def get_temp_help(self):
return self.temp_help
def update_work_km(self, amount):
self.work_km += amount
def get_work_km(self):
return self.work_km
def get_max_km(self):
return self.max_km
def get_rest(self):
return self.rest
def check_vehicle_status(self):
if self.status == 'Available' and self.location == self.emHospital and self.work_km > 0:
self.work_km -= 10
if self.work_km < 0:
self.work_km = 0
elif self.status == 'Rest':
if self.rest > 0:
self.rest -= 1
else:
self.status = 'Available'
self.rest = 30
self.work_km = 0
def medicine_needed(self, gravity, emer_type):
# gravity varies on a scale of 1 to 10; type can be LT or non-LT
if emer_type == "Life-threatening":
e_type = 2
else:
e_type = random.randint(0, 1)
return random.randint(e_type * gravity, e_type * gravity + 10) # medicine needed will be, at max, 30
def decrease_medicine(self, gravity, emer_type):
amount = self.medicine_needed(gravity, emer_type)
self.medicine = self.medicine - amount
if self.medicine <= self.minMedicine:
self.change_status("Replenish")
# Advances one coordinate
def update_location(self, start, dest):
if start[0] < dest[0]:
start[0] += 1
elif start[0] > dest[0]:
start[0] -= 1
else:
if start[1] < dest[1]:
start[1] += 1
elif start[1] > dest[1]:
start[1] -= 1
self.location = start
self.decrease_fuel(1)
self.update_work_km(1)
def move(self, emergency, collab):
eid = emergency.get_eid()
# Move from location to emergency
while not equal_locations(self.location, self.emLocation):
self.update_location(self.location, self.emLocation)
time.sleep(0.0036)
# Vehicles move 1 km in 0.0036 seconds <=> 36 seconds of real-life time.
# Real-life constant speed is 100 km/h (given that 0.36 seconds <=> 1 hour of real-life time)
print(self.type_vehicle, "vehicle", self.id, "arrived to emergency nº", eid)
self.decrease_medicine(emergency.get_gravity(), emergency.get_type())
# Move from emergency location to emergency's hospital
while not equal_locations(self.location, self.emHospital.get_location()):
self.update_location(self.location, self.emHospital.get_location())
time.sleep(0.0036)
print(self.type_vehicle, "vehicle", self.id, "dropped patient at the hospital, in emergency nº", eid)
if self.help_v and collab:
# If it is a backup vehicle, it goes back to base hospital in its zone
while not equal_locations(self.location, self.hospital_base.get_location()):
self.update_location(self.location, self.hospital_base.get_location())
time.sleep(0.0036)
print(self.type_vehicle, "vehicle", self.id, "provided backup for zone with emergency nº", eid, " and will now return to its base hospital")
self.help_v = False
if self.status == 'Replenish':
self.replenish()
print(self.type_vehicle, "vehicle", self.id, "replenished fuel and medicine at the hospital")
elif self.status == 'Assigned':
self.change_status('Available')
if self.work_km >= self.max_km:
self.change_status('Rest')
print(self.type_vehicle, "vehicle", self.id, "entered Rest mode")
def replenish(self):
self.fuel = self.max_fuel
self.medicine = self.max_medicine
self.change_status("Available")