Created
January 29, 2012 20:05
-
-
Save debuggerpk/1700402 to your computer and use it in GitHub Desktop.
calculate fixtures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __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