def head_to_head_season(user1_players, user2_players, user1_name="User 1", user2_name="User 2", year=os.getenv("YEAR", 2020), verbose=False): if verbose: print(f"Begin running simulation for NBA {year-1}-{year} season\n") data = Data(year) user1_players = data.convert_names(user1_players) user2_players = data.convert_names(user2_players) player1_total_wins = [] player2_total_wins = [] for date, game_data in data.per_week_game_data(): series1_wins, series2_wins = head_to_head_week(date, game_data, user1_players, user2_players, user1_name, user2_name, verbose) player1_total_wins += series1_wins player2_total_wins += series2_wins print( f"\nTotal Results for {year-1}-{year} season\n\t\t{user1_name}: {len(player1_total_wins)}\t{user2_name}: {len(player2_total_wins)}" ) if verbose: print_common_wins(player1_total_wins, user1_name) print_common_wins(player2_total_wins, user2_name) return
def main(): parser = argparse.ArgumentParser(description='Program.') parser.add_argument('--test-data-dir', dest='test_data_dir', required=True) parser.add_argument('--train-data-dir', dest='train_data_dir', required=True) parser.add_argument('--work-dir', dest='work_dir', required=True) parser.add_argument('--res-path', dest='res_path', required=True) args = parser.parse_args() print(args) seed_everything(2020) prod_model = MeanModel([ LgbModel({ 'boosting_type': 'gbdt', 'min_data_in_leaf': 25, 'lambda_l2': 0.06, 'num_leaves': 20, 'learning_rate': 0.035, 'feature_fraction': 0.6, 'bagging_fraction': 0.9, 'bagging_freq': 6, 'num_boost_round': 400, 'group_embeddings_n_components': 7, 'group_embeddings_n_iter': 24, }), KerasModel({ 'epochs': 100, 'verbose': 0, 'n1': 100, 'n2': 70, 'dropout': 0.1, 'learning_rate': 0.003, }), ], coefs=(0.7, 0.3)) train = Data() train.read(args.train_data_dir, 'train') test = Data() test.read(args.test_data_dir, 'test') prod_model.prepare(train, test) prod_model.fit(train) #prod_model.load(os.path.join(args.work_dir, 'models/lgb.txt')) try: res = prod_model.predict(test) pd.DataFrame({ 'uid': test.edu.uid, 'age': res }).to_csv(args.res_path, header=True, index=False) except DebugError: pd.DataFrame({ 'uid': test.edu.uid, 'age': np.repeat(35, test.edu.shape[0]) }).to_csv(args.res_path, header=True, index=False)
from lib import Data from tqdm import tqdm import pandas as pd data = Data(2019) total_game_data = [] for date, day_data in tqdm(data.per_day_game_data(), desc="Getting per day data"): for player_data in day_data: player_data['date'] = date total_game_data += day_data print("Saving data...") df = pd.DataFrame(total_game_data) filename = "data/nba_2018_2019_season_data.csv" df.to_csv(filename, index=False) print(f"Successfully saved to {filename}")
args = parser.parse_args() if torch.cuda.is_available() and not args.usegpu: print 'WARNING: You have a CUDA device, so you should probably run with --usegpu' model_dir = os.path.dirname(args.model) # Load Seeds random.seed(s.SEED) np.random.seed(s.SEED) torch.manual_seed(s.SEED) # Load Data data = Data(data_file=args.data, input_horizon=s.INPUT_HORIZON, n_stations=args.n_stations, train_ratio=s.TRAIN_RATIO, val_ratio=s.VAL_RATIO, debug=False) # Load Model model = Model(args.n_stations, s.MOVING_HORIZON, s.ACTIVATION, s.CRITERION, load_model_path=args.model, usegpu=args.usegpu) # Train First RNN _, _, [X_test, y_test] = data.load_data_lstm_1() print '\n\n' + '#' * 10 + ' TESTING ' + '#' * 10
def getChannels(): channels = Data.getChannels() template = env.get_template("channels.html") return template.render(channels=channels)
def showTags(tagname): courses = Data.getCoursesByTagname(tagname) template = env.get_template("categories.html") return template.render(category=tagname, courses=courses)
def getVideo(courseAlias, videoAlias): video = Data.getVideoByAlias(courseAlias, videoAlias) template = env.get_template("screencast.html") return template.render(video=video)
def getCourse(courseAlias): course = Data.getCourseByAlias(courseAlias) template = env.get_template("course.html") return template.render(course=course)
def coursesDetails(): courses = Data.getCourses() template = env.get_template("courses.html") return template.render(courses=courses)
def index(): courses = Data.getCourses() template = env.get_template("index.html") return template.render(courses=courses)
def convert_name(player_names, year): data = Data(year) player_slugs = [] for player_name in player_names: player_slugs.append(data.NAME_SLUG_CONVERTER[player_name.strip().lower()]) return player_slugs
from lib import Data import pandas as pd from tqdm import tqdm data = Data(2018) total_game_data = [] for date, day_data in tqdm(data.per_day_game_data(), desc="Getting per day data"): for player_data in day_data: player_data['date'] = date total_game_data += day_data print("Saving data...") df = pd.DataFrame(total_game_data) filename = "data/nba_2017_2018_season_data.csv" df.to_csv(filename, index=False) print(f"Successfully saved to {filename}")
import os from lib import Data from tqdm import tqdm import pandas as pd YEAR = int(os.getenv("YEAR", 2020)) PREVIOUS_YEAR = YEAR - 1 DATA = Data(YEAR) PREVIOUS_YEAR_DATA = Data(PREVIOUS_YEAR) # PREVIOUS SEASON def start(): total_game_data = [] for date, day_data in tqdm(PREVIOUS_YEAR_DATA.per_day_game_data(), desc="Getting previous season data"): for player_data in day_data: player_data['date'] = date total_game_data += day_data print("Saving data...") df = pd.DataFrame(total_game_data) filename = "data/previous_season_data.csv" df.to_csv(filename, index=False) print(f"Successfully saved to {filename}") # THIS SEASON total_game_data = [] print("Saving data...") df = pd.DataFrame(DATA.player_total)
import os from flask import Flask, render_template, request, jsonify from lib import Data import pandas as pd app = Flask(__name__) YEAR = int(os.getenv("YEAR")) PREVIOUS_YEAR = YEAR - 1 DATA = Data(YEAR) def send_json(status_code, message): resp = jsonify(message) resp.status_code = status_code return resp @app.route('/') @app.route('/index') def index(): df = pd.read_csv("data/this_season_player_data.csv") return render_template('players.html', data=df[['slug', 'name', 'age', 'drafted']].values) @app.route('/draft', methods=['POST', 'GET']) def draft(): if request.method == 'POST': userid = request.json.get('userid') or "" playerid = request.json.get('playerid') or ""
os.makedirs(output_dir) except: pass pin_memory = False if args.usegpu: pin_memory = True # Load Seeds random.seed(s.SEED) np.random.seed(s.SEED) torch.manual_seed(s.SEED) # Load Data data = Data(data_file=args.data, input_horizon=s.INPUT_HORIZON, n_stations=args.n_stations, train_ratio=s.TRAIN_RATIO, val_ratio=s.VAL_RATIO, debug=args.debug) # Load Model model = Model(args.n_stations, s.MOVING_HORIZON, s.ACTIVATION, s.CRITERION, usegpu=args.usegpu) # Train First RNN [X_train, y_train], [X_val, y_val], [X_test, y_test] = data.load_data_lstm_1() rnn_model_num = 1 print '#' * 10 + ' RNN 1 ' + '#' * 10 train_loader = torch.utils.data.DataLoader(Loader((X_train, y_train)), batch_size=args.batch_size, shuffle=True, num_workers=args.n_workers, pin_memory=pin_memory) val_loader = torch.utils.data.DataLoader(Loader((X_val, y_val)), batch_size=args.batch_size, shuffle=False,