def run_gid(gid, gametype): retries = 0 while retries < 10: try: DB = store.Store() g = game.Game(gid) if (g.game_type != gametype): return g.save() game_id = g.game_id ab = atbats.AtBats(gid, game_id) ab.save() chart = hitchart.HitChart(gid, game_id) chart.save() batters = players.Batters(gid, game_id) batters.save() pitchers = players.Pitchers(gid, game_id) pitchers.save() DB.finish() break except Exception as e: print "EXCEPTION: %s, RETRIES: %s" % (e, retries) retries += 1
def run(self): DB = store.Store() soup = BeautifulSoup(Fetcher.fetch(self.url)) for link in soup.findAll('a'): if link['href'].find('gid_') >= 0: gid = link['href'].rstrip('/') g = game.Game(gid) if (g.game_type != self.gametype): continue g.save() game_id = g.game_id ab = atbats.AtBats(gid, game_id) ab.save() chart = hitchart.HitChart(gid, game_id) chart.save() batters = players.Batters(gid, game_id) batters.save() pitchers = players.Pitchers(gid, game_id) pitchers.save()
def create_dataset(player, opponent, extractor): """ Used to create a learning dataset for the value and policy network. Play against itself and backtrack the winner to maximize winner moves probabilities """ queue = multiprocessing.JoinableQueue() dataset = multiprocessing.Queue() train_dataset = [] game_managers = [ game.GameManager(queue, dataset) for _ in range(CPU_CORES) ] for game_manager in game_managers: game_manager.start() for _ in range(NUM_MATCHES): queue.put(game.Game(player, opponent, extractor)) for _ in range(CPU_CORES): queue.put(None) queue.join() for _ in range(NUM_MATCHES): result = dataset.get() train_dataset.append(pickle.loads(result)) return train_dataset
def get_past_lines(): cursor = cnx.cursor() from_date = datetime.now() - timedelta(seconds=1200) to_date = datetime.now() query_games = ( "SELECT * FROM games WHERE update_time > %(from_date)s ORDER BY update_time DESC" ) cursor.execute(query_games, {'from_date': from_date}) past_games = [] row = cursor.fetchone() while row is not None: g = game.Game() data = dict(zip(cursor.column_names, row)) g.teams.append(data['team1']) g.teams.append(data['team2']) g.guid = data['gameid'] g.ats_line.append(data['ats1']) g.ats_line.append(data['ats2']) g.ou_line.append(data['ou1']) g.ou_line.append(data['ou2']) g.moneyline.append(data['ml1']) g.moneyline.append(data['ml2']) g.date = data['date'] g.update_time = data['update_time'] past_games.append(g) row = cursor.fetchone() cursor.close() return past_games
def initialize(self): if self.game_map is None: raise ValueError("No map provided") while True: try: self.display.message("Insert players information") self.display.message("Insert players quantity") start_info = self.receiver.handle_string() player_quantity = int(start_info[0]) break except Exception as err: self.display.message("Incorrect input") self.display.message(str(err)) players = dict() for player_id in range(player_quantity): while True: try: self.display.message( "Insert spawn position of player {0}".format( player_id + 1)) self.display.message("input format: <Name> <lay> <x> <y>") player_name, spawn_lay, spawn_x, spawn_y = self.receiver.handle_string( ) if player_name in players: raise ValueError("such player already exist") spawn_lay = int(spawn_lay) - 1 spawn_x = int(spawn_x) - 1 spawn_y = int(spawn_y) - 1 if spawn_lay < 0 or spawn_lay > len(self.game_map): raise ValueError("lay coord is invalid") if spawn_x < 0 or spawn_x > len(self.game_map[spawn_lay]): raise ValueError("y coord is invalid") if spawn_y < 0 or spawn_y > len( self.game_map[spawn_lay][spawn_x]): raise ValueError("y coord is invalid") players[player_name] = player.Player( spawn_lay, spawn_x, spawn_y, spawn_lay, spawn_x, spawn_y, player_name) break except Exception as err: self.display.message("Incorrect input") self.display.message(str(err)) self.players = players self.game = game.Game(self.game_map, players)
import pandas as pd import numpy as np import copy import math import matplotlib.pyplot as plt # import datetime import multiprocessing as multip from lib import game scores = [(3, 3), (0, 5), (2, 2), \ (5, 0), (1, 1), (2, 2), \ (2, 2), (2, 2), (2, 2)] g = game.Game(scores, ["C", "D", "P"]) class Evaluator: def run(self): pass class Meeting(Evaluator): def __init__(self, game, s1, s2, length=1000): self.game = game self.s1 = s1.clone() self.s2 = s2.clone() self.length = length self.nb_cooperation_s1 = 0 self.nb_cooperation_s2 = 0 def reinit(self):
#!/usr/bin/python from lib import game game.resource_path = "resources" katate = game.Game() katate.start()
def get_nfl_lines(): nfl_event_validation = open( os.getcwd() + '/event_validations/nfl_event_validation').read() nfl_view_state = open(os.getcwd() + '/view_states/nfl_view_state').read() data = { '__EVENTTARGET': 'ctl00$WagerContent$idx_1x1', '__VIEWSTATE': nfl_view_state, '__VIEWSTATEGENERATOR': '3DB83FCB', '__EVENTVALIDATION': nfl_event_validation } page = session.post( 'http://everysport247.com/wager/CreateSports.aspx?WT=0', data).content soup = BeautifulSoup(page, 'html.parser') tables = soup.find_all('table') table = tables[1] trows = table.find_all('tr') x = 0 games = [] g = game.Game() reset = 1 for row in trows: try: td = row.contents[3] if td.span['id'] != 'teamlogo': continue team_name = (td.span['class'][0] + ' ' + td.span['class'][1]).replace('football-', '') date = row.contents[1].string.strip() g.date += date + ' ' g.teams.append(team_name) g.guid = row.contents[4].input['value'][2:9] g.ats_line.append(row.contents[4].input['value'][10:].replace( '_', ' ')) # for s in row.contents[4].strings: # g.ats_line.append(s.replace(u'\xbd', '.5')) g.ou_line.append(row.contents[5].input['value'][10:].replace( '_', ' ')) # for s in row.contents[5].strings: # g.ou_line.append(s.replace(u'\xbd', '.5')) g.moneyline.append(row.contents[6].input['value'][12:]) # for s in row.contents[6].strings: # g.moneyline.append(s.replace(u'\xbd', '.5')) reset += 1 if reset > 2: games.append(g) g = game.Game() reset = 1 except Exception: pass for g in games: # correct the date to add the year date = datetime.strptime((str(g.date)).strip(), '%b %d %I:%M %p') if date.month != datetime.now().month: year = datetime.now().year + 1 else: year = datetime.now().year g.date = date.strftime('%Y-%m-%d %H:%M').replace('1900', str(year)) return games