import csv
import random
import numpy as np
# Read teams from [Link]
teams = []
with open('[Link]', 'r') as f:
reader = [Link](f)
for row in reader:
if row: # Skip empty rows
[Link](row[0].strip())
# Read matches and odds from [Link]
matches = []
with open('[Link]', 'r') as f:
reader = [Link](f)
next(reader) # Skip header if present
for row in reader:
if not row: # Skip empty rows
continue
home_team = row[0].strip()
away_team = row[1].strip()
try:
home_odds = float(row[2])
draw_odds = float(row[3])
away_odds = float(row[4])
except (IndexError, ValueError) as e:
print(f"Error processing row {row}: {e}")
continue
[Link]({
'home_team': home_team,
'away_team': away_team,
'home_odds': home_odds,
'draw_odds': draw_odds,
'away_odds': away_odds
})
# Simulate each match and generate scores
for match in matches:
ho = match['home_odds']
do = match['draw_odds']
ao = match['away_odds']
# Avoid division by zero
if ho <= 0 or do <= 0 or ao <= 0:
raise ValueError("Odds must be greater than zero.")
# Calculate probabilities from odds
recip_home = 1.0 / ho
recip_draw = 1.0 / do
recip_away = 1.0 / ao
total = recip_home + recip_draw + recip_away
prob_home = recip_home / total
prob_draw = recip_draw / total
prob_away = recip_away / total
# Determine outcome
outcome = [Link](['home', 'draw', 'away'], p=[prob_home, prob_draw, prob_away])
# Generate scores based on outcome
if outcome == 'home':
home_score = [Link](1, 4)
away_score = [Link](0, home_score - 1)
elif outcome == 'draw':
home_score = [Link](0, 3)
away_score = home_score
else: # away win
away_score = [Link](1, 4)
home_score = [Link](0, away_score - 1)
match['home_score'] = home_score
match['away_score'] = away_score
# Write results to [Link]
with open('[Link]', 'w', newline='') as f:
writer = [Link](f)
[Link](['HomeTeam', 'AwayTeam', 'HomeWinOdds', 'DrawOdds', 'AwayWinOdds',
'HomeScore', 'AwayScore'])
for match in matches:
[Link]([
match['home_team'],
match['away_team'],
match['home_odds'],
match['draw_odds'],
match['away_odds'],
match['home_score'],
match['away_score']
])
print("Simulation complete. Results saved to [Link]")