-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cook.py
36 lines (29 loc) · 1.17 KB
/
Cook.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
class Cook:
cur_id = 0
def __init__(self, requests_queue, distribution):
self.work_time_distribution = distribution
self.busy = False
self.requests_queue = requests_queue
self.current_req = None
self.time_to_finish = 0
self.id = Cook.cur_id
Cook.cur_id += 1
def upd_time(self, dt):
res = ''
if self.busy:
self.time_to_finish -= dt
# Еще занят, но время работы закончилось
if self.time_to_finish <= 1e-5:
#print(self.current_req.id, 'cook', self.id, 'fin')
res = self.current_req.type
if res == 'inside':
self.current_req.eat()
self.busy = False
self.current_req = None
# Свободен, а в очереди есть заявки
if not self.busy and len(self.requests_queue):
self.current_req = self.requests_queue.pop(0)
#print(self.current_req.id, 'cook', self.id, 'accepted')
self.time_to_finish += self.work_time_distribution.generate()
self.busy = True
return res