35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
import csv
|
|
import random
|
|
with open('spielplan_vorrunde.csv', newline='') as spielplan, open('team_rating.csv', newline='') as teamRating:
|
|
# readout CSVs
|
|
spieleCSV = csv.DictReader(spielplan)
|
|
ratingsCSV = csv.DictReader(teamRating)
|
|
|
|
# create absolute team rating dict
|
|
ratings = dict()
|
|
for row in ratingsCSV:
|
|
ratings[row['team']]=int(row['rating'])
|
|
|
|
# offset for relative strength
|
|
offset_rating = 0#min(ratings.values())-1
|
|
# standard deviation source says 1.9, but this is very high
|
|
std_dev = 1.3
|
|
# mean Goals per match
|
|
mean_goals = 2.2
|
|
|
|
for row in spieleCSV:
|
|
# get absolute rating
|
|
rating_home = ratings[row['Home Team']]
|
|
rating_away = ratings[row['Away Team']]
|
|
# calculate relative rating
|
|
relative_rating_home = (rating_home - offset_rating)/(rating_away - offset_rating)
|
|
relative_rating_away = 1/relative_rating_home
|
|
# calculate goals, no home advantage, round to positive integer
|
|
goals_home = max(0, round(random.gauss(mean_goals/2*relative_rating_home,std_dev/2)))
|
|
goals_away = max(0, round(random.gauss(mean_goals/2*relative_rating_away,std_dev/2)))
|
|
|
|
# output
|
|
print(row['Home Team'], row['Away Team'], str(relative_rating_home)+' : '+str(relative_rating_away), str(goals_home)+' : '+str(goals_away))
|
|
|
|
# keep window open
|
|
input() |