Skip to content

Commit 5c9feab

Browse files
committed
Fixes and improvements to game summaries.
1 parent 94393d5 commit 5c9feab

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

sc2reader/resources.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,16 @@ class GameSummary(Resource):
547547
def __init__(self, summary_file, filename=None, **options):
548548
super(GameSummary, self).__init__(summary_file, filename,**options)
549549

550-
self.players = dict()
550+
self.team = dict()
551+
self.teams = list()
552+
self.players = list()
553+
self.winners = list()
554+
self.player = dict()
551555
self.build_orders = dict()
552556
self.image_urls = list()
553557
self.localization_urls = dict()
554558
self.lobby_properties = dict()
555559
self.lobby_player_properties = dict()
556-
self.teams = dict()
557-
self.winners = list()
558560

559561
self.data = zlib.decompress(summary_file.read()[16:])
560562
self.parts = list()
@@ -614,14 +616,18 @@ def __init__(self, summary_file, filename=None, **options):
614616
# { 0: 3405691582L, 1: 11402158793782460416L}
615617
player.unknown2 = player_struct[0][1][1]
616618

617-
self.players[player.pid] = player
619+
self.players.append(player)
620+
self.player[player.pid] = player
621+
618622
if not player.teamid in self.teams:
619-
self.teams[player.teamid] = list()
620-
self.teams[player.teamid].append(player.pid)
623+
self.team[player.teamid] = list()
624+
self.team[player.teamid].append(player.pid)
625+
self.teams = [self.team[tid] for tid in sorted(self.team.keys())]
626+
621627

622628
# Parse graph and stats stucts, for each player
623-
for pid in self.players:
624-
p = self.players[pid]
629+
for pid, p in self.player.items():
630+
print type(pid), type(p)
625631
# Graph stuff
626632
xy = [(o[2], o[0]) for o in self.parts[4][0][2][1][p.pid]]
627633
p.army_graph = Graph([], [], xy_list=xy)
@@ -659,8 +665,7 @@ def __init__(self, summary_file, filename=None, **options):
659665
bo_structs.append(self.parts[4][0][3:])
660666

661667
# This might not be the most effective way, but it works
662-
for pid in self.players:
663-
p = self.players[pid]
668+
for pid, p in self.player.items():
664669
bo = list()
665670
for bo_struct in bo_structs:
666671
for order in bo_struct:

sc2reader/scripts/sc2boprinter.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,19 @@
66
Usage: python sc2boprinter.py FOLDER
77
"""
88

9-
import sys, os, argparse
10-
from sc2reader.factories import SC2Factory
9+
import sys, os, argparse, sc2reader
1110

12-
def get(dir):
13-
factory = SC2Factory()
14-
15-
res = list()
16-
17-
for file in os.listdir(dir):
18-
if file.rfind('.s2gs') > 0:
19-
res.append(factory.load_game_summary(os.path.join(dir, file)))
20-
21-
return res
2211
def main():
2312
parser = argparse.ArgumentParser(description="Prints build orders from all s2gs files in FOLDER")
24-
parser.add_argument('path', metavar='filename', type=str, nargs=1,
25-
help="Path to a folder")
26-
13+
parser.add_argument('path', metavar='filename', type=str, nargs=1, help="Path to a folder")
2714
args = parser.parse_args()
28-
res = get(args.path[0])
29-
for r in res:
30-
if r.__class__.__name__ == "GameSummary":
31-
print("\n"+"-"*40+"\n")
32-
print("= {} =".format(r))
33-
for p in r.players:
34-
print("== {} - {} ==".format(p.race, p.bnetid if not p.is_ai else "AI"))
35-
for order in r.build_orders[p.pid]:
36-
print("{:0>2}:{:0>2} {:<35} {:>2}/{}".format(order['time'] / 60,
15+
for r in sc2reader.load_game_summaries(args.path):
16+
print("\n"+"-"*40+"\n")
17+
print("= {} =".format(r))
18+
for p in r.players:
19+
print("== {} - {} ==".format(p.race, p.bnetid if not p.is_ai else "AI"))
20+
for order in r.build_orders[p.pid]:
21+
print("{:0>2}:{:0>2} {:<35} {:>2}/{}".format(order['time'] / 60,
3722
order['time'] % 60,
3823
order['order']['name'],
3924
order['supply'],

0 commit comments

Comments
 (0)