-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
33 lines (28 loc) · 1.21 KB
/
logger.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
class Logger:
def __init__(self):
self.commands = {}
def append_command(self, t, command):
clist = self.commands.get(t, [])
clist.append(command)
self.commands[t] = clist
def write_to_file(self, t_max, s):
fname = 'out{}.txt'.format(s)
linear = []
for t in range(t_max):
if t in self.commands:
linear.extend(self.commands[t])
with open(fname, 'w') as f:
f.write('{}\n'.format(len(linear)))
for cmd in linear:
cmd_name = cmd['name']
if cmd_name == 'load':
f.write('{} L {} {} {}\n'.format(cmd['drone_id'],
cmd['warehouse_id'],
cmd['prod_id'],
cmd['prod_count']))
elif cmd_name == 'deliver':
f.write('{} D {} {} {}\n'.format(cmd['drone_id'],
cmd['order_id'],
cmd['prod_id'],
cmd['prod_count']))
f.flush()