-
Notifications
You must be signed in to change notification settings - Fork 0
/
Service.py
39 lines (29 loc) · 1008 Bytes
/
Service.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
import Data;
import SimObject;
services = {};
class Service(SimObject.SimObject):
def __init__(self, attrs, name, orders):
SimObject.SimObject.__init__(self, attrs);
self.name = name;
self.orders = orders;
# add a new order to our orders
def Append(self, order):
self.orders.append(order);
# returns a new service that starts the specified amount of time later
def Add(time, service):
return Service(service.attrs, service.name, list((order[0] + time, order[1]) for order in service.orders));
# turns a list of service names into an actual schedule
def TrainSchedule(serviceNames):
result = [];
for name in serviceNames:
try:
for order in services[name].orders:
result.append((order[0], Data.Place(order[1])));
except KeyError:
print(services);
# sort before getting the start and end for the best results
result.sort();
# add orders for the start and end of the day
result.insert(0, (0, result[0][1]));
result.append((1560, result[-1][1]));
return result;