Skip to content

Instantly share code, notes, and snippets.

@debuggerpk
Created January 29, 2012 20:05
Show Gist options
  • Select an option

  • Save debuggerpk/1700402 to your computer and use it in GitHub Desktop.

Select an option

Save debuggerpk/1700402 to your computer and use it in GitHub Desktop.
calculate fixtures
__author__ = 'yousuf'
from dateutil.rrule import *
from dateutil.relativedelta import *
import itertools
import datetime
import random
teams = 18
teams = range(1, teams+1)
#calculate possible fixture combinations
fixcombos = list(itertools.combinations(teams,2))
random.shuffle(fixcombos)
nofixtures = len(fixcombos)
datestart = datetime.date.today()
dateend = datestart + datetime.timedelta(days=125)
#calculate possible fixture dates,
# rrule is part of dateutil (a custom python library for date manipulation)
# SA and SU stands for saturday and sunday
fixdays = list(rrule(DAILY, byweekday=(SA,SU), dtstart=datestart, until=dateend))
nofmatchdays = len(fixdays)
perday = nofixtures/nofmatchdays +1
perday = range(0,perday)
for x in perday:
fixdays = fixdays + fixdays
fixarray = range(0, nofixtures)
for y in fixarray:
printline = 'Date: ' + str(fixdays[y]) + ': Teams Involved: ' + str(fixcombos[y])
print printline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment