Skip to content

Instantly share code, notes, and snippets.

@patrick478
Last active February 29, 2016 23:36
Show Gist options
  • Save patrick478/42ae44a0e9d119e25190 to your computer and use it in GitHub Desktop.
Save patrick478/42ae44a0e9d119e25190 to your computer and use it in GitHub Desktop.
from __future__ import division
import random
def getHomeScore():
score = 0
num = random.random()
#using distribution of goals from top 4 Euro leagues 2000-2013
if num < .2256:
score = 0
elif num < 0.5593:
score = 1
elif num < 0.8082:
score = 2
elif num < 0.9316:
score = 3
elif num < 0.9788:
score = 4
elif num < 0.9942:
score = 5
elif num < 0.9988:
score = 6
else:
score = 7
return score
def getAwayScore():
score = 0
num = random.random()
#using distribution of goals from top 4 Euro leagues 2000-2013
if num < 0.3554:
score = 0
elif num < 0.7149:
score = 1
elif num < 0.9022:
score = 2
elif num < 0.9722:
score = 3
elif num < 0.9936:
score = 4
elif num < 0.9984:
score = 5
elif num < 0.9998:
score = 6
else:
score = 7
return score
inPlayoffsPointsCount = [0] * 56
totalPointsCount = [0] * 56
for i in range(10000000):
teams =[[1,"Adelaide"], [2, "Brisbane"], [3, "CCM"], [4, "Melbourne City"], [5, "Melbourne Victory"], [6, "Newcastle"],[7, "Perth"], [8, "Sydney FC"], [9, "Wellington"],[10, "Western Sydney"]]
matches = [[2,10], [9,1], [4,8], [3,5], [7,6],
[1,4], [8,9], [2,5], [7,3], [6,10],
[4,2], [3,8], [10,1], [9,7], [5,6],
[5,10], [6,7], [2,8], [1,3], [4,9],
[10,3], [9,5], [8,1], [2,6], [7,4],
[4, 1], [3,6], [5,2], [9,10], [8,7]]
points = [36, 35, 12, 32, 30, 26, 28, 30, 22, 38]
goal_diff = [8, 3, -24, 13, 4, -10, 2, 4, -9, 8]
for match in matches:
team1 = match[0]
team2 = match[1]
score1 = getHomeScore()
score2 = getAwayScore()
if score1 == score2:
points[team1-1] += 1
points[team2-1] += 1
elif score1 > score2:
points[team1-1] += 3
points[team2-1] += 0
elif score1 < score2:
points[team1-1] += 0
points[team2-1] += 3
goal_diff[team1-1] += score1-score2
goal_diff[team2-1] += score2-score1
sortedPoints = [i[0]+1 for i in sorted(enumerate(points), key=lambda x:x[1])][::-1]
nixFInalPos = sortedPoints.index(2)
totalPointsCount[points[8]] +=1
if(nixFInalPos <= 1):
inPlayoffsPointsCount[points[8]] += 1
for i in range(0, 56):
percentage = 0
if(totalPointsCount[i] > 0):
percentage = (inPlayoffsPointsCount[i]/totalPointsCount[i]) * 100
#print str.format("{} points: {}/{}", i, inPlayoffsPointsCount[i], totalPointsCount[i])
print str.format("{} points: {:.2f}%", i, percentage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment