Skip to content

Commit ce2dcd9

Browse files
committed
All tests passing with only minor changes.
Now its time to write better tests. This massive commit consolidates all the replay processors into one giant replay processor function that can operate on any set of file reads. Configuration options for full, partial, basic, minimal, and none file reads have been added to the config.files variable to customize sc2reader usage.
1 parent 300eb99 commit ce2dcd9

File tree

5 files changed

+266
-118
lines changed

5 files changed

+266
-118
lines changed

sc2reader/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import config
3030
import objects
3131
import utils
32+
import processors
3233
import exceptions
3334

3435

@@ -45,16 +46,11 @@ def __init__(self, **user_options):
4546
It should support any arbitrary number of different Reader objects.
4647
"""
4748
self.options = config.default_options.copy()
48-
self.sys = utils.AttributeDict()
4949
self.configure(**user_options)
5050

5151
def configure(self, **options):
5252
self.options.update(options)
5353

54-
# Depending on the options choosen, the system needs to update related
55-
# options and setting in order to get the reading right.
56-
self.sys = config.full if self.options.parse_events else config.partial
57-
5854
def read(self, location, **user_options):
5955
""" Read indicated file or recursively read matching files from the
6056
specified directory. Returns a replay or a list of replays depending
@@ -107,7 +103,7 @@ def read(self, location, **user_options):
107103
archive = mpyq.MPQArchive(location, listfile=False)
108104

109105
# These files are configured for either full or partial parsing
110-
for file in self.sys.files:
106+
for file in options.files:
111107

112108
# For each file, we build a smart buffer object from the
113109
# utf-8 encoded bitstream that mpyq extracts.
@@ -143,7 +139,7 @@ def read(self, location, **user_options):
143139
#
144140
# TODO: Maybe we should switch this to a hook based architecture
145141
# Needs to be able to load "contrib" type processors..
146-
for process in self.sys.processors+self.options.processors:
142+
for process in [processors.Full]+options.processors:
147143
replay = process(replay)
148144

149145
replays.append(replay)

sc2reader/config.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22
from .readers import *
33
from .utils import AttributeDict
44

5+
ALL_FILES = [
6+
'replay.initData',
7+
'replay.details',
8+
'replay.attributes.events',
9+
'replay.message.events',
10+
'replay.game.events'
11+
]
12+
13+
files = AttributeDict(
14+
all=[
15+
'replay.initData',
16+
'replay.details',
17+
'replay.attributes.events',
18+
'replay.message.events',
19+
'replay.game.events'],
20+
21+
partial=[
22+
'replay.initData',
23+
'replay.details',
24+
'replay.attributes.events',
25+
'replay.message.events',],
26+
27+
basic=[
28+
'replay.initData',
29+
'replay.details',
30+
'replay.attributes.events'],
31+
32+
minimal=[
33+
'replay.initData',],
34+
35+
none=[]
36+
)
37+
538
default_options = AttributeDict(
639
directory="",
740
processors=[],
@@ -12,9 +45,11 @@
1245
exclude_dirs=[],
1346
recursive=True,
1447
depth=-1,
15-
follow_symlinks=True
48+
follow_symlinks=True,
49+
files=files.all
1650
)
1751

52+
"""
1853
full = AttributeDict(
1954
files = [
2055
'replay.initData',
@@ -49,6 +84,7 @@
4984
RecorderProcessor,
5085
],
5186
)
87+
"""
5288

5389
class ReaderMap(dict):
5490
def __init__(self):

sc2reader/objects.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
MapData = namedtuple('MapData',['unknown','realm','map_hash'])
1414
PlayerData = namedtuple('PlayerData',['name','bnet','race','color','unknown1','unknown2','handicap','unknown3','result'])
1515
ColorData = namedtuple('ColorData',['a','r','g','b'])
16-
BnetData = namedtuple('BnetData',['unknown1','subregion','unknown2','uid'])
16+
BnetData = namedtuple('BnetData',['unknown1','unknown2','subregion','uid'])
1717
PacketData = namedtuple('Packet',['time','pid','flags','packet'])
1818
PingData = namedtuple('Ping',['time','pid','flags','x','y'])
1919
MessageData = namedtuple('Message',['time','pid','flags','target','text'])
@@ -67,9 +67,11 @@ def __init__(self, replay_file, **options):
6767
self.events = list()
6868
self.events_by_type = defaultdict(list)
6969
self.results = dict()
70-
self.teams = defaultdict(list)
70+
self.teams = list()
71+
self.team = dict()
7172
self.observers = list() #Unordered list of Observer
7273
self.players = list() #Unordered list of Player
74+
self.player = PersonDict()
7375
self.people = list() #Unordered list of Players+Observers
7476
self.humans = list() #Unordered list of Human People
7577
self.person = PersonDict() #Maps pid to Player/Observer
@@ -161,15 +163,15 @@ def __init__(self, time, player, x, y):
161163

162164
class Message(object):
163165

164-
def __init__(self, time, pid, target, text):
165-
self.time, self.sender_id, self.target, self.text = time, pid, target, text
166+
def __init__(self, time, sender, target, text):
167+
self.time,self.sender,self.target,self.text = time,sender,target,text
166168
self.seconds = time/16
167169
self.sent_to_all = (self.target == 0)
168170
self.sent_to_allies = (self.target == 2)
169171

170172
def __str__(self):
171173
time = ((self.time/16)/60, (self.time/16)%60)
172-
return "%s - Player %s - %s" % (time, self.sender_id, self.text)
174+
return "%s - Player %s - %s" % (time, self.sender.pid, self.text)
173175

174176
def __repr__(self):
175177
return str(self)
@@ -227,6 +229,8 @@ def __init__(self, pid, name, replay):
227229
self.aps = defaultdict(int)
228230
self.apm = defaultdict(int)
229231
self.avg_apm = 0
232+
# self.result = "Win","Loss","Unknown"
233+
# self.team = Team()
230234
# TODO: set default external interface variables?
231235

232236
@property
@@ -239,6 +243,10 @@ def __str__(self):
239243
def __repr__(self):
240244
return str(self)
241245

246+
@property
247+
def result(self):
248+
return self.team.result
249+
242250
class Event(object):
243251
name = 'BaseEvent'
244252
def apply(self): pass

0 commit comments

Comments
 (0)