Repository navigation
Expand file tree
/
Copy pathanalyse.py
More file actions
88 lines (80 loc) · 3.19 KB
/
Copy pathanalyse.py
File metadata and controls
88 lines (80 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json, os, xlsxwriter
maps = [
'1', '2', '3', '4', '5', '6', '7'
]
teams = [
'ALA',
'AIgamers',
'correcthorsebatterystaple',
'Directed_Acyclic_Giraffe',
'DRK',
'Matrix',
'Moemoekyun',
]
workbook = xlsxwriter.Workbook("analysis.xlsx")
for i, team1 in enumerate(teams):
worksheet = workbook.add_worksheet(name=team1)
worksheet.write(2, 0, "Score")
worksheet.write(3, 0, "Enemy Score")
worksheet.write(4, 0, "Points")
for j, team2 in enumerate(teams):
if i == j: continue
if j > i:
j -= 1
# Set up columns/rows
worksheet.write(0, j * len(maps) + 1, team2)
# Data
for k, m in enumerate(maps):
map_index = j * len(maps) + 1 + k
worksheet.write(1, map_index, f'{m}.txt')
replay_1 = f"replays/{team1}-{team2}-{m}.txt"
replay_2 = f"replays/{team2}-{team1}-{m}.txt"
if os.path.isfile(replay_1):
f = open(replay_1, "r")
l = list(f.readlines())
f.close()
elif os.path.isfile(replay_2):
f = open(replay_2, "r")
l = list(f.readlines())
f.close()
else:
l = []
# Try to find the (last line with scores.
done = False
if len(l) != 0:
team_names = json.loads(l[0][8:])["teams"]
for i in range(len(l)-1, -1, -1):
if l[i].startswith("[Replay]"):
obj = json.loads(l[i][8:])
if obj["type"] == "tick":
t1_score = obj["scores"][0]
t2_score = obj["scores"][1]
rounds = obj["remaining_rounds"]
if team_names[0] == team2:
t1_score, t2_score = t2_score, t1_score
if rounds == 1:
# Write result
worksheet.write(2, map_index, t1_score)
worksheet.write(3, map_index, t2_score)
if t1_score > t2_score:
if (t1_score - t2_score) / t1_score >= 0.2:
points = 5
else:
points = 4
elif t1_score < t2_score:
if (t2_score - t1_score) / t2_score >= 0.2:
points = 1
else:
points = 2
else:
points = 3
worksheet.write(4, map_index, points)
done = True
break
else:
break
if not done:
worksheet.write(2, map_index, "N/A")
worksheet.write(3, map_index, "N/A")
worksheet.write(4, map_index, "N/A")
workbook.close()