berechnungsskript
This commit is contained in:
33
fifa-calculator.py
Normal file
33
fifa-calculator.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
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
|
||||||
|
std_dev = 1.9
|
||||||
|
# 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),std_dev/2)*relative_rating_home))
|
||||||
|
## goals_away = max(0, round(random.gauss((mean_goals/2),std_dev/2)*relative_rating_away))
|
||||||
|
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)))
|
||||||
|
|
||||||
|
print(row['Home Team'], row['Away Team'], str(relative_rating_home)+' : '+str(relative_rating_away), str(goals_home)+' : '+str(goals_away))
|
||||||
Reference in New Issue
Block a user