-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
277 lines (256 loc) · 9.05 KB
/
main.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import pandas as pd
import queue
from queue import PriorityQueue
import WorkOrder
from WorkOrder import WorkOrder
import Worker
from Worker import Worker
import Facility
from Facility import Facility
import sys
workers = []
facility1 = Facility('Fac1',0,0,PriorityQueue(),PriorityQueue())
facility2 = Facility('Fac2',0,0,PriorityQueue(),PriorityQueue())
facility3 = Facility('Fac3',0,0,PriorityQueue(),PriorityQueue())
facility4 = Facility('Fac4',0,0,PriorityQueue(),PriorityQueue())
facility5 = Facility('Fac5',0,0,PriorityQueue(),PriorityQueue())
def updateFacility():
df = pd.read_excel(r'router/RiceHackathonFile.xlsx', sheet_name='Facility Details')
for index, data in df.iterrows():
if data[0] == 'Fac1':
facility1 = Facility(data[0],data[1],data[2],PriorityQueue(),PriorityQueue())
elif data[0] == 'Fac2':
facility2 = Facility(data[0],data[1],data[2],PriorityQueue(),PriorityQueue())
elif data[0] == 'Fac3':
facility3 = Facility(data[0],data[1],data[2],PriorityQueue(),PriorityQueue())
elif data[0] == 'Fac4':
facility4 = Facility(data[0],data[1],data[2],PriorityQueue(),PriorityQueue())
elif data[0] == 'Fac5':
facility5 = Facility(data[0],data[1],data[2],PriorityQueue(),PriorityQueue())
def updateWorkers():
df = pd.read_excel(r'router/RiceHackathonFile.xlsx', sheet_name='Worker Details')
for index, data in df.iterrows():
worker = Worker(data[0],data[1],data[2],None,None)
workers.append(worker)
def updateWorkQueues():
df = pd.read_excel(r'router/RiceHackathonFile.xlsx', sheet_name='Work Order Examples')
#print (df)
for index, data in df.iterrows():
#print(index, row)
work = WorkOrder(data[0],data[1],data[2],data[3],data[4],data[5],data[6],0)
if data[1] == 'Fac1':
facility1.readyQ.put((work.priority,work))
elif data[1] == 'Fac2':
facility2.readyQ.put((work.priority,work))
elif data[1] == 'Fac3':
facility3.readyQ.put((work.priority,work))
elif data[1] == 'Fac4':
facility4.readyQ.put((work.priority,work))
elif data[1] == 'Fac5':
facility5.readyQ.put((work.priority,work))
def getWorkAtFacility(worker): #is returned a work. The work is already set to the activeQ in the facility class.
work = None
if worker.current_facility == 'Fac1':
work = facility1.getWork(worker)
elif worker.current_facility == 'Fac2':
work = facility2.getWork(worker)
elif worker.current_facility == 'Fac3':
work = facility3.getWork(worker)
elif worker.current_facility == 'Fac4':
work = facility4.getWork(worker)
elif worker.current_facility == 'Fac5':
work = facility5.getWork(worker)
#print("hi")
#print(facility1.activeQ.qsize())
if work is None:
#print("HIIIIIIIIIIII GET WORK")
worker.current_facility = None
#worker.current_task = None
work = getWork(worker)
#print(work)
worker.current_facility = work.facility
worker.current_task = work
return work
def getWork(worker):
if worker.current_facility is None:
work1 = facility1.peekWork(worker)
#print("Peeked Work 1")
work2 = facility2.peekWork(worker)
#print("Peeked Work 2")
work3 = facility3.peekWork(worker)
#print("Peeked Work 3")
work4 = facility4.peekWork(worker)
#print("Peeked Work 4")
work5 = facility5.peekWork(worker)
#print("Peeked Work 5")
pq = PriorityQueue()
if work1 is not None:
pq.put(work1)
if work2 is not None:
pq.put(work2)
if work3 is not None:
pq.put(work3)
if work4 is not None:
pq.put(work4)
if work5 is not None:
pq.put(work5)
work = pq.get()
#if work is not None:
# print(work)
# print("work is not none")
# print(work[1].facility)
#if work is None:
# print("FATAL ERROR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`")
if work.facility == 'Fac1':
work = facility1.getWork(worker)
elif work.facility == 'Fac2':
work = facility2.getWork(worker)
elif work.facility == 'Fac3':
work = facility3.getWork(worker)
elif work.facility == 'Fac4':
work = facility4.getWork(worker)
elif work.facility == 'Fac5':
work = facility5.getWork(worker)
if work is None:
print(work)
worker.current_facility = work.facility
worker.current_task = work
return work
else:
getWorkAtFacility(worker)
def retrieveWork(workerName): #takes in a string from server, and returns a work order for them
for worker in workers:
if worker.name == workerName:
print(worker.current_task, end='')
sys.stdout.flush()
def getNewWork(workerName): #delete old work
#print(facility1.activeQ.qsize())
writer = pd.ExcelWriter('router/RiceHackathonFile.xlsx', engine='xlsxwriter')
df1 = pd.read_excel(r'router/RiceHackathonFile.xlsx', sheet_name='Summary')
df1.to_excel(writer, sheet_name='Summary')
df2 = pd.read_excel(r'router/RiceHackathonFile.xlsx', sheet_name='Worker Details')
df2.to_excel(writer, sheet_name='Worker Details')
df3 = pd.read_excel(r'router/RiceHackathonFile.xlsx', sheet_name='Equipment Details')
df3.to_excel(writer, sheet_name='Equipment Details')
df4 = pd.read_excel(r'router/RiceHackathonFile.xlsx', sheet_name='Facility Details')
df4.to_excel(writer, sheet_name='Facility Details')
for worker in workers:
if worker.name == workerName:
work = worker.current_task #REMOVE THE OLD TASK FROM THE DATABASE
df5 = pd.read_excel(r'router/RiceHackathonFile.xlsx', sheet_name='Work Order Examples')
data = df5.loc[:,:]
data = data.drop(int(work.workID)-1001)
data.to_excel(writer, sheet_name='Work Order Examples')
writer.save()
if worker.current_facility == 'Fac1':
facility1.removeActive(worker)
elif worker.current_facility == 'Fac2':
facility2.removeActive(worker)
elif worker.current_facility == 'Fac3':
facility3.removeActive(worker)
elif worker.current_facility == 'Fac4':
facility4.removeActive(worker)
elif worker.current_facility == 'Fac5':
facility5.removeActive(worker)
worker.current_task = None
work = getWorkAtFacility(worker)
print(work, end='')
def stopWork(workerName, time):
for worker in workers:
if worker.name == workerName:
work = None
if worker.current_facility == 'Fac1':
work = facility1.removeActive(worker)
elif worker.current_facility == 'Fac2':
work = facility2.removeActive(worker)
elif worker.current_facility == 'Fac3':
work = facility3.removeActive(worker)
elif worker.current_facility == 'Fac4':
work = facility4.removeActive(worker)
elif worker.current_facility == 'Fac5':
work = facility5.removeActive(worker)
else:
print("should not be here")
work.inProgress += int(time)
if worker.current_facility == 'Fac1':
facility1.readyQ.put((work.priority,work))
elif worker.current_facility == 'Fac2':
facility2.readyQ.put((work.priority,work))
elif worker.current_facility == 'Fac3':
facility3.readyQ.put((work.priority,work))
elif worker.current_facility == 'Fac4':
facility4.readyQ.put((work.priority,work))
elif worker.current_facility == 'Fac5':
facility5.readyQ.put((work.priority,work))
else:
print("should not be here")
print("Success", end='')
def whoIsWhere():
for worker in workers:
print(worker.name, end=': ')
print(worker.current_facility)
def checkQueues():
#while not facility1.readyQ.empty():
# print(facility1.readyQ.get()[1].workID)
#while not facility2.readyQ.empty():
# print(facility2.readyQ.get()[1].workID)
#while not facility3.readyQ.empty():
# print(facility3.readyQ.get()[1].workID)
print("CHECK QUEUE")
temp = PriorityQueue()
count = 0
while not facility4.readyQ.empty():
temp.put(facility4.readyQ.get())
count+=1
print(count)
while not temp.empty():
facility4.readyQ.put(temp.get())
#while not facility5.readyQ.empty():
# print(facility5.readyQ.get()[1].workID)
def main():
updateFacility()
#print('Updated Facilities \n')
updateWorkers()
#print('Updated Workers \n')
updateWorkQueues()
#print('Updated Work Queues \n')
#checkQueues()
for worker in workers:
if worker.current_facility is None:
worker.current_task = getWork(worker)
elif worker.current_facility == 'Fac1':
facility1.readyQ.put((work.priority,work))
elif worker.current_facility == 'Fac2':
facility2.readyQ.put((work.priority,work))
elif worker.current_facility == 'Fac3':
facility3.readyQ.put((work.priority,work))
elif worker.current_facility == 'Fac4':
facility4.readyQ.put((work.priority,work))
else:
facility5.readyQ.put((work.priority,work))
#print(worker.name)
#print(worker.current_facility)
#print(worker.current_task)
#print()
#retrieveWork('Bob')
#print()
#getNewWork('Bob')
#print()
#getNewWork('Bob')
#print()
#getNewWork('Bob')
#whoIsWhere()
#stopWork('Sally','1')
#print("DONE")
if sys.argv[1] == 'retrieveWork':
retrieveWork(sys.argv[2])
if sys.argv[1] == 'getNewWork':
getNewWork(sys.argv[2])
if sys.argv[1] == 'stopWork':
stopWork(sys.argv[2],sys.argv[3])
if sys.argv[1] == 'whoIsWhere':
whoIsWhere()
if __name__== "__main__":
main()
#print (w1.__dict__.keys())
#print (w1.__dict__.values())