-
Notifications
You must be signed in to change notification settings - Fork 1
/
manual_labeller.py
65 lines (55 loc) · 1.72 KB
/
manual_labeller.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
#!/usr/bin/python
import compute_stats
import collections
import random
import simplejson as json
import pprint
def IsInt(v):
try:
y = int(v)
return True
except:
return False
def GetLabels(keys, name):
good_input = False
while not good_input:
good_input = True
x = raw_input('label(s) for ' + name + ': ')
vals = x.split()
ret = []
for val in vals:
if IsInt(val):
val = int(val)
if 0 <= val < len(keys):
ret.append(keys[val])
else:
good_input = False
print 'bad index', val
break
else:
print 'warning new key', val
keys.append(val)
keys.sort()
ret.append(val)
good_input = good_input and len(ret) > 0
return ret
def main():
games = map(compute_stats.Game, json.load(open('terse_games.json', 'r')))
keys, labelled_games = compute_stats.ReadLabels()
random.shuffle(games)
output_file = open('golden_labels2.csv', 'a', 0)
for game in games:
if game.GameNo() in labelled_games:
print 'skipping labelled game', game
continue
print game
for idx, key in enumerate(keys):
print idx, key
for player_result in game.PlayerList():
labels = GetLabels(keys, player_result.Name())
output_file.write(
'%s,%d,%s\n' % (player_result.Name(), game.GameNo(),
','.join(labels))
)
if __name__ == '__main__':
main()