Skip to content

Commit b3d0308

Browse files
author
Scott Kerbey
committed
Clean up readme and remove commented code
1 parent dcc2862 commit b3d0308

File tree

3 files changed

+42
-284
lines changed

3 files changed

+42
-284
lines changed

README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# dota_2_win_predictor
2-
Predicting which team will win based on the heroes picked using a neural network
2+
Predicting which team will win based on the heroes picked.
33

44
Dependencies:
5-
Tensorflow, Numpy, MySql.Connector and dota2api
5+
Tensorflow, Numpy, pymongo and dota2api
66

7-
Requires a MySQL server to save match details
7+
dota2api is no longer available on pypi repository.
8+
To install it download it from github, build and install it yourself.
89

9-
Create a text file - api_key.txt - to put your dota 2 API key in.
10+
Requires a MongoDB server to run.
11+
12+
Set your dota API key as an environment variable to be imported.
1013
You can get a key from here: https://steamcommunity.com/dev/apikey
1114

12-
Create a text file - config_file.txt - to put your username and password in for connecting to the database
13-
You can edit the config dictionary in win_classifier.py and setup_database.ipynb to configure you connection
15+
Setup environment variables for your username and password for connecting to the database
1416

15-
Run setup_database.ipynb in a jupyter notebook to set up database tables and populate them with data
17+
Run setup_database.py in a jupyter notebook to set up database tables and populate them with data
1618

17-
Run win_classifier with --train flag to train the neural network
19+
Run win_classifier.py with --train flag to train the neural network
1820
You can provide other flags to tweak the operation of the training
1921

20-
Run win_classifier with --predict to run a prediction of a match
22+
Run win_classifier.py with --predict to run a prediction of a match
2123
e.g. >python win_classifier.py --predict="1,2,3,4,5,6,7,8,9,10"
2224
with the first 5 numbers being the hero_ids of the radiant heroes and the second 5 dire.
2325
The output will be the probability that radiant will win.

process_data.py

+19-100
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#!/usr/bin/env python
2-
# coding: utf-8
3-
4-
# In[92]:
1+
# %%
52
from pymongo import MongoClient
63
import json
74
import dota2api
@@ -11,79 +8,23 @@
118
# %%
129
api = dota2api.Initialise(api_key)
1310

14-
# In[97]:
15-
# ip = '20.40.184.204'
16-
ip = '104.209.80.106'
17-
client = MongoClient(ip, 27017)
11+
# %%
12+
ip = "10.0.1.4"
13+
port = 27017
14+
username = os.environ.get('MONGO_USER')
15+
pwd = os.environ.get('MONGO_PWD')
16+
client = MongoClient(
17+
ip,
18+
port,
19+
username=username,
20+
password=pwd,
21+
authMechanism='SCRAM-SHA-1'
22+
)
1823

19-
# In[6]:
20-
# query = ("CREATE DATABASE dota7")
21-
# cursor.execute(query)
24+
# %%
2225
db = client.dota
2326

24-
# In[ ]:
25-
# def process_heroes():
26-
# query = ("SELECT * FROM heroes")
27-
# cursor.execute(query)
28-
# global hero_win_rates
29-
# hero_win_rates = []
30-
# h_columns = cursor.column_names
31-
# heroes = cursor.fetchall()
32-
# for h in heroes:
33-
# h = dict(zip(h_columns, h))
34-
# hero_win_rates.append({'id': h['id'], 'name': h['localized_name'], 'matches_won': 0.0, 'matches_played': 0.0})
35-
# match_hero_stmt = ("SELECT * FROM match_hero WHERE hero_id=%s")
36-
# for h in hero_win_rates:
37-
# h['hero_matchup'] = []
38-
# for he in heroes:
39-
# he = dict(zip(h_columns, he))
40-
# h['hero_matchup'].append({'id': he['id'], 'name': he['localized_name'], 'matches_won_against': 0.0, 'matches_played_against': 0.0})
41-
# data = (h['id'],)
42-
# cursor.execute(match_hero_stmt,data)
43-
# mh_columns = cursor.column_names
44-
# for mh in cursor.fetchall():
45-
# mh = dict(zip(mh_columns, mh))
46-
47-
# matches_stmt = ("SELECT * FROM matches WHERE match_id=%s")
48-
# data = (mh['match_id'],)
49-
# cursor.execute(matches_stmt,data)
50-
51-
# mat = dict(zip(cursor.column_names, cursor.fetchone()))
52-
# if ((mh['player_slot'] < 128 and mat['radiant_win']) or (mh['player_slot'] >= 128 and not mat['radiant_win'])):
53-
# h['matches_won'] = h['matches_won'] + 1
54-
# h['matches_played'] = h['matches_played'] + 1
55-
56-
# match_hero_stmt2 = ("SELECT * FROM match_hero WHERE match_id=%s AND NOT hero_id=%s")
57-
# data = (mh['match_id'],mh['hero_id'])
58-
# cursor.execute(match_hero_stmt2,data)
59-
60-
# for mh2 in cursor.fetchall():
61-
# mh2 = dict(zip(mh_columns, mh2))
62-
# pl = next((pl for pl in h['hero_matchup'] if pl['id']==mh2['hero_id']), None)
63-
# if(pl):
64-
# if(mh['player_slot']<128 and mh2['player_slot']>=128 or mh['player_slot']>=128 and mh2['player_slot']<128):
65-
# pl['matches_played_against'] += 1
66-
# if(mh['player_slot']<128 and mat['radiant_win'] or mh['player_slot']>=128 and not mat['radiant_win']):
67-
# pl['matches_won_against'] += 1
68-
# for h in hero_win_rates:
69-
# h['win_rate'] = None if (h['matches_played']==0) else h['matches_won']/h['matches_played']
70-
# save_wr_stmt = ("""UPDATE heroes
71-
# SET win_rate = %s,
72-
# matches_played = %s
73-
# WHERE id = %s""")
74-
# data = (None if (h['win_rate']==None) else h['win_rate'], h['matches_played'],h['id'])
75-
# cursor.execute(save_wr_stmt,data)
76-
# for pl in h['hero_matchup']:
77-
# pl['win_rate'] = None if (pl['matches_played_against']==0) else pl['matches_won_against']/pl['matches_played_against']
78-
# save_mwr_stmt = ("""UPDATE hero_matchups
79-
# SET win_rate = %s,
80-
# matches_played = %s
81-
# WHERE hero_id = %s AND opponent_id = %s""")
82-
# data = (None if not pl['win_rate'] else pl['win_rate'], pl['matches_played_against'],h['id'],pl['id'])
83-
# cursor.execute(save_mwr_stmt,data)
84-
# print("id: {}, name: {}, wins: {}, total: {}, win rate: {}".format(h['id'],
85-
# h['name'],
86-
# h['matches_won'],
27+
# %%
8728
def process_heroes():
8829
heroes_table = db.heroes
8930
match_hero_table = db.match_hero
@@ -192,7 +133,7 @@ def match_hero_query2(match_id, hero_id):
192133
print("id: {}, name: {}, wins: {}, total: {}, win rate: {}".format(h['_id'], h['name'], h['matches_won'], h['matches_played'], "-" if (h['win_rate']==None) else '%.2f' % (100*h['win_rate'])+"%"))
193134

194135

195-
# In[ ]:
136+
# %%
196137
# def generate_hero_matchups():
197138
# query = ("DELETE FROM hero_matchups")
198139
# cursor.execute(query)
@@ -209,30 +150,10 @@ def match_hero_query2(match_id, hero_id):
209150
# data = (hid1, hid2)
210151
# cursor.execute(create_mwr_stmt, data)
211152

212-
# In[ ]:
153+
# %%
213154
process_heroes()
214155

215-
# In[ ]:
216-
# def suggest_1():
217-
# global hero_win_rates
218-
# top_heroes = []
219-
# max_top = 5
220-
# sorted_hero_win_rates = sorted(hero_win_rates, key=lambda k: (-1,-1) if (k['win_rate']==None) else (k['win_rate'],k['matches_played']), reverse=True)
221-
# temp_wr = sorted_hero_win_rates[0]['win_rate']
222-
# i = 0
223-
# while i < max_top or sorted_hero_win_rates[i]['win_rate'] == temp_wr:
224-
# temp_wr = sorted_hero_win_rates[i]['win_rate']
225-
# add_hero = {'id': sorted_hero_win_rates[i]['id'],
226-
# 'matches_played': sorted_hero_win_rates[i]['matches_played'],
227-
# 'matches_won': sorted_hero_win_rates[i]['matches_won'],
228-
# 'name': sorted_hero_win_rates[i]['name'],
229-
# 'win_rate': sorted_hero_win_rates[i]['win_rate']}
230-
# top_heroes.append(add_hero)
231-
# print(add_hero)
232-
# i = i + 1
233-
# return top_heroes
234-
235-
156+
# %%
236157
def suggest_1():
237158
global hero_win_rates
238159
top_heroes = []
@@ -252,7 +173,7 @@ def suggest_1():
252173
i = i + 1
253174
return top_heroes
254175

255-
# In[ ]:
176+
# %%
256177
def suggest_2(hero_id1):
257178
global hero_win_rates
258179
top_heroes = []
@@ -283,5 +204,3 @@ def suggest_2(hero_id1):
283204
# print(sorted_hero_matchups[i])
284205
i = i + 1
285206
return top_heroes
286-
287-
#%%

0 commit comments

Comments
 (0)