Ejemplo n.º 1
0
    def setUp(self):
        add_pitcher_entry()
        database_session = MlbDatabase(DB_PATH).open_session()
        entry = GameEntry(date.today(), date.today().ctime(), CommitNewPregamePitcherTest.HOME_TEAM, 'MIA')
        database_session.add(entry)
        database_session.commit()

        database_session.close()
Ejemplo n.º 2
0
def add_pitcher_entries():
    database_session = MlbDatabase(DB_PATH).open_session()

    starting_pitcher_1 = PitcherEntry('Andrew', 'Cashner', '10468')
    database_session.add(starting_pitcher_1)
    starting_pitcher_2 = PitcherEntry('Jeff', 'Samardzija', '9374')
    database_session.add(starting_pitcher_2)

    database_session.commit()
    database_session.close()
Ejemplo n.º 3
0
    def setUp(self):
        add_hitter_entry()
        add_pitcher_entry()
        database_session = MlbDatabase(DB_PATH).open_session()

        entry = GameEntry(date.today(), date.today().ctime(), 'SD', 'BOS')
        database_session.add(entry)
        database_session.commit()

        database_session.close()
Ejemplo n.º 4
0
    def runTest(self):
        database_session = MlbDatabase(DB_PATH).open_session()

        starting_pitcher_1 = PitcherEntry('Andrew', 'Cashner', '10468')
        starting_pitcher_1.baseball_reference_id = 'cashnan01'
        starting_pitcher_1.home_team = 'MIA'
        starting_pitcher_1.pitching_hand = 'R'

        database_session.add(starting_pitcher_1)
        database_session.commit()

        database_session.close()
Ejemplo n.º 5
0
def add_hitter_entry():
    database_session = MlbDatabase(DB_PATH).open_session()

    hitter = HitterEntry('Wil', 'Myers', '10972')
    hitter.baseball_reference_id = 'myerswi01'
    hitter.team = 'SD'
    hitter.batting_hand = 'R'

    database_session.add(hitter)
    database_session.commit()

    database_session.close()
Ejemplo n.º 6
0
    def runTest(self):
        database_session = MlbDatabase(DB_PATH).open_session()

        entry = PregamePitcherGameEntry()
        entry.rotowire_id = '10468'
        entry.game_date = date.today()
        entry.game_time = date.today().ctime()
        entry.home_team = CommitNewPregamePitcherTest.HOME_TEAM

        database_session.add(entry)
        database_session.commit()

        database_session.close()
Ejemplo n.º 7
0
def get_pregame_hitting_stats_wrapper(game):
    database_session = MlbDatabase().open_session()
    for current_hitter in game.away_lineup:
        pitcher_hand = game.home_pitcher.hand
        print "Mining %s." % current_hitter.name
        try:
            pregame_hitter_entry = get_hitter_stats(current_hitter.rotowire_id,
                                                             game.home_pitcher.rotowire_id,
                                                             current_hitter.team,
                                                             pitcher_hand,
                                                             database_session)
            pregame_hitter_entry.game_date = date.today()
            pregame_hitter_entry.opposing_team = game.home_pitcher.team
            predict_draftkings_points(pregame_hitter_entry)
            database_session.add(pregame_hitter_entry)
            database_session.commit()
        except HitterNotFound as e:
            print e
        except IntegrityError:
            print "Attempt to duplicate hitter entry: %s %s %s" % (current_hitter.name,
                                                                   pregame_hitter_entry.team,
                                                                   pregame_hitter_entry.opposing_team)
            database_session.rollback()

    for current_hitter in game.home_lineup:
        pitcher_hand = game.away_pitcher.hand
        print "Mining %s." % current_hitter.name
        try:
            pregame_hitter_entry = get_hitter_stats(current_hitter.rotowire_id,
                                                             game.away_pitcher.rotowire_id,
                                                             current_hitter.team,
                                                             pitcher_hand,
                                                             database_session)
            pregame_hitter_entry.game_date = date.today()
            pregame_hitter_entry.opposing_team = game.away_pitcher.team
            predict_draftkings_points(pregame_hitter_entry)
            database_session.add(pregame_hitter_entry)
            database_session.commit()
        except HitterNotFound as e:
            print e
        except IntegrityError:
            print "Attempt to duplicate hitter entry: %s %s %s" % (current_hitter.name,
                                                                   pregame_hitter_entry.team,
                                                                   pregame_hitter_entry.opposing_team)
            database_session.rollback()

    database_session.close()
Ejemplo n.º 8
0
def get_pregame_hitting_stats_wrapper(game):
    database_session = MlbDatabase().open_session()
    for current_hitter in game.away_lineup:
        pitcher_hand = game.home_pitcher.hand
        print "Mining %s." % current_hitter.name
        try:
            pregame_hitter_entry = get_hitter_stats(
                current_hitter.rotowire_id, game.home_pitcher.rotowire_id,
                current_hitter.team, pitcher_hand, database_session)
            pregame_hitter_entry.game_date = date.today()
            pregame_hitter_entry.opposing_team = game.home_pitcher.team
            predict_draftkings_points(pregame_hitter_entry)
            database_session.add(pregame_hitter_entry)
            database_session.commit()
        except HitterNotFound as e:
            print e
        except IntegrityError:
            print "Attempt to duplicate hitter entry: %s %s %s" % (
                current_hitter.name, pregame_hitter_entry.team,
                pregame_hitter_entry.opposing_team)
            database_session.rollback()

    for current_hitter in game.home_lineup:
        pitcher_hand = game.away_pitcher.hand
        print "Mining %s." % current_hitter.name
        try:
            pregame_hitter_entry = get_hitter_stats(
                current_hitter.rotowire_id, game.away_pitcher.rotowire_id,
                current_hitter.team, pitcher_hand, database_session)
            pregame_hitter_entry.game_date = date.today()
            pregame_hitter_entry.opposing_team = game.away_pitcher.team
            predict_draftkings_points(pregame_hitter_entry)
            database_session.add(pregame_hitter_entry)
            database_session.commit()
        except HitterNotFound as e:
            print e
        except IntegrityError:
            print "Attempt to duplicate hitter entry: %s %s %s" % (
                current_hitter.name, pregame_hitter_entry.team,
                pregame_hitter_entry.opposing_team)
            database_session.rollback()

    database_session.close()
Ejemplo n.º 9
0
def get_pregame_pitching_stats_wrapper(game):
    database_session = MlbDatabase().open_session()

    current_pitcher = game.away_pitcher
    print "Mining %s." % current_pitcher.name
    try:
        pregame_pitcher_entry = get_pitcher_stats(current_pitcher.rotowire_id,
                                                  current_pitcher.team,
                                                  game.home_pitcher.team,
                                                  database_session)

        predict_draftkings_points(pregame_pitcher_entry)
        database_session.add(pregame_pitcher_entry)
        database_session.commit()
    except IntegrityError:
        print "Attempt to duplicate pitcher entry: %s %s %s" % (
            current_pitcher.name, pregame_pitcher_entry.team,
            pregame_pitcher_entry.opposing_team)
        database_session.rollback()
    except PitcherNotFound as e:
        print e

    current_pitcher = game.home_pitcher
    print "Mining %s." % current_pitcher.name
    try:
        pregame_pitcher_entry = get_pitcher_stats(current_pitcher.rotowire_id,
                                                  current_pitcher.team,
                                                  game.away_pitcher.team,
                                                  database_session)

        predict_draftkings_points(pregame_pitcher_entry)
        database_session.add(pregame_pitcher_entry)
        database_session.commit()
    except IntegrityError:
        print "Attempt to duplicate pitcher entry: %s %s %s" % (
            current_pitcher.name, pregame_pitcher_entry.team,
            pregame_pitcher_entry.opposing_team)
        database_session.rollback()
    except PitcherNotFound as e:
        print e

    database_session.close()
Ejemplo n.º 10
0
def get_pregame_pitching_stats_wrapper(game):
    database_session = MlbDatabase().open_session()

    current_pitcher = game.away_pitcher
    print "Mining %s." % current_pitcher.name
    try:
        pregame_pitcher_entry = get_pitcher_stats(current_pitcher.rotowire_id,
                                                           current_pitcher.team,
                                                           game.home_pitcher.team,
                                                           database_session)

        predict_draftkings_points(pregame_pitcher_entry)
        database_session.add(pregame_pitcher_entry)
        database_session.commit()
    except IntegrityError:
        print "Attempt to duplicate pitcher entry: %s %s %s" % (current_pitcher.name,
                                                                pregame_pitcher_entry.team,
                                                                pregame_pitcher_entry.opposing_team)
        database_session.rollback()
    except PitcherNotFound as e:
        print e

    current_pitcher = game.home_pitcher
    print "Mining %s." % current_pitcher.name
    try:
        pregame_pitcher_entry = get_pitcher_stats(current_pitcher.rotowire_id,
                                                           current_pitcher.team,
                                                           game.away_pitcher.team,
                                                           database_session)

        predict_draftkings_points(pregame_pitcher_entry)
        database_session.add(pregame_pitcher_entry)
        database_session.commit()
    except IntegrityError:
        print "Attempt to duplicate pitcher entry: %s %s %s" % (current_pitcher.name,
                                                                pregame_pitcher_entry.team,
                                                                pregame_pitcher_entry.opposing_team)
        database_session.rollback()
    except PitcherNotFound as e:
        print e

    database_session.close()
Ejemplo n.º 11
0
    def runTest(self):
        database_session = MlbDatabase(DB_PATH).open_session()

        lineup = LineupEntry()
        lineup.starting_pitcher_1 = '10468'
        lineup.starting_pitcher_2 = '9374'
        lineup.catcher = '8047'
        lineup.first_baseman = '8620'
        lineup.second_baseman = '6508'
        lineup.third_baseman = '9862'
        lineup.shortstop = '11437'
        lineup.outfielder_1 = '7140'
        lineup.outfielder_2 = '13190'
        lineup.outfielder_3 = '7618'
        lineup.game_date = date.today()
        lineup.game_time = date.today().ctime()

        database_session.add(lineup)
        database_session.commit()

        database_session.close()
Ejemplo n.º 12
0
def add_hitter_entries():
    """ Just add some hitter entries to the test database to satisfy foreign key constraints
    """
    database_session = MlbDatabase(DB_PATH).open_session()

    catcher = HitterEntry('Russell', 'Martin', '8047')
    database_session.add(catcher)
    first_baseman = HitterEntry('Ryan', 'Zimmerman', '8620')
    database_session.add(first_baseman)
    second_baseman = HitterEntry('Chase', 'Utley', '6508')
    database_session.add(second_baseman)
    third_baseman = HitterEntry('Josh', 'Donaldson', '9862')
    database_session.add(third_baseman)
    shortstop = HitterEntry('Manny', 'Machado', '11437')
    database_session.add(shortstop)
    outfielder_1 = HitterEntry('Melvin', 'Upton Jr.', '7140')
    database_session.add(outfielder_1)
    outfielder_2 = HitterEntry('Jose', 'Peraza', '13190')
    database_session.add(outfielder_2)
    outfielder_3 = HitterEntry('Nick', 'Markakis', '7618')
    database_session.add(outfielder_3)

    database_session.commit()
    database_session.close()