def __init__(self, league_season_id=False): self.league_name = 'ncaam' self.league_abbrev = 'ncaam' self.dbobj = configg.dbobj self.league_obj = league.League(configg.dbobj, self.league_name) FindTeams.__init__(self, league_season_id) self._getRecentLeagueSeasonId(self.league_obj)
def _verifyLeague(params): args = params.copy() for arg in ['start_date', 'end_date', 'files']: del args[arg] lgobj = league.League(**args) if not lgobj.obj or not lgobj.league_season: return False else: return lgobj
def to_league(self, league_id): """Construct a League object from a Game :param league_id: League ID of the new League to construct :type league_id: str :return: Fully constructed object :rtype: League """ lg = league.League(self.sc, league_id) lg.inject_yhandler(self.yhandler) return lg
def scrape(dbobj, dt, files): # Choose games lgobj = league.League(dbobj) games = lgobj.getGames(dt) # Get source gamedata = source.main.go(games, files) # Scrape extract.main.go(gamedata) clean.main.go(gamedata, dbobj) load.main.go(gamedata, dbobj)
def getParamsManual(): # Choose league curs.execute("SELECT * FROM league") leagues = [] lgs = curs.fetchall() for lg in lgs: leagues.append(dict(zip(lg.keys(), lg))) print 'ID: League Name' for l in leagues: print '%s: %s' % (l['id'], l['name']) league_input = raw_input('Choose league by ID: ') league_input = int(league_input) # Choose league season lgobj = league.League(league_id=league_input) league_seasons = lgobj.getLeagueSeasons() print 'ID: Season Name' for ls in league_seasons: print '%s: %s' % (ls['id'], ls['season_name']) league_season_input = raw_input('Choose season: ') # Choose dates to scrape start_date_input = raw_input( 'Choose START date (yyyy-mm-dd or blank for today\'s date of %s): ' % (datetime.date.today())) if not start_date_input: start_date_input = datetime.date.today() end_date_input = start_date_input else: start_date_input = datetime.datetime.strptime(start_date_input, '%Y-%m-%d').date() end_date_input = raw_input( 'Choose END date (yyyy-mm-dd or blank for START date): ') if not end_date_input: end_date_input = start_date_input else: end_date_input = datetime.datetime.strptime( end_date_input, '%Y-%m-%d').date() print "+++ Database name: %s" % (str(configg.db_params['db'])) return { 'league_id': league_input, 'league_season_id': league_season_input, 'files': [], 'start_date': start_date_input, 'end_date': end_date_input }
# index_json indexjson = indexjson.IndexJson(INDEX_JSON_FOLDER_PATH, OPENDOTA_INDEX_JSON_FOLDER_PATH) # steam steamjson = steamjson.SteamJson(leagueid, apikey_steam, startid, end_id, league_folder) steamjson.write_json(league_folder) ############ ここ手動でいじるとき is_matchlist_not_change = steamjson.is_matchlist_not_change(league_folder) if is_matchlist_not_change: print("matchlist is not change, make opendota in local file") # opendota opendotajson = opendotajson.OpendotaJson(leagueid, apikey_opendota, steamjson, indexjson, league_folder, is_matchlist_not_change) opendotajson.write_json(league_folder) # make stat league = league.League(leagueid, opendotajson, indexjson) league.write_json(league_folder) # make all league json all_league_json = read_all_league_json(PARENT_LEAGUE_FOLDER_PATH, ALL_LEAGUE_JSON_FILENAME) all_league_json[leagueid] = league.get_leaguejson() write_all_league_json(PARENT_LEAGUE_FOLDER_PATH, ALL_LEAGUE_JSON_FILENAME, all_league_json) print("--end--")
with open(league.SAVE_DIR + l.name + '.dat', 'wb') as f: pickle.dump(l, f) def load(filename): try: savefile = open(league.SAVE_DIR + filename, "rb") return pickle.load(savefile) except: return False lg = None if len(sys.argv) == 1: lg = league.League() save(lg) else: lg = load(sys.argv[1]) if not lg: lg = league.League() save(lg) players = league.allPlayers() players = list(reversed(sorted(players, key=lambda p: p.getRating()))) def leave(): save(lg) sys.exit()
import sys import os PROJECT_ROOT = os.path.abspath( os.path.join(os.path.dirname(os.path.realpath(__file__)))) if PROJECT_ROOT not in sys.path: sys.path.insert(0, PROJECT_ROOT) import league import plot league_id = 361793 season_id = 2017 season_length = 16 L = league.League(league_id, season_id, season_length) print L teams = L.teams pos_avg = L.get_league_avg_points_per_position() plot_data = { 'name': '', 'x': list(), 'y': list(), 'plot_type': '', 'text': '', 'title': '', 'filename': '', }
def __init__(self, league_season_id=False): self.league_name = 'nba' self.league_obj = league.League(configg.dbobj, self.league_name) FindGames.__init__(self, league_season_id) self._getRecentLeagueSeasonId(self.league_obj)
def main(): players = league.League(argv[1], argv[2], argv[3]) evolution.run(players)
def _init_game(game_type, teams, fast, num_turns, back_round=False, log_base_folder=None): logging.info(">>>> INIT GAME") if log_base_folder == None: log_base_folder = configure.load_configuration()['games_path'] + '/' # Generamos el nombre del fichero de log según el tipo de juego log_base_name = filenames.generate_filename(game_type, noExtension=True) log_folder_name = log_base_folder + log_base_name log_file_name = log_folder_name + "/" + game_type + ".txt" logging.info("Fichero de log: %s", log_file_name) logging.info("Carpeta de log: %s", log_folder_name) os.mkdir(log_folder_name) # Lanzamos el tipo de juego apropiado if game_type == 'cup': game = tournament.Tournament(teams, num_turns, log_folder=log_folder_name) else: game = league.League(teams, num_turns, back_round, log_folder=log_folder_name) band = False # Contenedor para clasificaciones classifications = {} results = None # Cada elemento tendrá una tupla de 3: ganadas, empatadas y perdidas estadisticas = { "aux_ghost_team": { "ganadas": 0, "empatadas": 0, "perdidas": 0 } } for equipo in contest.generate_key_names(teams).keys(): estadisticas[equipo] = { "ganadas": 0, "empatadas": 0, "perdidas": 0 } # Mientras no se haya completado el juego while not game.completed( ) and not band and not controlPartida.flagCancelarCampeonato: logging.info("---- START OF THE ROUND") if results != None: # Cargamos el diálogo de resultados R = round_results.roundResults( classifications, results, game.get_prev_round_number() + 1, game.get_number_of_rounds(), show_classifications=(game_type != 'cup'), stats=estadisticas, show_top_teams=True, next_matches=game.matchs[game.get_round_number()]) # Mostramos el diálogo de resultados button_pressed = R.result_dialog.run() while gtk.events_pending(): gtk.main_iteration(False) if button_pressed == -4 or button_pressed == 0: band = True continue # Guardamos el número de la ronda roundNumber = game.get_round_number() if roundNumber == 0: show_round_matches(game) # Por defecto que la barra de progreso no exista progress_bar = None # Si no mostramos el progreso del juego, que salga la barra if fast: progress_bar = pbs.ProgressBarDialog(None, _('Running the contest')) progress_bar_dialog = progress_bar.progress_bar_dialog progress_bar.set_num_elements( game.get_round(roundNumber).number_games) progress_bar_dialog.show() while gtk.events_pending(): gtk.main_iteration(False) # Jugamos esta ronda game.play_round(progress_bar, fast) if controlPartida.flagCancelarCampeonato: return # Guardamos en r la ronda actual, con sus resultados y tal r = game.get_round(roundNumber) # Resultados de la ronda results = r.get_round_results() # Actualizamos el fichero del log update_log_round(log_file_name, results, roundNumber) for partido in results: if partido[1] == 1: estadisticas[partido[0][0]]["ganadas"] += 1 estadisticas[partido[0][1]]["perdidas"] += 1 elif partido[1] == -1: estadisticas[partido[0][1]]["ganadas"] += 1 estadisticas[partido[0][0]]["perdidas"] += 1 else: estadisticas[partido[0][0]]["empatadas"] += 1 estadisticas[partido[0][1]]["empatadas"] += 1 if game_type == 'cup': pass else: # "Puntuations" es una palabra que no existe classifications = game.get_actual_puntuations() # Ocultamos la barra de progreso (que ya habrá acabado) if fast: progress_bar_dialog.hide() logging.info("---- END OF THE ROUND") if not band: # Mostramos los resultados FINALES R = round_results.roundResults( classifications, results, game.get_prev_round_number() + 1, game.get_number_of_rounds(), show_classifications=(game_type != 'cup'), show_top_teams=True, stats=estadisticas) # Mostramos el diálogo de resultados button_pressed = R.result_dialog.run() while gtk.events_pending(): gtk.main_iteration(False) if not band and not controlPartida.flagCancelarCampeonato: if game_type == 'cup': update_log_ending_tournament(log_file_name, estadisticas) dibujoClasificacion = dibujo_clasificacion.DibujoClasificacion( game) else: update_log_ending_league(log_file_name, classifications) logging.info(">>>> END INIT GAME") return (band, classifications)