Example #1
0
def JuniorMales(request):
    params = Parameters()
    context = {}
    if request.method == "POST":
        unique_jr_males, competing_jr_males, unique_jr_females, competing_jr_females = Create2DivJuniors(
        )  # Generate those with 2 jr divisions
        JMDivisions = genJrMaleDivisions()
        result = finders.find('registration/2man.png')
        template_loc = finders.searched_locations[0]
        filePath = os.path.join(template_loc, 'registration', 'poolsheets')
        for div in JMDivisions:
            competitors = [
                p.person.first_Name + ' ' + p.person.last_Name for p in div[2]
            ]
            gender = "Male"
            cat = div[0]
            wt = str(div[1])
            fileName = CreatePDFBrackets(competitors, gender, cat, wt,
                                         template_loc, filePath)
            div[-1] = fileName
        # Figure out who's not in divisions!!!
        context = {
            'unique_jr_males': unique_jr_males,
            'competing_jr_males': competing_jr_males,
            'unique_jr_females': unique_jr_females,
            'competing_jr_females': competing_jr_females,
            'JMDivisions': JMDivisions,
            'JFDivisions': None
        }
    return render(request, "create_divisions.html", context)
Example #2
0
def genJrDivisions():
    params = Parameters()
    # Junior Female Divisions
    JFDivisions = []
    for age, weight in params.JF_WEIGHT.items():
        weight.append(0)
        for w in weight:
            g = JuniorFemale.objects.filter(age_group=age, weight_class=w)
            total_matches = computeMatches(g)
            JFDivisions.append([
                age, w, g, total_matches,
                total_matches * params.JR_MATCH_TIMES[age], ''
            ])
    # Junior Male Divisions
    JMDivisions = []
    for age, weight in params.JM_WEIGHT.items():
        weight.append(0)
        for w in weight:
            g = JuniorMale.objects.filter(age_group=age, weight_class=w)
            total_matches = computeMatches(g)
            JMDivisions.append([
                age, w, g, total_matches,
                total_matches * params.JR_MATCH_TIMES[age], ''
            ])
    return JMDivisions, JFDivisions
Example #3
0
def CreateSeniorDivisions(request):
    params = Parameters()
    context = {}
    """if request.method == "POST":
        unique_jr_males,competing_jr_males,unique_jr_females,competing_jr_females = Create2DivJuniors() # Generate those with 2 jr divisions
        JMDivisions, JFDivisions = genJrDivisions()
        # Figure out who's not in divisions!!!
        context = {'unique_jr_males':unique_jr_males,
               'competing_jr_males':competing_jr_males,
               'unique_jr_females':unique_jr_females,
               'competing_jr_females':competing_jr_females,
               'JMDivisions':JMDivisions, 'JFDivisions':JFDivisions}"""
    return render(request, "create_divisions.html", context)
Example #4
0
def Create2DivJuniors():
    params = Parameters()
    unique_jr_males = Person.objects.filter(category__icontains="Jr",
                                            sex="M").count()
    # If second division is age based
    for jm in JuniorMale.objects.filter(up_one_age=True):
        if len(JuniorMale.objects.filter(person=jm.person)) >= 2:
            pass
        else:
            yr = int(jm.person.date_of_Birth.strftime('%Y'))
            try:
                while params.JM_AGES[yr] == jm.age_group:
                    yr -= 1
                new_jm = jm
                new_jm.age_group = params.JM_AGES[yr]
                new_jm.pk = None
                new_jm.save()
            except:
                print(jm)
    # If second division is weight based
    for jm in JuniorMale.objects.filter(up_one_weight=True):
        if len(JuniorMale.objects.filter(person=jm.person)) >= 2:
            pass
        else:
            try:
                weight_ind = params.JM_WEIGHT[jm.age_group].index(
                    jm.weight_class)
                new_jm = jm
                new_jm.weight_class = params.JM_WEIGHT[jm.age_group][weight_ind
                                                                     + 1]
                new_jm.pk = None
                new_jm.save()
            except:
                print(jm)
    # Count again
    competing_jr_males = JuniorMale.objects.count()

    unique_jr_females = Person.objects.filter(category__icontains="Jr",
                                              sex="F").count()
    # If second division is age based
    for jf in JuniorFemale.objects.filter(up_one_age=True):
        if len(JuniorFemale.objects.filter(person=jf.person)) >= 2:
            pass
        else:
            yr = int(jf.person.date_of_Birth.strftime('%Y'))
            try:
                while params.JF_AGES[yr] == jf.age_group:
                    yr -= 1
                new_jf = jf
                new_jf.age_group = params.JF_AGES[yr]
                new_jf.pk = None
                new_jf.save()
            except:
                print(jf)
    # If second division is weight based
    for jf in JuniorFemale.objects.filter(up_one_weight=True):
        if len(JuniorFemale.objects.filter(person=jf.person)) >= 2:
            pass
        else:
            try:
                weight_ind = params.JF_WEIGHT[jf.age_group].index(
                    jf.weight_class)
                new_jf = jf
                new_jf.weight_class = params.JF_WEIGHT[jf.age_group][weight_ind
                                                                     + 1]
                new_jf.pk = None
                new_jf.save()
            except:
                print(jf)
    # Count again
    competing_jr_females = JuniorFemale.objects.count()
    return unique_jr_males, competing_jr_males, unique_jr_females, competing_jr_females
Example #5
0
def Gen16Man(competitors, gender, cat, wt, template_loc, filePath):

    prepend = str(len(competitors)) + 'man_MD_'
    fileName = GiveName(prepend, gender, cat, wt)
    result = os.path.join(template_loc, '16man.png')
    c = canvas.Canvas(os.path.join(filePath, fileName), pagesize=letter)
    width, height = letter
    c.setLineWidth(.3)
    c.setFont('Helvetica', 8)

    ncomp = 16
    byes = ncomp - len(competitors)
    players = [""] * ncomp
    if byes == 7:
        bye_locs = [0, 2, 4, 6, 8, 10, 12]
    elif byes == 6:
        bye_locs = [0, 2, 4, 8, 10, 12]
    elif byes == 5:
        bye_locs = [0, 2, 4, 8, 10]
    elif byes == 4:
        bye_locs = [0, 2, 8, 10]
    elif byes == 3:
        bye_locs = [0, 2, 8]
    elif byes == 2:
        bye_locs = [0, 8]
    elif byes == 1:
        bye_locs = [0]
    else:
        bye_locs = []

    j = 0
    for i in range(ncomp):
        if i in bye_locs:
            players[i] = "Bye"
        else:
            players[i] = competitors[j]
            j += 1

    deltay = 0.3 * inch
    start = 0.5 * inch
    startLeft = 0.4 * inch
    deltaline = 0.05 * inch

    imgwidth = 31.93 * inch
    imgheight = 36.61 * inch
    scaleFac = 0.25

    leftBracket = 0.65 * inch

    start1 = height - start
    start2 = height - start - deltaline
    c.drawString(startLeft, start1, "Gender: " + gender)
    c.drawString(width - 8 * start, start1, "1st (W15)")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    start2 = start1 - deltaline
    c.drawString(startLeft, start1, "Category: " + cat)
    c.drawString(width - 8 * start, start1, "2nd (W16)")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    start2 = start1 - deltaline
    c.drawString(startLeft, start1, "Weight Class: " + wt)
    c.drawString(width - 8 * start, start1, "3rd (L16)")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    c.drawString(startLeft, start1, "Mat Area: ")

    c.drawImage(result,
                0.5 * start,
                start - 0.5 * inch,
                width=scaleFac * imgwidth,
                height=scaleFac * imgheight)

    for i, player in enumerate(players):
        c.drawString(leftBracket, 8.75 * inch - i * 0.345 * inch, player)
        if player == "Bye":
            c.drawString(leftBracket,
                         8.75 * inch - (17.6 + i / 2) * 0.345 * inch, player)

    c.setFont('Helvetica', 12)
    params = Parameters()
    match_time = params.JR_MATCH_TIMES[cat]
    c.drawString(width / 2 - 2 * inch, height - start, "Match Time:")
    c.drawString(width / 2 - 2 * inch, height - start - deltay,
                 str(match_time) + " minutes")

    c.save()
    return fileName
Example #6
0
def Gen8Man(competitors, gender, cat, wt, template_loc, filePath):

    prepend = str(len(competitors)) + 'man_MD_'
    fileName = GiveName(prepend, gender, cat, wt)
    result = os.path.join(template_loc, '8man.png')
    c = canvas.Canvas(os.path.join(filePath, fileName), pagesize=letter)
    width, height = landscape(letter)
    c.setLineWidth(.3)
    c.setFont('Helvetica', 10)

    byes = 8 - len(competitors)
    players = [""] * 8
    if byes == 1:
        bye_locs = [0]
    elif byes == 2:
        bye_locs = [0, 4]
    else:
        bye_locs = []

    j = 0
    for i in range(8):
        if i in bye_locs:
            players[i] = "Bye"
        else:
            players[i] = competitors[j]
            j += 1

    deltay = 0.3 * inch
    start = 0.5 * inch
    startLeft = 0.8 * inch
    deltaline = 0.05 * inch

    imgwidth = 25.11 * inch
    imgheight = 19.67 * inch
    scaleFac = 0.35

    leftBracket = 1.3 * inch

    start1 = height - start
    start2 = height - start - deltaline
    c.drawString(startLeft, start1, "Gender: " + gender)
    c.drawString(width - 8 * start, start1, "1st (W7)")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    start2 = start1 - deltaline
    c.drawString(startLeft, start1, "Category: " + cat)
    c.drawString(width - 8 * start, start1, "2nd (W8)")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    start2 = start1 - deltaline
    c.drawString(startLeft, start1, "Weight Class: " + wt)
    c.drawString(width - 8 * start, start1, "3rd (L8)")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    c.drawString(startLeft, start1, "Mat Area: ")

    c.drawImage(result,
                1.5 * start,
                start - 0.5 * inch,
                width=scaleFac * imgwidth,
                height=scaleFac * imgheight)

    for i, player in enumerate(players):
        c.drawString(leftBracket, 6.35 * inch - i * 0.49 * inch, player)
        if player == "Bye":
            if i == 0:
                c.drawString(leftBracket, 1.94 * inch, player)
            elif i == 4:
                c.drawString(leftBracket, 0.96 * inch, player)

    c.setFont('Helvetica', 12)
    params = Parameters()
    match_time = params.JR_MATCH_TIMES[cat]
    c.drawString(width / 2 - 2 * inch, height - start, "Match Time:")
    c.drawString(width / 2 - 2 * inch, height - start - deltay,
                 str(match_time) + " minutes")

    c.save()
    return fileName
Example #7
0
def Gen5Man(competitors, gender, cat, wt, template_loc, filePath):

    prepend = '5man_RR_'
    fileName = GiveName(prepend, gender, cat, wt)
    result = os.path.join(template_loc, '5man.png')
    c = canvas.Canvas(os.path.join(filePath, fileName), pagesize=letter)
    width, height = landscape(letter)
    c.setLineWidth(.3)
    c.setFont('Helvetica', 9)
    (player1, player2, player3, player4, player5) = competitors

    deltay = 0.3 * inch
    start = 0.5 * inch
    startLeft = 0.8 * inch
    deltaline = 0.05 * inch

    imgwidth = 30.5 * inch
    imgheight = 22.17 * inch
    scaleFac = 0.3

    leftBracket = 1.6 * inch

    start1 = height - start
    start2 = height - start - deltaline
    c.drawString(startLeft, start1, "Gender: " + gender)
    c.drawString(width - 8 * start, start1, "1st")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    start2 = start1 - deltaline
    c.drawString(startLeft, start1, "Category: " + cat)
    c.drawString(width - 8 * start, start1, "2nd")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    start2 = start1 - deltaline
    c.drawString(startLeft, start1, "Weight Class: " + wt)
    c.drawString(width - 8 * start, start1, "3rd")
    c.line(width - 8 * start, start2, width - start, start2)
    start1 -= deltay
    c.drawString(startLeft, start1, "Mat Area: ")

    result = finders.find('registration/5man.png')
    c.drawImage(result,
                1.5 * inch,
                start - 0.1 * inch,
                width=scaleFac * imgwidth,
                height=scaleFac * imgheight)

    c.drawString(leftBracket, 6.6 * inch, player1)
    c.drawString(leftBracket, 6.15 * inch, player2)
    c.drawString(leftBracket, 5.75 * inch, player3)
    c.drawString(leftBracket, 5.3 * inch, player4)

    c.drawString(leftBracket, 4.45 * inch, player1)
    c.drawString(leftBracket, 4.05 * inch, player3)
    c.drawString(leftBracket, 3.6 * inch, player2)
    c.drawString(leftBracket, 3.2 * inch, player5)

    c.drawString(leftBracket, 2.1 * inch, player3)
    c.drawString(leftBracket, 1.7 * inch, player5)
    c.drawString(leftBracket, 1.25 * inch, player1)
    c.drawString(leftBracket, 0.85 * inch, player4)

    c.drawString(leftBracket + 4.7 * inch, 6.6 * inch, player4)
    c.drawString(leftBracket + 4.7 * inch, 6.15 * inch, player5)
    c.drawString(leftBracket + 4.7 * inch, 5.75 * inch, player2)
    c.drawString(leftBracket + 4.7 * inch, 5.3 * inch, player3)

    c.drawString(leftBracket + 4.7 * inch, 4.45 * inch, player1)
    c.drawString(leftBracket + 4.7 * inch, 4.05 * inch, player5)
    c.drawString(leftBracket + 4.7 * inch, 3.6 * inch, player2)
    c.drawString(leftBracket + 4.7 * inch, 3.2 * inch, player4)

    c.drawString(leftBracket + 4.7 * inch, 2.3 * inch, player1)
    c.drawString(leftBracket + 4.7 * inch, 1.9 * inch, player2)
    c.drawString(leftBracket + 4.7 * inch, 1.45 * inch, player3)
    c.drawString(leftBracket + 4.7 * inch, 1.05 * inch, player4)
    c.drawString(leftBracket + 4.7 * inch, 0.6 * inch, player5)

    c.setFont('Helvetica', 12)
    params = Parameters()
    match_time = params.JR_MATCH_TIMES[cat]
    c.drawString(width / 2 - 2 * inch, height - start, "Match Time:")
    c.drawString(width / 2 - 2 * inch, height - start - deltay,
                 str(match_time) + " minutes")

    c.save()
    return fileName