def parseData(path): """ Returns a list of feature vectors and a list of classes for each replay file in the given path. """ data = [] targets = [] for index, filename in enumerate(os.listdir(path)): if os.path.splitext(filename)[-1] == '.SC2Replay': fullpath = os.path.join(path, filename) try: replay = sc2reader.load_replay(fullpath) print "Loading replay %s" % replay.filename log.loadReplay(replay) #Get data from the first 5 minutes of the replay frames = 5*framesPerMinute if replay.frames >= frames and len(replay.players) == 2: player1race = re.search(pattern, str(replay.players[0])) player2race = re.search(pattern, str(replay.players[1])) if player1race.group(0) in race and player2race.group(0) in race: targets.append(race[player1race.group(0)]) targets.append(race[player2race.group(0)]) data.append(gamelog(replay, endFrame=frames, classify=abilityID, framesPerRow=frames).getColumn(0)) data.append(gamelog(replay, endFrame=frames, classify=abilityID, framesPerRow=frames).getColumn(1)) except MPQError: print "Failed to load replay %s" % fullpath return (data, targets)
def abilityID(event): """ Returns the event's ability ID. This function is passed to gamelog to classify events accoring to ability ID. """ if hasattr(event, 'ability_id'): return u'%i' % event.ability_id else: return None #The classifier we use to assign events to columns archive = os.path.join(mainPath, 'abilities.txt') with open(archive, 'r') as infile: abilities = json.load(infile) abilityidClassifier = eventClassifier(abilities, abilityID) log = gamelog(abilityidClassifier, end=frames, framesPerRow=frames) #Load and parse the training data def parseData(path): """ Returns a list of feature vectors and a list of classes for each replay file in the given path. """ data = [] targets = [] for index, filename in enumerate(os.listdir(path)): if os.path.splitext(filename)[-1] == '.SC2Replay': fullpath = os.path.join(path, filename) try: replay = sc2reader.load_replay(fullpath) print "Loading replay %s" % replay.filename