-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameSummaryStats.py
231 lines (190 loc) · 9.92 KB
/
GameSummaryStats.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
pd.set_option('display.max_columns', None)
pd.options.mode.chained_assignment = None
with open(r'data/csgo_gamedata.html', encoding='utf-8') as file:
html = file.read()
soup = BeautifulSoup(html, 'html.parser')
first_game_table = soup.find_all('table', {'class': 'csgo_scoreboard_inner_right'})[1]
first_info_table = soup.find_all('table', {'class': 'csgo_scoreboard_inner_left'})[0]
first_game_df = pd.read_html(str(first_game_table))[0]
first_info_df = pd.read_html(str(first_info_table))[0]
master_game_df = pd.DataFrame()
line = {}
name = 'TIER 5 POKIMANE SUB'
team_a = first_game_df.iloc[:5, :]
team_b = first_game_df.iloc[6:, :]
team_a_score = int(first_game_df.loc[5, 'Player Name'].replace(' ', '').split(':')[0])
team_b_score = int(first_game_df.loc[5, 'Player Name'].replace(' ', '').split(':')[1])
team_a_roster = team_a['Player Name'].tolist()
team_b_roster = team_b['Player Name'].tolist()
game_id_list = first_info_df.loc[1, 0].replace(':', '').replace('-', '').split()
game_id = str(game_id_list[0]) + str(game_id_list[1])
def outcome(name=name, team_a_roster=team_a_roster, team_b_roster=team_b_roster, team_a_score=team_a_score,
team_b_score=team_b_score):
status = None
if name in team_a_roster and (team_a_score > team_b_score):
status = 'Win'
elif name in team_b_roster and (team_b_score > team_a_score):
status = 'Win'
else:
status = 'Loss'
return status
first_game_df = first_game_df.drop(5)
first_game_df['★'] = first_game_df['★'].replace(np.nan, 0)
star_list = list(first_game_df['★'])
for i in range(len(star_list)):
current_val = str(star_list[i])
if '★' in current_val:
star_count = list(current_val)
if len(star_count) == 1:
star_list[i] = 1
else:
star_list[i] = int(star_count[-1])
first_game_df['★'] = star_list
dtypes = {'Ping': int, 'K': int, 'A': int, 'D': int, '★': int, 'Score': int}
first_game_df = first_game_df.astype(dtypes)
totals = []
for col in first_game_df.columns:
if first_game_df[col].dtype == object:
del first_game_df[col]
grand_totals = [first_game_df['Ping'].mean(), first_game_df['K'].sum(), first_game_df['A'].sum(),
first_game_df['D'].sum(),
first_game_df['★'].sum(), first_game_df['Score'].sum()]
team_a_totals = [first_game_df.iloc[:5, :]['A'].sum(), first_game_df.iloc[:5, :]['D'].sum(),
first_game_df.iloc[:5, :]['★'].sum(), first_game_df.iloc[:5, :]['Score'].sum()]
team_b_totals = [first_game_df.iloc[5:, :]['K'].sum(),
first_game_df.iloc[5:, :]['A'].sum(), first_game_df.iloc[5:, :]['D'].sum(),
first_game_df.iloc[5:, :]['★'].sum(), first_game_df.iloc[5:, :]['Score'].sum()]
line['Date'] = first_info_df.loc[1, 0].split(' ')[0]
line['Game ID'] = game_id
line['Map'] = first_info_df.loc[0, 0][len('Competitive '):]
line['Duration'] = int(first_info_df.loc[4, 0].split(':', 1)[1].split(':')[0]) * 60 + int(
first_info_df.loc[4, 0].split(':', 1)[1].split(':')[1])
line['On Team'] = 'B'
if name in team_a_roster:
line['On Team'] = 'A'
line['Outcome'] = outcome()
line['Team A Points'] = team_a_score
line['Team A Mean Ping'] = first_game_df.iloc[:5, :]['Ping'].mean()
line['Team A Total Kills'] = first_game_df.iloc[:5, :]['K'].sum()
line['Team A Mean Kills'] = first_game_df.iloc[:5, :]['K'].mean()
line['Team A Total Assists'] = first_game_df.iloc[:5, :]['A'].sum()
line['Team A Mean Assists'] = first_game_df.iloc[:5, :]['A'].mean()
line['Team A Total Deaths'] = first_game_df.iloc[:5, :]['D'].sum()
line['Team A Mean Deaths'] = first_game_df.iloc[:5, :]['D'].mean()
line['Team A Total MVP'] = first_game_df.iloc[:5, :]['★'].sum()
line['Team A Mean MVP'] = first_game_df.iloc[:5, :]['★'].mean()
line['Team A Total Score'] = first_game_df.iloc[:5, :]['Score'].sum()
line['Team A Mean Score'] = first_game_df.iloc[:5, :]['Score'].mean()
line['Team B Points'] = team_b_score
line['Team B Mean Ping'] = first_game_df.iloc[5:, :]['Ping'].mean()
line['Team B Total Kills'] = first_game_df.iloc[5:, :]['K'].sum()
line['Team B Mean Kills'] = first_game_df.iloc[5:, :]['K'].mean()
line['Team B Total Assists'] = first_game_df.iloc[5:, :]['A'].sum()
line['Team B Mean Assists'] = first_game_df.iloc[5:, :]['A'].mean()
line['Team B Total Deaths'] = first_game_df.iloc[5:, :]['D'].sum()
line['Team B Mean Deaths'] = first_game_df.iloc[5:, :]['D'].mean()
line['Team B Total MVP'] = first_game_df.iloc[5:, :]['★'].sum()
line['Team B Mean MVP'] = first_game_df.iloc[5:, :]['★'].mean()
line['Team B Total Score'] = first_game_df.iloc[5:, :]['Score'].sum()
line['Team B Mean Score'] = first_game_df.iloc[5:, :]['Score'].mean()
columns = list(line.keys())
master_game_df = master_game_df.append(line, ignore_index=True)
master_game_df = master_game_df[columns]
skip = 1
for game_table, info_table in zip(soup.find_all('table', {'class': 'csgo_scoreboard_inner_right'}),
soup.find_all('table', {'class': 'csgo_scoreboard_inner_left'})):
if skip == 1:
skip += 1
continue
temp_game_df = pd.read_html(str(game_table))[0]
temp_info_df = pd.read_html(str(info_table))[0]
line = {}
name = 'TIER 5 POKIMANE SUB'
team_a = temp_game_df.iloc[:5, :]
team_b = temp_game_df.iloc[6:, :]
team_a_score = int(temp_game_df.loc[5, 'Player Name'].replace(' ', '').split(':')[0])
team_b_score = int(temp_game_df.loc[5, 'Player Name'].replace(' ', '').split(':')[1])
team_a_roster = team_a['Player Name'].tolist()
team_b_roster = team_b['Player Name'].tolist()
game_id_list = temp_info_df.loc[1, 0].replace(':', '').replace('-', '').split()
game_id = str(game_id_list[0]) + str(game_id_list[1])
def outcome(name=name, team_a_roster=team_a_roster, team_b_roster=team_b_roster, team_a_score=team_a_score,
team_b_score=team_b_score):
status = None
if name in team_a_roster and (team_a_score > team_b_score):
status = 'Win'
elif name in team_b_roster and (team_b_score > team_a_score):
status = 'Win'
else:
status = 'Loss'
return status
temp_game_df = temp_game_df.drop(5)
temp_game_df['★'] = temp_game_df['★'].replace(np.nan, 0)
star_list = list(temp_game_df['★'])
for i in range(len(star_list)):
current_val = str(star_list[i])
if '★' in current_val:
star_count = list(current_val)
if len(star_count) == 1:
star_list[i] = 1
else:
star_list[i] = int(star_count[-1])
temp_game_df['★'] = star_list
dtypes = {'Ping': int, 'K': int, 'A': int, 'D': int, '★': int, 'Score': int}
temp_game_df = temp_game_df.astype(dtypes)
totals = []
for col in temp_game_df.columns:
if temp_game_df[col].dtype == object:
del temp_game_df[col]
# pass
grand_totals = [temp_game_df['Ping'].mean(), temp_game_df['K'].sum(), temp_game_df['A'].sum(),
temp_game_df['D'].sum(),
temp_game_df['★'].sum(), temp_game_df['Score'].sum()]
team_a_totals = [temp_game_df.iloc[:5, :]['A'].sum(), temp_game_df.iloc[:5, :]['D'].sum(),
temp_game_df.iloc[:5, :]['★'].sum(), temp_game_df.iloc[:5, :]['Score'].sum()]
team_b_totals = [temp_game_df.iloc[5:, :]['K'].sum(),
temp_game_df.iloc[5:, :]['A'].sum(), temp_game_df.iloc[5:, :]['D'].sum(),
temp_game_df.iloc[5:, :]['★'].sum(), temp_game_df.iloc[5:, :]['Score'].sum()]
line['Date'] = temp_info_df.loc[1, 0].split(' ')[0]
line['Game ID'] = game_id
line['Map'] = temp_info_df.loc[0, 0][len('Competitive '):]
line['Duration'] = int(temp_info_df.loc[4, 0].split(':', 1)[1].split(':')[0]) * 60 + int(
temp_info_df.loc[4, 0].split(':', 1)[1].split(':')[1])
line['On Team'] = 'B'
if name in team_a_roster:
line['On Team'] = 'A'
line['Outcome'] = outcome()
line['Team A Points'] = team_a_score
line['Team A Mean Ping'] = temp_game_df.iloc[:5, :]['Ping'].mean()
line['Team A Total Kills'] = temp_game_df.iloc[:5, :]['K'].sum()
line['Team A Mean Kills'] = temp_game_df.iloc[:5, :]['K'].mean()
line['Team A Total Assists'] = temp_game_df.iloc[:5, :]['A'].sum()
line['Team A Mean Assists'] = temp_game_df.iloc[:5, :]['A'].mean()
line['Team A Total Deaths'] = temp_game_df.iloc[:5, :]['D'].sum()
line['Team A Mean Deaths'] = temp_game_df.iloc[:5, :]['D'].mean()
line['Team A Total MVP'] = temp_game_df.iloc[:5, :]['★'].sum()
line['Team A Mean MVP'] = temp_game_df.iloc[:5, :]['★'].mean()
line['Team A Total Score'] = temp_game_df.iloc[:5, :]['Score'].sum()
line['Team A Mean Score'] = temp_game_df.iloc[:5, :]['Score'].mean()
line['Team B Points'] = team_b_score
line['Team B Mean Ping'] = temp_game_df.iloc[5:, :]['Ping'].mean()
line['Team B Total Kills'] = temp_game_df.iloc[5:, :]['K'].sum()
line['Team B Mean Kills'] = temp_game_df.iloc[5:, :]['K'].mean()
line['Team B Total Assists'] = temp_game_df.iloc[5:, :]['A'].sum()
line['Team B Mean Assists'] = temp_game_df.iloc[5:, :]['A'].mean()
line['Team B Total Deaths'] = temp_game_df.iloc[5:, :]['D'].sum()
line['Team B Mean Deaths'] = temp_game_df.iloc[5:, :]['D'].mean()
line['Team B Total MVP'] = temp_game_df.iloc[5:, :]['★'].sum()
line['Team B Mean MVP'] = temp_game_df.iloc[5:, :]['★'].mean()
line['Team B Total Score'] = temp_game_df.iloc[5:, :]['Score'].sum()
line['Team B Mean Score'] = temp_game_df.iloc[5:, :]['Score'].mean()
print(line)
master_game_df = master_game_df.append(line, ignore_index=True)
master_game_df['Duration'] = master_game_df['Duration'].astype(int)
master_game_df['Game ID'] = master_game_df['Game ID'].astype(np.int64) // (10 * 10^2000)
columns = list(line.keys())
master_game_df = master_game_df[columns]
master_game_df.to_csv('data/GameStats.csv', index=False)