Skip to content

Instantly share code, notes, and snippets.

@prophile
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prophile/f15a934c3fb23134a40b to your computer and use it in GitHub Desktop.
Save prophile/f15a934c3fb23134a40b to your computer and use it in GitHub Desktop.
Calculate the number of matches in a league
from __future__ import print_function, division
import argparse
from datetime import timedelta
from math import ceil, floor
def parse_time(x):
hours, minutes = x.split(':')
return timedelta(hours=int(hours), minutes=int(minutes))
parser = argparse.ArgumentParser(description='Calculate statistics about matches for an SR competition')
parser.add_argument('--arenas', type=int, default=1,
help='Number of arenas')
parser.add_argument('--time', type=parse_time, required=True, help='Total league time')
parser.add_argument('--teams', type=int, required=True, help='Number of teams')
parser.add_argument('--entrants', type=int, default=4, help='Number of entrants into each agme')
parser.add_argument('--match-length', type=int, default=5, help='Length of each of match in minutes')
parser.add_argument('--verbose', action='store_true', help='Give more verbose output')
args = parser.parse_args()
if args.verbose:
vprint = print
else:
def vprint(*args, **kwargs):
pass
slots = int(floor(args.time.total_seconds() / (60 * args.match_length)))
vprint('{} slots'.format(slots))
entrants_per_slot = args.arenas * args.entrants
slots_required_for_allvsall = int(ceil(args.teams / entrants_per_slot))
vprint('{} slots required for an all vs all'.format(slots_required_for_allvsall))
rounds = int(floor(slots / slots_required_for_allvsall))
print('{} matches per team'.format(rounds))
time_between_matches_seconds = args.time.total_seconds() / (rounds + 1)
print('Average time between matches: {}'.format(timedelta(seconds=time_between_matches_seconds)))
float_periods = slots - (rounds * slots_required_for_allvsall)
vprint('Float time: {} ({} match periods)'.format(timedelta(minutes=float_periods*args.match_length), float_periods))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment