示例#1
0
class SC2Remix(object):
    def __init__(self, replay):
        self.replay = replay
#        self.file = self._open(replay)
        self._get_mpq()
        self.archive = None

    def _get_mpq(self):
        try:
            self.mpq = MPQArchive(self.replay)
        except IOError:
            return None

    def _open(self, replay):
        try:
            self.file = open(replay, 'rb')
        except:
            print "Error opening replay."

    def zip(self, path=''):
        self.archive = zipfile.ZipFile(self.mpq.file.name+'.zip','w')
        files = self.mpq.extract()
        for f in self.mpq.files:
            self.archive.writestr(f, files[f])
        self.archive.close()
示例#2
0
def extract_mmr_apm(path, your_id, opponent_id):
    try:
        archive = MPQArchive(path)

        players = json.loads(
            archive.extract()[b'replay.gamemetadata.json'])['Players']

        if "MMR" not in players[opponent_id]:
            players[opponent_id]["MMR"] = "Unknown"
        if "MMR" not in players[your_id]:
            players[your_id]["MMR"] = "Unkown"

        return {
            "yourMMR": str(players[your_id]['MMR']),
            "opponentMMR": str(players[opponent_id]['MMR']),
            "yourAPM": str(players[your_id]['APM']),
            "opponentAPM": str(players[opponent_id]['APM'])
        }
    except Exception:
        traceback.print_exc()
        print("failed to parse mmr/apm for path {}".format(path))
        return {
            "yourMMR": "Unknown",
            "opponentMMR": "Unknown",
            "yourAPM": "Unknown",
            "opponentAPM": "Unknown"
        }
示例#3
0
	def __init__(self, replay_file):
		self.teams 				= []
		self.replay_file		= replay_file
		
		self.parsers			= {}

		try:
			archive = MPQArchive(self.replay_file)
						
			files = archive.extract()

			# bootstrap the right parsers, expand here for different version parsing too
			
			self.parsers['header'] = DetailsParser(archive.header['user_data_header']['content'])
			
			for file_name, data in files.iteritems():
				if(file_name == self.FILES['attributes']):
					self.parsers[file_name] = AttributesParser(data)
						
				if(file_name == self.FILES['details']):
					self.parsers[file_name] = DetailsParser(data)
		
			teams = self.attribute(2001)
			num_teams = 2

			if teams == '1v1':
				teams_lookup_attribute = 2002
				
			elif teams == '2v2':
				teams_lookup_attribute = 2003
				
			elif teams == '3v3':
				teams_lookup_attribute = 2004
				
			elif teams == '4v4':
				teams_lookup_attribute = 2005
				
			elif teams == 'FFA':
				teams_lookup_attribute = 2006
				num_teams = 10
				
			elif teams == '6v6':
				teams_lookup_attribute = 2008
			
			# create the teams before the players
			for i in range(num_teams):
				self.teams.append(Team(i+1))
			
			# bootstrap the player object with some raw data
			for i, player_details in enumerate(self.parsers[self.FILES['details']].parse()[0]):
				
				player = Player(player_details, self.player_attributes(i+1))
								
				# team
				players_team = player.attribute(teams_lookup_attribute)								
				self.teams[int(players_team[1])-1].players.append(player)
				
		except IOError as (errno, strerror):
			print strerror
示例#4
0
def winners(filepath):
    archive = MPQArchive(str(filepath))
    files = archive.extract()
    data = json.loads(files[b"replay.gamemetadata.json"])
    result_by_playerid = {p["PlayerID"]: p["Result"] for p in data["Players"]}
    return {
        playerid: result == "Win"
        for playerid, result in result_by_playerid.items()
    }
def extractResult(filepath):
    archive = MPQArchive(str(filepath))
    files = archive.extract()
    data = json.loads(files[b"replay.gamemetadata.json"])
    #     print(data)
    result_by_playerid = {p["PlayerID"]: p["Result"] for p in data["Players"]}
    #     print(data["Players"])
    #     print(result_by_playerid)
    return {
        playerid: result == "Win"
        for playerid, result in result_by_playerid.items()
    }


# winners("./replays/MyBot_vs_DefaultRandomHard_DreamcatcherLE_11_05_063.SC2Replay")