def get_win_loss(name, start, end, games): retreaved_games = get_games('whoisis', start, end, games) white, black = split_bw(retreaved_games, 'whoisis') data = gen_all_win_loss(white, black) return data
def main(connection: Connection): user, last_year, last_month = get_starting_user(connection) while user: print(f'Consuming {user}...') try: with connection: connection.execute('update users set started = 1 where id = ?', [user]) except Exception as e: print(e) sys.exit(1) today = datetime.today() starting_year = last_year or 1999 for year in range(starting_year, today.year + 1): starting_month = 1 if (year > last_year or not last_month) else last_month for month in range(starting_month, 13): if year == today.year and month > today.month: break print(f'Looking for {user} in {year}-{month}...') games = reversed(get_games(user, year, month)) for game in games: add_user(connection, game.black) add_user(connection, game.white) if game.id: add_game(connection, game) update_user_progress(connection, user, year, month) cursor = connection.cursor() cursor.execute('select count(*) from games') count = cursor.fetchone()[0] print( f'Finished {year}-{month}. There are now {count} games.\n' ) print() count = count_games(connection, user) print( f'Finished consuming {user}. This user has {count} viewable games.' ) try: with connection: connection.execute( 'update users set finished = 1 where id = ?', [user]) except Exception as e: print(e) sys.exit(1) user, last_year, last_month = get_starting_user(connection) connection.close() print('Done!')
def get_all_moves(name, start, end, games, split=True, not_dummy=True): print("getting all moves") retreaved_games = get_games('whoisis', start, end, games) white, black = split_bw(retreaved_games, 'whoisis') if split: # print(gen_games(black, False, not_dummy)[0]) return gen_games(white, True, not_dummy), gen_games(black, False, not_dummy) # print(white) data = gen_all_game_moves(white, black, not_dummy) return data
white, black = split_bw(retreaved_games, 'whoisis') data = gen_all_win_loss(white, black) return data def gen_all_win_loss(white, black): data = [] data.extend(gen_win_loss(white)) data.extend(gen_win_loss(black)) return data if __name__ == "__main__": start = datetime(2018, 12, 8) end = datetime(2020, 12, 9) games = 13 retreaved_games = get_games('whoisis', start, end, games) # for game in retreaved_games: # print(game) # break white, black = split_bw(retreaved_games, 'whoisis') # print(black) data = gen_all_win_loss(black, white)
from keras.layers import Dense from keras.models import model_from_json import get_games import chess_feeder import numpy import json import os numpy.random.seed(3) token = str(open("token", "r").read()).replace("\n", "") user = "******" print("getting games") inputs, outputs = chess_feeder.feed_games(get_games.get_games(user, token)) inputs = numpy.array(inputs) outputs = numpy.array(outputs) print("model starts here") model = Sequential() model.add(Dense(8 * 8 * 12, input_dim=8 * 8 * 12, activation='relu')) model.add(Dense(5000, activation='relu')) model.add(Dense(5000, activation='relu')) model.add(Dense(5000, activation='relu')) model.add(Dense(8 * 8 * 8 * 8, activation='sigmoid')) model.compile(loss='categorical_crossentropy', optimizer='adam',
class PureRandomModel(object): def __init__(self): self.mutable = True def __call__(self, game): return game.team1 if rand() < .5 else game.team2 def __str__(self): return "Pure Random Model" models = [KenPomStrictModel(), KenPomRandomModel(1), KenPomRandomModel(2), KenPomRandomModel(3), KenPomRandomModel(4), SeedModel(), PureRandomModel()] #DEBUGGING TODO DELETEME #models = [KenPomStrictModel()] kenpom = get_kenpom() games = get_games() for round in actual_winners: for team in actual_winners[round]: assert any(True for t in kenpom if t.name==team) for game in (g for g in games if g.round==round): if game.team1 and game.team1.name == team: game.advance(game.team1) break elif game.team2 and game.team2.name == team: game.advance(game.team2) break def average(a): """Average a list of tuples of the form (value, number of items with that value)""" sum = 0