-
Notifications
You must be signed in to change notification settings - Fork 1
/
collect.py
executable file
·77 lines (69 loc) · 2.48 KB
/
collect.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
#!/usr/bin/env python3
"""
A command-line utility for gathering data. Only a collector name is required:
./collect.py ssa
By default the random bot is used to wander across the training level. Another
bot or level can be selected using --bot (name and params key) and --level.
Collectors vary greatly in what they do. They usually have a matching processor
or trainer that can make use of the collected data.
"""
from core import available_collectors, do_collect
from iop import date_desc, level_desc, parse_args, time_desc
description = "Collect data from a level."
arguments = (
(('collector',), {
'choices': available_collectors.keys(),
'help': "collector to use"
}),
(('-l', '--level'), {
'default': 'train',
'help': "level to collect from (levels/<level>_level.data)"
}),
(('-b', '--bot'), {
'nargs': 2,
'default': ['random', None],
'help': "bot and params key that will be used to wander the level"
}),
(('-i', '--iterations'), {
'type': int,
'default': 1,
'help': "level runs to make, amount of data to collect"
}),
(('-s', '--prngs_seed'), {
'type': int,
'default': None,
'help': "fixed seed for all pseudo-random number generators"
}),
(('-o', '--output'), {
'default': None,
'help': "file suffix in data/<collector>_<output>.npz"
}),
(('-v', '--verbosity'), {
'type': int,
'default': 1,
'help': "0 = condensed, 1 = expanded, 4+ = debugging info"
}),
(('-p', '--precision'), {
'type': int,
'default': None,
'help': "how many decimal digits of floats to print"
})
)
if __name__ == '__main__':
args = parse_args(description, arguments)
for iteration in range(args.iterations):
data, info = do_collect(**vars(args))
if args.verbosity == 0:
info['level'] = info['level']['key']
out = "{collector} {level} {output}".format(**info)
else:
info['date'] = date_desc(info['date'])
info['level'] = level_desc(info['level'])
info['time'] = time_desc(info['time'], args.precision)
out = ("\nDate: {date}\n" +
"Collector: {collector}\n" +
"Level: {level}\n" +
"Bot: {bot[0]} {bot[1]}\n" +
"Time: {time}\n" +
"Output: {output}, PRNGs: {prngs_seed}\n").format(**info)
print(out, flush=True)