예제 #1
0
 def query_data(self):
     """Fetches all records for player id"""
     db = DB()
     q = "SELECT bat_order, AB, BB, HBP FROM rguru_hitters where id=%s"
     res = db.query(q, (self.id_,))
     db.finish()
     return res
예제 #2
0
 def get_team_abs(self, date, team):
     db = DB()
     q = "SELECT name, AB, BB, HBP FROM rguru_hitters WHERE date=%s and team=%s"
     res = db.query(q, (date, team))
     db.finish()
     return res
예제 #3
0
        batters.append((bat_id, l, r))
    return batters


def get_splits_for_batter(rguru_id):
    batter_name = get_player.name_from_id(rguru_id)
    pitcher_ids = get_pitchers(rguru_id)
    # for pid in pitcher_ids:
    #     print get_player.name_from_id(pid, 'p')
    l, r = get_ratio(pitcher_ids)
    print "Pitchers faced by {}".format(batter_name)
    print "Lefties ({:.2f}%) | Righties ({:.2f}%)".format(l*100, r*100)


def get_all_splits(sample_lim=50):
    """
    Will get L/R splits for all batters at bats > sample_lim.
    :return:
    """
    bat_ids = get_batter_ids(sample_lim)
    pitcher_ids = get_pitchers_many(bat_ids)
    batter_ratios = [[get_player.name_from_id(id_), '{:.2f}'.format(l*100), '{:.2f}'.format(r*100)]
                     for id_, l, r in
                     sorted(get_all_ratios(pitcher_ids), key=lambda x: x[1], reverse=True)]
    print tabulate.tabulate(batter_ratios, ['Player', 'vs L', 'vs R'], 'fancy_grid')


get_all_splits()

db.finish()
예제 #4
0
 def get_dates(self):
     db = DB()
     q = "SELECT date FROM rguru_hitters WHERE team = %s"
     res = db.query(q, (self.team,))
     db.finish()
     return set([x[0] for x in res])
예제 #5
0
def get_splits_for_batter(rguru_id):
    batter_name = get_player.name_from_id(rguru_id)
    pitcher_ids = get_pitchers(rguru_id)
    # for pid in pitcher_ids:
    #     print get_player.name_from_id(pid, 'p')
    l, r = get_ratio(pitcher_ids)
    print "Pitchers faced by {}".format(batter_name)
    print "Lefties ({:.2f}%) | Righties ({:.2f}%)".format(l * 100, r * 100)


def get_all_splits(sample_lim=50):
    """
    Will get L/R splits for all batters at bats > sample_lim.
    :return:
    """
    bat_ids = get_batter_ids(sample_lim)
    pitcher_ids = get_pitchers_many(bat_ids)
    batter_ratios = [[
        get_player.name_from_id(id_), '{:.2f}'.format(l * 100),
        '{:.2f}'.format(r * 100)
    ] for id_, l, r in sorted(
        get_all_ratios(pitcher_ids), key=lambda x: x[1], reverse=True)]
    print tabulate.tabulate(batter_ratios, ['Player', 'vs L', 'vs R'],
                            'fancy_grid')


get_all_splits()

db.finish()