-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStation.py
55 lines (41 loc) · 1.6 KB
/
Station.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
"""Contains Station and Task classes"""
from typing import NewType, Optional
from .Order import OrderId
from .Item import ItemId
from .TaskStatus import TaskStatus
StationId = NewType('StationId', int)
TaskId = NewType('TaskId', int)
class Station():
"""Stations process partial orders"""
def __init__(self, station_id: StationId, order_id: Optional[OrderId] = None):
self.station_id = station_id
self.order_id = order_id
def assign_order_id(self, order_id: OrderId):
self.order_id = order_id
def clear_station(self):
self.order_id = None
def has_order(self):
return self.order_id is not None
def is_available(self):
return self.order_id is None
def __repr__(self):
if self.is_available():
return f'Station {self.station_id}: AVAILABLE'
return f'Station {self.station_id}: Order {self.order_id}'
class Task():
"""Tasks are directives of Item X to Station Y"""
def __init__(self, task_id: TaskId, station_id: StationId,
order_id: OrderId, item_id: ItemId, quantity: int, status: TaskStatus):
self.task_id = task_id
self.station_id = station_id
self.order_id = order_id
self.item_id = item_id
self.quantity = quantity
self.status = status
def is_complete(self):
return self.status == TaskStatus.COMPLETE
def is_error(self):
return self.status == TaskStatus.ERROR
def __repr__(self):
return (f'Task {self.task_id} [{self.status}]: '
f'Item {self.item_id}x{self.quantity} to Station {self.station_id}')