Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
There was no way to guess what were the team in the data. Fixed?
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfrow committed Aug 2, 2017
1 parent af36dfd commit 9d4ab17
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
60 changes: 59 additions & 1 deletion BestPicks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from Learner import ValueNetwork, maybe_restore_from_checkpoint

CHAMPIONS_SIZE = 150
PATCHES_SIZE = 150
PATCHES_SIZE = 149

config = configparser.ConfigParser()
config.read('config.ini')
Expand Down Expand Up @@ -163,6 +163,10 @@ def initUI(self):
self.yourTeam = QComboBox()
self.yourTeam.addItems(TEAMS)
bestPicksLayout.addWidget(self.yourTeam, 0, 1)
self.evaluateButton = QPushButton('Wait...')
self.evaluateButton.setEnabled(False)
self.evaluateButton.clicked.connect(lambda: self.evaluate())
bestPicksLayout.addWidget(self.evaluateButton, 0, 2)
yourRoleLabel = QLabel()
yourRoleLabel.setText('Your role:')
bestPicksLayout.addWidget(yourRoleLabel, 1, 0)
Expand Down Expand Up @@ -231,6 +235,59 @@ def buildNetwork(self):

self.generateButton.setText('Analyze')
self.generateButton.setEnabled(True)
self.evaluateButton.setText('Evaluate')
self.evaluateButton.setEnabled(True)

def evaluate(self):
print('generating for:', str(self.yourRole.currentText()), file=sys.stderr)
currentState = OrderedDict([(champ, 'A') for champ in CHAMPIONS_LABEL])
bans = [str(self.player1Ban.currentText()), str(self.player2Ban.currentText()), str(self.player3Ban.currentText()),
str(self.player4Ban.currentText()), str(self.player5Ban.currentText()), str(self.player6Ban.currentText()),
str(self.player7Ban.currentText()), str(self.player8Ban.currentText()), str(self.player9Ban.currentText()),
str(self.player10Ban.currentText())]
print('bans', bans, file=sys.stderr)
picks = [(str(self.player1Pick.currentText()), str(self.player1Role.currentText())),
(str(self.player2Pick.currentText()), str(self.player2Role.currentText())),
(str(self.player3Pick.currentText()), str(self.player3Role.currentText())),
(str(self.player4Pick.currentText()), str(self.player4Role.currentText())),
(str(self.player5Pick.currentText()), str(self.player5Role.currentText())),
(str(self.player6Pick.currentText()), 'Opp'), (str(self.player7Pick.currentText()), 'Opp'),
(str(self.player8Pick.currentText()), 'Opp'), (str(self.player9Pick.currentText()), 'Opp'),
(str(self.player10Pick.currentText()), 'Opp')]
print('picks', picks, file=sys.stderr)
for ban in bans:
if ban [0] != '.':
currentState[ban] = 'B'
for (pick, role) in picks:
if pick[0] != '.' and role[0] in CHAMPIONS_STATUS:
currentState[pick] = role[0]

yourTeam = str(self.yourTeam.currentText())
if yourTeam == '...':
print('You need to select a team!', file=sys.stderr)
return
# print(currentState, file=sys.stderr)

data = []

row_data = []
row_data.extend([1 if currentState[CHAMPIONS_LABEL[k]] == s else 0 for k in range(len(CHAMPIONS_LABEL)) for s in CHAMPIONS_STATUS])
row_data.extend([0 for k in range(CHAMPIONS_SIZE - len(CHAMPIONS_LABEL)) for s in CHAMPIONS_STATUS])
row_data.extend(PATCH)
row_data.append(yourTeam)
data.append(row_data)

batch = [[], []]
batch[0] = data

feed_dict = {
self.x: batch[0],
}
pred_values = self.sess.run(self.y_pred, feed_dict=feed_dict)

self.results.setRowCount(1)
self.results.setItem(0, 0, 'winrate')
self.results.setItem(0, 1, '%.2f' % (pred_values[0] * 100))

def generate(self):
print('generating for:', str(self.yourRole.currentText()), file=sys.stderr)
Expand Down Expand Up @@ -284,6 +341,7 @@ def generate(self):
row_data.extend([1 if state[CHAMPIONS_LABEL[k]] == s else 0 for k in range(len(CHAMPIONS_LABEL)) for s in CHAMPIONS_STATUS])
row_data.extend([0 for k in range(CHAMPIONS_SIZE - len(CHAMPIONS_LABEL)) for s in CHAMPIONS_STATUS])
row_data.extend(PATCH)
row_data.append(yourTeam)
data.append(row_data)

batch = [[], []]
Expand Down
16 changes: 10 additions & 6 deletions DataExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
regions_list = config['REGIONS']
COLUMNS = [champ for champ in CHAMPIONS_LABEL]
COLUMNS.append('patch')
COLUMNS.append('team')
COLUMNS.append('win')
COLUMNS.append('file')

Expand Down Expand Up @@ -83,8 +84,9 @@ def getRoleIndex(lane, role):

for gamePath in gamesPath:
raw_data = OrderedDict([(champ, []) for champ in CHAMPIONS_LABEL])
raw_data['win'] = []
raw_data['patch'] = []
raw_data['team'] = []
raw_data['win'] = []
raw_data['file'] = []
print(gamePath)
game = pickle.load(open(gamePath, 'rb'))
Expand Down Expand Up @@ -141,8 +143,10 @@ def getRoleIndex(lane, role):
# Blank, everything is available
blueState = OrderedDict()
redState = OrderedDict()
blueState['team'] = 0
redState['team'] = 1
blueState['win'] = int(blueWin)
redState['win'] = int(blueWin)
redState['win'] = int(redWin)
blueState['patch'] = game_patch
redState['patch'] = game_patch
blueState['file'] = os.path.basename(gamePath)
Expand All @@ -151,8 +155,8 @@ def getRoleIndex(lane, role):
redState.update([(champ_name, 'A') for champ_name in CHAMPIONS_LABEL])
for key, value in blueState.items():
raw_data[key].append(value)
# for key, value in redState.items():
# raw_data[key].append(value)
for key, value in redState.items():
raw_data[key].append(value)

# Bans
blueState = dict(blueState) # don't forget to create a clean copy
Expand All @@ -165,8 +169,8 @@ def getRoleIndex(lane, role):
break
for key, value in blueState.items():
raw_data[key].append(value)
# for key, value in redState.items():
# raw_data[key].append(value)
for key, value in redState.items():
raw_data[key].append(value)

# Smart lane-role
b_roles = OrderedDict()
Expand Down
7 changes: 5 additions & 2 deletions DataProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

SAVE = 1000
CHAMPIONS_SIZE = 150
PATCHES_SIZE = 150
INPUT_SIZE = CHAMPIONS_SIZE * 8 + PATCHES_SIZE + 1
PATCHES_SIZE = 149
INPUT_SIZE = CHAMPIONS_SIZE * 8 + PATCHES_SIZE + 1 + 1 # team color + team win
config = configparser.ConfigParser()
config.read('config.ini')
DATABASE = config['PARAMS']['database']
Expand All @@ -27,10 +27,12 @@

names = CHAMPIONS_LABEL[:]
names.append('patch')
names.append('team')
names.append('win')
names.append('file')
dtype = {champ: str for champ in CHAMPIONS_LABEL}
dtype['patch'] = str
dtype['team'] = int
dtype['win'] = int
dtype['file'] = str

Expand Down Expand Up @@ -60,6 +62,7 @@ def processing(dataFile):
row_data.extend([1 if row[CHAMPIONS_LABEL[k]] == s else 0 for k in range(len(CHAMPIONS_LABEL)) for s in CHAMPIONS_STATUS])
row_data.extend([0 for k in range(CHAMPIONS_SIZE - len(CHAMPIONS_LABEL)) for s in CHAMPIONS_STATUS ])
row_data.extend([1 if row['patch'] == PATCHES[k] else 0 for k in range(PATCHES_SIZE)])
row_data.append(row['team'])
row_data.append(row['win'])
data.loc[len(data)] = row_data
if len(data):
Expand Down
8 changes: 4 additions & 4 deletions Learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# 7.14: champions 138, patches: 97
# current rythm: 6 champions per season, 24 patches per season
CHAMPIONS_SIZE = 150
PATCHES_SIZE = 150
INPUT_SIZE = CHAMPIONS_SIZE * 8 + PATCHES_SIZE
PATCHES_SIZE = 149
INPUT_SIZE = CHAMPIONS_SIZE * 8 + PATCHES_SIZE + 1 # team color
config = configparser.ConfigParser()
config.read('config.ini')
DATABASE = config['PARAMS']['database']
Expand Down Expand Up @@ -151,7 +151,7 @@ def nextBatchValue(self):
return batch
j = min(self.i + self.batchSize, len(self.df))
batch[0] = self.df.iloc[self.i:j, :-1].values.tolist()
batch[1] = self.df.iloc[self.i:j, -1].values.tolist() # first column is the value
batch[1] = self.df.iloc[self.i:j, -1].values.tolist() # last column is the win value
if j < len(self.df):
self.i = j
else:
Expand Down Expand Up @@ -261,5 +261,5 @@ def learn(netType, netArchi, archi_kwargs, batchSize, checkpoint, report, lr):
if __name__ == '__main__':
# Testing (production network will be more sopisticated)
# learn(netType='Value', netArchi='Dense2', archi_kwargs={'NN': 2048, 'training': True}, batchSize=10000, checkpoint=None, report=1, lr=1e-4)
learn(netType='Value', netArchi='Dense3', archi_kwargs={'NN': 2048, 'training': True}, batchSize=10000, checkpoint=None, report=1, lr=1e-4)
learn(netType='Value', netArchi='Dense3', archi_kwargs={'NN': 2048, 'training': True}, batchSize=1000, checkpoint=None, report=1, lr=1e-4)
# learn(netType='Value', netArchi='Dense5', archi_kwargs={'NN': 2048, 'training': True}, batchSize=10000, checkpoint=None, report=1, lr=1e-4)

0 comments on commit 9d4ab17

Please sign in to comment.