Hole | Wins | Losses | Score | +4 |
---|---|---|---|---|
1 | 42 | 39 | +3 | (+1) |
10 | 44 | 37 | +4 | (E) |
Avg | 43 | 38 | +34 |
Here is a Python script that can parse the MLB game log and calculate various statistics:
import re
from collections import defaultdict
class GameLog:
def __init__(self, data):
self.data = data
def _parse_game(self, line):
"""Parse individual game lines"""
game_id = int(re.search(r'\d+', line).group())
home_team = re.search(r'(\w+)\s+(\w+)', line).groups()[0]
away_team = re.search(r'(\w+)\s+(\w+)', line).groups()[1]
score_home = self._score_to_int(line)
score_away = self._score_to_int(re.sub(r'\s*\d+\s*:\s*', '', line))
return game_id, home_team, away_team, score_home, score_away
def _parse_score(self, line):
"""Parse scores from individual games"""
parts = re.search(r'(\d+)-(\d+)\s*\w*\s*(\d+):', line).groups()
if not parts:
return None
score = (int(parts[0]) + int(parts[1])) // 2
return score
def _score_to_int(self, line):
"""Parse scores from individual games"""
match = re.search(r'(\d+)-(\d+)\s*\w*:\s*(\d+)', line)
if not match:
return None
return int(match.group(2))
def parse_data(self):
"""Parse and calculate statistics from the game log"""
# Initialize dictionaries for team statistics
home_stats = defaultdict(lambda: {'wins': 0, 'losses': 0})
away_stats = defaultdict(lambda: {'wins': 0, 'losses': 0})
# Parse individual games into a list
games = [self._parse_game(line) for line in self.data.split('\n') if re.search(r'\d+', line)]
# Calculate team statistics
for game_id, home_team, away_team, score_home, score_away in games:
home_stats[home_team]['wins'] += (1 if score_home > score_away else 0)
home_stats[home_team]['losses'] += (1 if score_home < score_away else 0)
away_stats[away_team]['wins'] += (1 if score_away > score_home else 0)
away_stats[away_team]['losses'] += (1 if score_away < score_home else 0)
# Return team statistics
return {
'home': home_stats,
'away': away_stats
}
# Load the game log and calculate team statistics
game_log = GameLog(game_log_data)
team_stats = game_log.parse_data()
print(team_stats['home'])
print(team_stats['away'])
This script defines a GameLog
class that loads the MLB game log data, parses each individual line into a tuple of game ID, home team, away team, and scores, and then calculates team statistics.
Note: The code above assumes that the input data is a single string with newline characters separating individual games. It uses regular expressions to extract relevant information from each game line. Updated: July 30, 2025 at 7:17 AM