Introduction
In this chapter I define the module summarise_rpl
and I reviews how to extract a Replay's
metadata with sc2reader
. This metadata will allow me to index the replays when they are processed to group them by player and race to construct the players' profiles.
Exported Functions
- get_replay_info
The Replay
Object
sc2reader
loads replay files into Repaly
objects. Once these objects are defined, users can access their data in two ways.
The user can access descriptive information about a
Replay
by calling on some of the object's attributes. This data is useful for indexing and organising purposes.Second, the
Replay
can provide access to other objects representing the different events, entities and behaviours that make up a StarCraft II match. This data is helpful to calculate and compose the player's performance indicators.
The following code shows how one can load a Replay
into a variable.
rps_path = Path("./test_replays")
game_path = str(rps_path/"Jagannatha LE.SC2Replay")
single_replay = sc2reader.load_replay(game_path)
single_replay
Having defined the object, I can summarise the match's descriptive information as shown in the following code.
print(f'File path: {single_replay.filename}')
print(f'File hash: {single_replay.filehash}')
print(f'Version of the game in which the replay was played: ',
f'{single_replay.release_string}')
print(f'Expansion (WoL: Wingd of Liberty, HotS: Heart of the Swarm, ',
f'LotV: Legacy of the Void): {single_replay.expansion}')
print(f'Game region: {single_replay.region}')
print(f'Game category: {single_replay.category}')
print(f'Game type: {single_replay.game_type}')
print(f'Map: {single_replay.map_name}')
print(f'Date start (datetime.datetime): {single_replay.start_time}')
print(f'Date end (datetime.datetime): {single_replay.end_time}')
print(f'Duration in MM.SS (minutes.seconds): {single_replay.game_length}')
print(f'Duration in MM.SS (minutes.seconds): ',
f'{type(single_replay.length.seconds)}')
print(f'Duration in frames: {single_replay.frames}')
print(f'Frames per Second: {single_replay.game_fps}')
print(f'Players dict: {single_replay.player}')
print(f'Winner : {single_replay.winner}')
The Participant
Object
Beyond the information contained in a Replay's
attributes, users can call upon the Participant
objects associated with it to complement this data. These Participant
objects record the match's players, what races they played with, and their results.
- A Participant is a Player and a User
- An Observer is a User and not a Player
- A Computer is a Player and not a User
With this in mind, here I access the match participans' information as follows:
player_one = single_replay.player[1]
player_two = single_replay.player[2]
type(player_one)
This way I locate the each Participant
within a variable, which allows me to extract meaningful information from these objects, as I show bellow.
print(f'User Name: {player_one.name}')
print(f'Race played in match: {player_one.play_race}')
print(f'Match result: {player_one.result}')
print(f'Player ID: {player_one.pid}')
print(f'User Name: {player_two.name}')
print(f'Race played in match: {player_two.play_race}')
print(f'Match result: {player_two.result}')
print(f'Player ID: {player_two.pid}')
Data structures
First, I define a couple of frozen datacasses that can store the data I will extract from the Replay
.
The Player_data
class will store a sumary of each player's basic information.
The following is an example of this class.
p_one = Player_data(single_replay.player[1].pid,
single_replay.player[1].name,
single_replay.player[1].play_race,
single_replay.player[1].result)
print(p_one)
Meanwhile, the Replay_data
class stores the information on the match. This includes a list of Player_data
instances that consolidate the information of the match's players in a single location.
Helper Functions
To illustrate how this dataclass works, let me define a helper function (get_players
) to iterate through the match's list of players converting each one into a Player_data
instance and returning a new list with this summaries.
With this function, I can store a summary of the matches meta-data in a Replay_data
instance like this:
match = Replay_data(
replay_name= single_replay.filename,
replay_id= Path(single_replay.filename).name,
date_time= single_replay.date,
game_length= single_replay.length.seconds,
match_type= single_replay.game_type,
game_release= single_replay.release_string,
map_name= single_replay.map_name,
category= single_replay.category,
winner= single_replay.winner,
players= get_players(single_replay.player)) # note the use of the
# helper function here
print(match)
Exported Functions
Having defined these data structures, I define the get_replay_info
function which receives a Replay
and returns its summary as a Replay_data
instance.
The following code demonstrates the use of this function.
match = get_replay_info(single_replay)
print(match)
References
- Kim, G. (2015) 'sc2reader Documentation'. Available at: https://sc2reader.readthedocs.io/_/downloads/en/latest/pdf/.