Astros Scorecard

Last Updated:
Astros logo
HoleWinsLossesScore-5
14833-3(+1)
104734-5(+1)
Avg4834+30

Analysis

Here is a Python script that parses the given text and outputs the final standings for each team.

import re

class Team:
    def __init__(self, name):
        self.name = name
        self.wins = 0
        self.losses = 0
        self.ties = 0

    def update_record(self, opponent, result, type):
        if result == 'win':
            if type == 'home' or type == 'away':
                self.wins += 1
            else:
                self.losses += 1
        elif result == 'loss':
            if type == 'home' or type == 'away':
                self.losses += 1
            else:
                self.wins += 1
        elif result == 'tie':
            if type == 'home' or type == 'away':
                self.ties += 1
            else:
                print(f"Unrecognized tie type: {type}")

def parse_match(match_text, team):
    match_info = re.findall(r'(home|away) \d+, (win|loss|tie)', match_text)
    for info in match_info:
        result = 'unknown'
        if info[0] == 'win':
            result = 'win'
        elif info[0] == 'loss':
            result = 'loss'
        else:
            result = 'tie'
        type = 'home' if info[1] == 'home' else 'away'
        team.update_record(opponent, result, type)

def parse_standings(match_text):
    teams = {}
    lines = match_text.split('\n')
    for line in lines:
        match_info = re.findall(r'\d+ - \d+', line)
        if match_info:
            home_team_name = re.search(r'Team (.*?) -', line).group(1)
            away_team_name = re.search(r'- Team (.*?) ', line).group(1)
            teams[home_team_name] = Team(home_team_name)
            teams[away_team_name] = Team(away_team_name)
    for match_text in lines:
        match_info = re.findall(r'(home|away) \d+, (win|loss|tie)', match_text)
        for info in match_info:
            team1, result, type = info
            if result == 'unknown':
                print(f"Unrecognized result: {result} on match_text: {match_text}")
                continue
            team1_name = re.search(r'Team (.*?) -', match_text).group(1)
            if team1 not in teams:
                continue
            team2, opponent = None, None
            for line in lines:
                if f'{opponent} - Team {team1_name}' in line or f'Team {team1_name} - {opponent}' in line:
                    team2_name = re.search(r'- Team (.*?) ', line).group(1)
                    break
            else:
                continue
            if type == 'home' or type == 'away':
                teams[team1_name].update_record(opponent, result, type)
                if team2_name != team1_name and teams[team2_name] != None:
                    teams[team2_name].update_record(team1_name, result, type)

    # Add the final standings to each team
    for team in teams.values():
        print(f"{team.name}:\nWin-Loss-Tie: {team.wins}-{team.losses}-{team.ties}")

standings = []
with open('data.txt', 'r') as file:
    match_text = file.read()
lines = match_text.split('\n')
for line in lines:
    if not re.match(r'\d+ - \d+', line):
        continue
    standings.append(line)
parse_standings(standings)

Here is the Python program that reads from data.txt, extracts game data, and prints each team's final score.

The script starts by reading the file into a list of lines. It then parses through this list to identify which games are played. The games are split between home teams and away teams, with the line Team Team - in between them.

Each game is also broken down further into two main parts: wins/losses/ties against an opponent, and the specific results of each matchup.

For simplicity's sake, we assume that a 'win' or 'loss' result directly maps to either +1 win on our scoreboard for home teams or away teams, respectively, while a tie result maps to zero. Updated: April 16, 2025 at 1:00 AM