예제 #1
0
    if len(str(game).split()) == 5:
        team1 = str(game).split()[0]
        team2 = str(game).split()[3]
    else:
        if str(game).split()[2] == 'at':
            team1 = str(game).split()[0]
            team2 = str(game).split()[3] + ' ' + str(game).split()[4]
        else:
            team1 = str(game).split()[0] + ' ' + str(game).split()[1]
            team2 = str(game).split()[4]

    return team1, team2


#set the scraper for baseball reference
scraper = brscraper.BRScraper()

#read in data from the last 3 days
day = input("Day ")
month = input("Month ")
yesterday = mlbgame.day(2017, month, day - 1)
two_days = mlbgame.day(2017, month, day - 2)
today = mlbgame.day(2017, month, day)

#get todays stats for predict
get_todays_stats()

#get training stats to train
get_training_data()

#make columns
예제 #2
0
 def setUp(self):
     self.scraper = brscraper.BRScraper()
예제 #3
0
    def getData(self):
        self.btn.setText("Downloading...")  #tell client we are dowenloading
        scraper = brscraper.BRScraper()  #initialize scraper
        teams = ["ARI", "ATL", "BAL", "BOS", "CHC", "CHW" , "CIN", "CLE", "COL", \
        "DET", "HOU" , "KCR", "LAA", "LAD", "MIA", "MIL", "MIN", "NYM", "NYY",\
        "OAK", "PHI", "PIT", "SEA", "SDP", "SFG", "STL", "TBR", "TEX", "TOR", "WSN"]

        #fetch data for each team
        for num, team in enumerate(teams):
            data = scraper.parse_tables(
                "teams/" + team + "/2016.shtml",
                table_ids='team_batting')  #build team URL
            batting = data.get(
                'team_batting'
            )  #we're only interested in hitting stats for now

            #for each entry, we add if its a new player, or consolidate if its an existing player.
            #some players will appear in multiple teams, so we need to be ready to combine stats.
            for row in batting:
                if row['Name'] in self.players:
                    stats = self.players[row['Name']]
                    stats['HR'] = +int(row['HR'])
                    stats['2B'] = +int(row['2B'])
                    stats['3B'] = +int(row['3B'])
                    stats['SB'] = +int(row['SB'])
                    stats['RBI'] = +int(row['RBI'])
                    stats['R'] = +int(row['R'])

                    oldba = stats['BA']
                    oldobp = stats['OBP']
                    oldab = stats['AB']
                    oldpa = stats['PA']

                    ba = float(row['BA'])
                    obp = float(row['OBP'])
                    ab = int(row['AB'])
                    pa = int(row['PA'])

                    if (oldab + ab > 0):
                        stats['BA'] = (oldba * oldab + ba * ab) / (oldab + ab)
                    if (oldpa + pa > 0):
                        stats['OBP'] = (oldobp * oldpa + obp * pa) / (oldpa +
                                                                      pa)

                    stats['PA'] = oldpa + pa
                    stats['AB'] = oldba + ba

                    self.players[row['Name']] = stats

                else:
                    self.players[row['Name']] = {'BA' : float(row['BA']), 'OBP' : float(row['OBP']), 'HR' : int(row['HR']), \
                    '2B' : int(row['2B']), '3B' : int(row['3B']), 'SB' : int(row['SB']), \
                    'RBI' : int(row['RBI']), 'R' : int(row['R']), 'PA' : int(row['PA']), \
                    'AB' : int(row['AB']) }
            self.progress.setValue(
                (num + 1) / len(teams) * 100)  #update progress bar

        #when data retrieval is done, disable download button
        self.btn.setText("Done!")
        self.btn.setEnabled(False)
        #add list of names to auto-completer
        self.model.setStringList(self.players.keys())