示例#1
0
def rank_debaters(request):
    speakers = tab_logic.rank_speakers()
    debaters = [(s, tab_logic.tot_speaks_deb(s), tab_logic.tot_ranks_deb(s), tab_logic.deb_team(s)) for s in speakers]

    nov_speakers = tab_logic.rank_nov_speakers()
    nov_debaters = [
        (s, tab_logic.tot_speaks_deb(s), tab_logic.tot_ranks_deb(s), tab_logic.deb_team(s)) for s in nov_speakers
    ]

    return render_to_response(
        "rank_debaters_component.html",
        {"debaters": debaters, "nov_debaters": nov_debaters, "title": "Speaker Rankings"},
        context_instance=RequestContext(request),
    )
示例#2
0
def rank_debaters(request):
    speakers = tab_logic.rank_speakers()
    debaters = [(s, tab_logic.tot_speaks_deb(s), tab_logic.tot_ranks_deb(s),
                 tab_logic.deb_team(s)) for s in speakers]

    nov_speakers = tab_logic.rank_nov_speakers()
    nov_debaters = [(s, tab_logic.tot_speaks_deb(s),
                     tab_logic.tot_ranks_deb(s), tab_logic.deb_team(s))
                    for s in nov_speakers]

    return render_to_response('rank_debaters_component.html', {
        'debaters': debaters,
        'nov_debaters': nov_debaters,
        'title': "Speaker Rankings"
    },
                              context_instance=RequestContext(request))
示例#3
0
 def make_debater_row(self, debater):
     return (
         debater.name,
         tab_logic.deb_team(debater).name if tab_logic.deb_team(debater) else "",
         tab_logic.tot_speaks_deb(debater),
         tab_logic.tot_ranks_deb(debater)
     )
示例#4
0
def export_debater_stats(request):
    """Exports data as XLS for each speaker: total speaker points, total ranks, single adjusted speaks, single adjusted
    ranks, double adjusted speaks, double adjusted ranks, team performance, opposition strength. Automatically averages
    for iron-men. """
    book = Workbook('utf-8')
    sheet = book.add_sheet('Team stats')

    sheet.write(
        0, 0,
        'If you are calculating the awards off these statistics, please pay attention to how you sort. '
        'In general, everything except ranks should be sorted from large to small.'
    )

    headers = [
        'debater name', 'total speaker points', 'total ranks',
        'single-adjusted speaker points', 'single-adjusted ranks',
        'double-adjusted speaker points', 'double-adjusted ranks',
        'team performance (debater\'s team win#)', 'opposition strength'
    ]
    for i in xrange(len(headers)):
        sheet.write(1, i, headers[i])

    debaters = Debater.objects.all()
    for i in xrange(len(debaters)):
        debater, row = debaters[i], i + 2
        sheet.write(row, 0, debater.name)
        sheet.write(row, 1,
                    tab_logic.tot_speaks_deb(debater, average_ironmen=True))
        sheet.write(row, 2, tab_logic.tot_ranks_deb(debater, True))
        sheet.write(row, 3, tab_logic.single_adjusted_speaks_deb(debater))
        sheet.write(row, 4, tab_logic.single_adjusted_ranks_deb(debater))
        sheet.write(row, 5, tab_logic.double_adjusted_speaks_deb(debater))
        sheet.write(row, 6, tab_logic.double_adjusted_ranks_deb(debater))
        sheet.write(
            row, 7,
            tab_logic.tot_wins(
                Team.objects.filter(debaters__name=debater.name).first()))
        sheet.write(row, 8, tab_logic.opp_strength(debater))

    # construct response
    response = HttpResponse(content_type='application/vnd.ms-excel')
    response[
        'Content-Disposition'] = 'attachment; filename=mittab-debater-stats.xls'
    book.save(response)
    return response
示例#5
0
 def make_debater_row(self, debater):
     return (debater.name, tab_logic.deb_team(debater).name
             if tab_logic.deb_team(debater) else "",
             tab_logic.tot_speaks_deb(debater),
             tab_logic.tot_ranks_deb(debater))
示例#6
0
def tab_card(request, team_id):
    try:
        team_id = int(team_id)
    except ValueError:
        return redirect_and_flash_error(request, "Invalid team id")
    team = Team.objects.get(pk=team_id)
    rounds = ([r for r in Round.objects.filter(gov_team=team)] +
              [r for r in Round.objects.filter(opp_team=team)])
    rounds.sort(key =lambda x: x.round_number)
    roundstats = [RoundStats.objects.filter(round=r) for r in rounds]
    debaters = [d for d in team.debaters.all()]
    iron_man = False
    if (len(debaters) == 1):
      iron_man = True
    d1 = debaters[0]
    if (not iron_man):
      d2 = debaters[1]
    round_stats = []
    num_rounds = TabSettings.objects.get(key="tot_rounds").value
    cur_round = TabSettings.objects.get(key="cur_round").value
    blank = " ";
    for i in range(num_rounds):
        round_stats.append([blank]*7)

    for r in rounds:
        dstat1 = [k for k in RoundStats.objects.filter(debater=d1).filter(round=r).all()]
        dstat2 = []
        if (not iron_man):
          dstat2 = [k for k in RoundStats.objects.filter(debater=d2).filter(round=r).all()]
        blank_rs = RoundStats(debater=d1, round=r, speaks=0, ranks=0)
        while len(dstat1) + len(dstat2) < 2:
            # Something is wrong with our data, but we don't want to crash
            dstat1.append(blank_rs)
        if not dstat2 and not dstat1:
            break
        if not dstat2:
            dstat1,dstat2 = dstat1[0], dstat1[1]
        elif not dstat1:
            dstat1,dstat2 = dstat2[0], dstat2[1]
        else:
            dstat1,dstat2 = dstat1[0], dstat2[0]
        index = r.round_number - 1
        round_stats[index][3] = " - ".join([j.name for j in r.judges.all()])
        round_stats[index][4] = (float(dstat1.speaks), float(dstat1.ranks))
        round_stats[index][5] = (float(dstat2.speaks), float(dstat2.ranks))
        round_stats[index][6] = (float(dstat1.speaks + dstat2.speaks), float(dstat1.ranks + dstat2.ranks))

        if r.gov_team == team:
            round_stats[index][2] = r.opp_team
            round_stats[index][0] = "G"
            if r.victor == 1:
                round_stats[index][1] = "W"
            elif r.victor == 2 :
                round_stats[index][1] = "L"
            elif r.victor == 3:
                round_stats[index][1] = "WF"
            elif r.victor == 4 :
                round_stats[index][1] = "LF"
            elif r.victor == 5 :
                round_stats[index][1] = "AD"
            elif r.victor == 6:
                round_stats[index][1] = "AW"
        elif r.opp_team == team:
            round_stats[index][2] = r.gov_team
            round_stats[index][0] = "O"
            if r.victor == 1:
                round_stats[index][1] = "L"
            elif r.victor == 2 :
                round_stats[index][1] = "W"
            elif r.victor == 3:
                round_stats[index][1] = "LF"
            elif r.victor == 4 :
                round_stats[index][1] = "WF"
            elif r.victor == 5 :
                round_stats[index][1] = "AD"
            elif r.victor == 6:
                round_stats[index][1] = "AW"

    for i in range(cur_round-1):
        if round_stats[i][6] == blank:
            round_stats[i][6] = (0,0)
    for i in range(1,cur_round-1):
        round_stats[i][6] = (round_stats[i][6][0] + round_stats[i-1][6][0],
                             round_stats[i][6][1] + round_stats[i-1][6][1])
    #Error out if we don't have a bye
    try:
        bye_round = Bye.objects.get(bye_team = team).round_number
    except:
        bye_round = None

    #Duplicates Debater 1 for display if Ironman team    
    if (iron_man):
      d2 = d1
    return render(request, 'tab/tab_card.html', 
                             {'team_name': team.name,
                              'team_school': team.school,
                              'debater_1': d1.name,
                              'debater_1_status': Debater.NOVICE_CHOICES[d1.novice_status][1],
                              'debater_2': d2.name,
                              'debater_2_status': Debater.NOVICE_CHOICES[d2.novice_status][1],
                              'round_stats': round_stats,
                              'd1st': tot_speaks_deb(d1),
                              'd1rt': tot_ranks_deb(d1),
                              'd2st': tot_speaks_deb(d2),
                              'd2rt': tot_ranks_deb(d2),
                              'ts': tot_speaks(team),
                              'tr': tot_ranks(team),
                              'bye_round': bye_round})
示例#7
0
def tab_card(request, team_id):
    try:
        team_id = int(team_id)
    except ValueError:
        return render_to_response('error.html', {
            'error_type': "Tab Card",
            'error_name': "View",
            'error_info': "Team id must be an integer!"
        },
                                  context_instance=RequestContext(request))
    team = Team.objects.get(pk=team_id)
    rounds = ([r for r in Round.objects.filter(gov_team=team)] +
              [r for r in Round.objects.filter(opp_team=team)])
    rounds.sort(key=lambda x: x.round_number)
    roundstats = [RoundStats.objects.filter(round=r) for r in rounds]
    debaters = [d for d in team.debaters.all()]
    iron_man = False
    if (len(debaters) == 1):
        iron_man = True
    d1 = debaters[0]
    if (not iron_man):
        d2 = debaters[1]
    round_stats = []
    num_rounds = TabSettings.objects.get(key="tot_rounds").value
    cur_round = TabSettings.objects.get(key="cur_round").value
    blank = " "
    for i in range(num_rounds):
        round_stats.append([blank] * 7)

    for r in rounds:
        dstat1 = [
            k for k in RoundStats.objects.filter(debater=d1).filter(
                round=r).all()
        ]
        dstat2 = []
        if (not iron_man):
            dstat2 = [
                k for k in RoundStats.objects.filter(debater=d2).filter(
                    round=r).all()
            ]
        blank_rs = RoundStats(debater=d1, round=r, speaks=0, ranks=0)
        while len(dstat1) + len(dstat2) < 2:
            # Something is wrong with our data, but we don't want to crash
            dstat1.append(blank_rs)
        if not dstat2 and not dstat1:
            break
        if not dstat2:
            dstat1, dstat2 = dstat1[0], dstat1[1]
        elif not dstat1:
            dstat1, dstat2 = dstat2[0], dstat2[1]
        else:
            dstat1, dstat2 = dstat1[0], dstat2[0]
        index = r.round_number - 1
        round_stats[index][3] = " - ".join([j.name for j in r.judges.all()])
        round_stats[index][4] = (float(dstat1.speaks), float(dstat1.ranks))
        round_stats[index][5] = (float(dstat2.speaks), float(dstat2.ranks))
        round_stats[index][6] = (float(dstat1.speaks + dstat2.speaks),
                                 float(dstat1.ranks + dstat2.ranks))

        if r.gov_team == team:
            round_stats[index][2] = r.opp_team
            round_stats[index][0] = "G"
            if r.victor == 1:
                round_stats[index][1] = "W"
            elif r.victor == 2:
                round_stats[index][1] = "L"
            elif r.victor == 3:
                round_stats[index][1] = "WF"
            elif r.victor == 4:
                round_stats[index][1] = "LF"
            elif r.victor == 5:
                round_stats[index][1] = "AD"
            elif r.victor == 6:
                round_stats[index][1] = "AW"
        elif r.opp_team == team:
            round_stats[index][2] = r.gov_team
            round_stats[index][0] = "O"
            if r.victor == 1:
                round_stats[index][1] = "L"
            elif r.victor == 2:
                round_stats[index][1] = "W"
            elif r.victor == 3:
                round_stats[index][1] = "LF"
            elif r.victor == 4:
                round_stats[index][1] = "WF"
            elif r.victor == 5:
                round_stats[index][1] = "AD"
            elif r.victor == 6:
                round_stats[index][1] = "AW"

    for i in range(cur_round - 1):
        if round_stats[i][6] == blank:
            round_stats[i][6] = (0, 0)
    for i in range(1, cur_round - 1):
        round_stats[i][6] = (round_stats[i][6][0] + round_stats[i - 1][6][0],
                             round_stats[i][6][1] + round_stats[i - 1][6][1])
    # Error out if we don't have a bye
    try:
        bye_round = Bye.objects.get(bye_team=team).round_number
    except:
        bye_round = None

    # Duplicates Debater 1 for display if Ironman team
    if (iron_man):
        d2 = d1
    return render_to_response(
        'tab_card.html', {
            'team_name': team.name,
            'team_school': team.school,
            'debater_1': d1.name,
            'debater_1_status': Debater.NOVICE_CHOICES[d1.novice_status][1],
            'debater_2': d2.name,
            'debater_2_status': Debater.NOVICE_CHOICES[d2.novice_status][1],
            'round_stats': round_stats,
            'd1st': tot_speaks_deb(d1),
            'd1rt': tot_ranks_deb(d1),
            'd2st': tot_speaks_deb(d2),
            'd2rt': tot_ranks_deb(d2),
            'ts': tot_speaks(team),
            'tr': tot_ranks(team),
            'bye_round': bye_round
        },
        context_instance=RequestContext(request))
示例#8
0
def tab_card(request, team_id):
    try:
        team_id = int(team_id)
    except ValueError:
        return render_to_response('error.html',
                                 {'error_type': "Tab Card",'error_name': "View",
                                  'error_info': "Team id must be an integer!"},
                                  context_instance=RequestContext(request))
    team = Team.objects.get(pk=team_id)
    rounds = ([r for r in Round.objects.filter(gov_team=team)] +
              [r for r in Round.objects.filter(opp_team=team)])
    rounds.sort(key =lambda x: x.round_number)
    roundstats = [RoundStats.objects.filter(round=r) for r in rounds]
    debaters = [d for d in team.debaters.all()]
    d1,d2 = debaters[0], debaters[1]
    round_stats = []
    num_rounds = TabSettings.objects.get(key="tot_rounds").value
    cur_round = TabSettings.objects.get(key="cur_round").value
    blank = " ";
    for i in range(num_rounds):
        round_stats.append([blank]*7)

    for r in rounds:
        dstat1 = [k for k in RoundStats.objects.filter(debater=d1).filter(round=r).all()]
        dstat2 = [k for k in RoundStats.objects.filter(debater=d2).filter(round=r).all()]
        blank_rs = RoundStats(debater=d1, round=r, speaks=0, ranks=0)
        while len(dstat1) + len(dstat2) < 2:
            # Something is wrong with our data, but we don't want to crash
            dstat1.append(blank_rs)
        if not dstat2 and not dstat1:
            break
        if not dstat2:
            dstat1,dstat2 = dstat1[0], dstat1[1]
        elif not dstat1:
            dstat1,dstat2 = dstat2[0], dstat2[1]
        else:
            dstat1,dstat2 = dstat1[0], dstat2[0]
        index = r.round_number - 1
        round_stats[index][3] = " - ".join([j.name for j in r.judges.all()])
        round_stats[index][4] = (float(dstat1.speaks), float(dstat1.ranks))
        round_stats[index][5] = (float(dstat2.speaks), float(dstat2.ranks))
        round_stats[index][6] = (float(dstat1.speaks + dstat2.speaks), float(dstat1.ranks + dstat2.ranks))

        if r.gov_team == team:
            round_stats[index][2] = r.opp_team
            round_stats[index][0] = "G"
            if r.victor == 1:
                round_stats[index][1] = "W"
            elif r.victor == 2 :
                round_stats[index][1] = "L"
            elif r.victor == 3:
                round_stats[index][1] = "WF"
            elif r.victor == 4 :
                round_stats[index][1] = "LF"
            elif r.victor == 5 :
                round_stats[index][1] = "AD"
            elif r.victor == 6:
                round_stats[index][1] = "AW"
        elif r.opp_team == team:
            round_stats[index][2] = r.gov_team
            round_stats[index][0] = "O"
            if r.victor == 1:
                round_stats[index][1] = "L"
            elif r.victor == 2 :
                round_stats[index][1] = "W"
            elif r.victor == 3:
                round_stats[index][1] = "LF"
            elif r.victor == 4 :
                round_stats[index][1] = "WF"
            elif r.victor == 5 :
                round_stats[index][1] = "AD"
            elif r.victor == 6:
                round_stats[index][1] = "AW"

    for i in range(cur_round-1):
        if round_stats[i][6] == blank:
            round_stats[i][6] = (0,0)
    for i in range(1,cur_round-1):
        round_stats[i][6] = (round_stats[i][6][0] + round_stats[i-1][6][0],
                             round_stats[i][6][1] + round_stats[i-1][6][1])

    totals = [[0,0],[0,0],[0,0]]
    for r in rounds:
        index = r.round_number-1
        if round_stats[index][4]==blank or round_stats[index][5]==blank:
            continue
        totals[0][0] += round_stats[index][4][0]
        totals[0][1] += round_stats[index][4][1]
        totals[1][0] += round_stats[index][5][0]
        totals[1][1] += round_stats[index][5][1]
        totals[2][0] += round_stats[index][4][0] + round_stats[index][5][0]
        totals[2][1] += round_stats[index][4][1] + round_stats[index][5][1]
    
    #Error out if we don't have a bye
    try:
        bye_round = Bye.objects.get(bye_team = team).round_number
    except:
        bye_round = None
        
    return render_to_response('tab_card.html', 
                             {'team_name': team.name,
                              'team_school': team.school,
                              'debater_1': d1.name,
                              'debater_1_status': Debater.NOVICE_CHOICES[d1.novice_status][1],
                              'debater_2': d2.name,
                              'debater_2_status': Debater.NOVICE_CHOICES[d2.novice_status][1],
                              'round_stats': round_stats,
                              'd1st': tot_speaks_deb(d1),
                              'd1rt': tot_ranks_deb(d1),
                              'd2st': tot_speaks_deb(d2),
                              'd2rt': tot_ranks_deb(d2),
                              'ts': tot_speaks(team),
                              'tr': tot_ranks(team),
                              'bye_round': bye_round},
                              context_instance=RequestContext(request))
示例#9
0
def tab_card(request, team_id):
    try:
        team_id = int(team_id)
    except ValueError:
        return redirect_and_flash_error(request, "Invalid team id")
    team = Team.objects.get(pk=team_id)
    rounds = ([r for r in Round.objects.filter(gov_team=team)] +
              [r for r in Round.objects.filter(opp_team=team)])
    rounds.sort(key=lambda x: x.round_number)
    debaters = [d for d in team.debaters.all()]
    iron_man = False
    if len(debaters) == 1:
        iron_man = True
    deb1 = debaters[0]
    if not iron_man:
        deb2 = debaters[1]
    round_stats = []
    num_rounds = TabSettings.objects.get(key="tot_rounds").value
    cur_round = TabSettings.objects.get(key="cur_round").value
    blank = " "
    for i in range(num_rounds):
        round_stats.append([blank] * 7)

    for round_obj in rounds:
        dstat1 = [
            k for k in RoundStats.objects.filter(debater=deb1).filter(
                round=round_obj).all()
        ]
        dstat2 = []
        if not iron_man:
            dstat2 = [
                k for k in RoundStats.objects.filter(debater=deb2).filter(
                    round=round_obj).all()
            ]
        blank_rs = RoundStats(debater=deb1, round=round_obj, speaks=0, ranks=0)
        while len(dstat1) + len(dstat2) < 2:
            # Something is wrong with our data, but we don't want to crash
            dstat1.append(blank_rs)
        if not dstat2 and not dstat1:
            break
        if not dstat2:
            dstat1, dstat2 = dstat1[0], dstat1[1]
        elif not dstat1:
            dstat1, dstat2 = dstat2[0], dstat2[1]
        else:
            dstat1, dstat2 = dstat1[0], dstat2[0]
        index = round_obj.round_number - 1
        round_stats[index][3] = " - ".join(
            [j.name for j in round_obj.judges.all()])
        round_stats[index][4] = (float(dstat1.speaks), float(dstat1.ranks))
        round_stats[index][5] = (float(dstat2.speaks), float(dstat2.ranks))
        round_stats[index][6] = (float(dstat1.speaks + dstat2.speaks),
                                 float(dstat1.ranks + dstat2.ranks))

        if round_obj.gov_team == team:
            round_stats[index][2] = round_obj.opp_team
            round_stats[index][0] = "G"
            if round_obj.victor == 1:
                round_stats[index][1] = "W"
            elif round_obj.victor == 2:
                round_stats[index][1] = "L"
            elif round_obj.victor == 3:
                round_stats[index][1] = "WF"
            elif round_obj.victor == 4:
                round_stats[index][1] = "LF"
            elif round_obj.victor == 5:
                round_stats[index][1] = "AD"
            elif round_obj.victor == 6:
                round_stats[index][1] = "AW"
        elif round_obj.opp_team == team:
            round_stats[index][2] = round_obj.gov_team
            round_stats[index][0] = "O"
            if round_obj.victor == 1:
                round_stats[index][1] = "L"
            elif round_obj.victor == 2:
                round_stats[index][1] = "W"
            elif round_obj.victor == 3:
                round_stats[index][1] = "LF"
            elif round_obj.victor == 4:
                round_stats[index][1] = "WF"
            elif round_obj.victor == 5:
                round_stats[index][1] = "AD"
            elif round_obj.victor == 6:
                round_stats[index][1] = "AW"

    for i in range(cur_round - 1):
        if round_stats[i][6] == blank:
            round_stats[i][6] = (0, 0)
    for i in range(1, cur_round - 1):
        round_stats[i][6] = (round_stats[i][6][0] + round_stats[i - 1][6][0],
                             round_stats[i][6][1] + round_stats[i - 1][6][1])
    #Error out if we don't have a bye
    try:
        bye_round = Bye.objects.get(bye_team=team).round_number
    except Exception:
        bye_round = None

    #Duplicates Debater 1 for display if Ironman team
    if iron_man:
        deb2 = deb1
    return render(
        request, "tab/tab_card.html", {
            "team_name": team.display_backend,
            "team_school": team.school,
            "debater_1": deb1.name,
            "debater_1_status": Debater.NOVICE_CHOICES[deb1.novice_status][1],
            "debater_2": deb2.name,
            "debater_2_status": Debater.NOVICE_CHOICES[deb2.novice_status][1],
            "round_stats": round_stats,
            "d1st": tot_speaks_deb(deb1),
            "d1rt": tot_ranks_deb(deb1),
            "d2st": tot_speaks_deb(deb2),
            "d2rt": tot_ranks_deb(deb2),
            "ts": tot_speaks(team),
            "tr": tot_ranks(team),
            "bye_round": bye_round
        })