-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgenerate_data.py
67 lines (50 loc) · 1.96 KB
/
generate_data.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
import argparse
from multiprocessing import Pool
import generalsim
from os import listdir
from os.path import isfile, join
import pickle
import numpy as np
REPORT_INTERVAL = 10000
# Currently only extracting games between 2 players
# with greater than 80 stars
NUM_PLAYERS = 2
STAR_TRESH = 80
def extract_game(f_name):
game_x, game_y, game_z = [], [], []
if f_name.endswith(".gioreplay"):
game = generalsim.GeneralSim(f_name)
status = game.add_log(STAR_TRESH, NUM_PLAYERS)
if status:
while not game.step():
pass
game_x, game_y, game_z = game.export_log()
return game_x, game_y, game_z
def extract_data(l_f, threads):
"""Extracts data from a list of gioreplay"""
pool = Pool(threads)
mapped_data = pool.map(extract_game, l_f)
x, y, z = zip(*mapped_data)
return x, y, z
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--processes", type=int, default=None)
parser.add_argument("--data", type=str, default="replays_prod",
help="directory where the gioreplay files are stored")
parser.add_argument("--stars", type=int, default=90,
help="threshold for stars to parse games from")
parser.add_argument("--players", type=int, default=2,
help="number of players needed so that we parse games")
args = parser.parse_args()
NUM_PLAYERS = args.players
STAR_TRESH = args.stars
print("Finding all gioreplay files...")
f_list = [join(args.data, f) for f in listdir(args.data) if isfile(join(args.data, f))]
print("Extracting data from all gioreplay files...")
x, y, z = extract_data(f_list, args.processes)
x = list(filter(lambda x: True if x else False, x))
y = list(filter(lambda y: True if y else False, y))
z = list(filter(lambda z: True if z else False, z))
np.savez("data_x", x)
np.savez("data_y", y)
np.savez("data_z", z)