示例#1
0
def rank_break(request):
    print "starting break: ", datetime.now()
    varsity_break = tab_logic.rank_teams_for_break()
    teams = [
        (team, tab_logic.tot_wins(team), tab_logic.ranks_minus_opp_wins(team),
         tab_logic.tot_speaks(team), tab_logic.tot_ranks(team),
         tab_logic.opp_strength_no_round1(team)) for team in varsity_break
    ]
    print "Got ranked varsity teams"

    print "starting novice break: ", datetime.now()
    novice_break = tab_logic.rank_nov_teams_for_break()
    nov_teams = [(team, tab_logic.tot_wins(team),
                  tab_logic.ranks_minus_opp_wins(team),
                  tab_logic.tot_speaks(team), tab_logic.tot_ranks(team),
                  tab_logic.opp_strength_no_round1(team))
                 for team in novice_break]
    print "Got ranked novice teams"

    return render_to_response('rank_break.html', {
        'varsity': teams,
        'novice': nov_teams,
        'title': "The Break"
    },
                              context_instance=RequestContext(request))
示例#2
0
 def make_team_row(self, team):
     return (team.name, team.school.name,
             team.hybrid_school.name if team.hybrid_school else "",
             team.debaters.first().name if team.debaters.count() else "",
             team.debaters.last().name if team.debaters.count() > 1 else "",
             tab_logic.tot_wins(team), tab_logic.tot_speaks(team),
             tab_logic.tot_ranks(team))
示例#3
0
def rank_teams(request):
    print "starting rankings: ", datetime.now()
    ranked_teams = tab_logic.rank_teams()
    print "Got ranked teams"
    teams = [(team, tab_logic.tot_wins(team), tab_logic.tot_speaks(team),
              tab_logic.tot_ranks(team)) for team in ranked_teams]

    print "started novice rankings: ", datetime.now()
    ranked_novice_teams = tab_logic.rank_nov_teams()
    nov_teams = [(team, tab_logic.tot_wins(team), tab_logic.tot_speaks(team),
                  tab_logic.tot_ranks(team)) for team in ranked_novice_teams]

    print "Got ranked novice teams"
    return render_to_response('rank_teams_component.html', {
        'varsity': teams,
        'novice': nov_teams,
        'title': "Team Rankings"
    },
                              context_instance=RequestContext(request))
示例#4
0
 def make_team_row(self, team):
     return (
         team.name,
         team.school.name,
         team.hybrid_school.name if team.hybrid_school else "",
         team.debaters.first().name if team.debaters.count() else "",
         team.debaters.last().name if team.debaters.count() > 1 else "",
         tab_logic.tot_wins(team),
         tab_logic.tot_speaks(team),
         tab_logic.tot_ranks(team)
     )
示例#5
0
def rank_teams(request):
    print "starting rankings: ", datetime.now()
    ranked_teams = tab_logic.rank_teams()
    print "Got ranked teams"
    teams = [(team,
              tab_logic.tot_wins(team),
              tab_logic.tot_speaks(team),
              tab_logic.tot_ranks(team))
              for team in ranked_teams]

    print "started novice rankings: ", datetime.now()
    ranked_novice_teams = tab_logic.rank_nov_teams()
    nov_teams = [(team,
                  tab_logic.tot_wins(team),
                  tab_logic.tot_speaks(team),
                  tab_logic.tot_ranks(team))
                  for team in ranked_novice_teams]

    print "Got ranked novice teams"
    return render_to_response('rank_teams_component.html',
                             {'varsity': teams,
                              'novice': nov_teams,
                              'title': "Team Rankings"},
                              context_instance=RequestContext(request))
示例#6
0
def export_team_stats(request):
    """Exports data as XLS for each team: win-loss record, total speaker points, total ranks, single-adjusted
    speaker points, single-adjusted ranks, double-adjusted speaker points, double-adjusted ranks, and opposition
    strength."""
    book = Workbook('utf-8')
    sheet = book.add_sheet('Team stats')

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

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

    teams = Team.objects.all()
    for i in xrange(len(teams)):
        team, row = teams[i], i + 2
        sheet.write(row, 0, team.name)
        sheet.write(row, 1, tab_logic.tot_wins(team))
        sheet.write(row, 2, tab_logic.tot_speaks(team))
        sheet.write(row, 3, tab_logic.tot_ranks(team))
        sheet.write(row, 4, tab_logic.single_adjusted_speaks(team))
        sheet.write(row, 5, tab_logic.single_adjusted_ranks(team))
        sheet.write(row, 6, tab_logic.double_adjusted_speaks(team))
        sheet.write(row, 7, tab_logic.double_adjusted_ranks(team))
        sheet.write(row, 8, tab_logic.opp_strength(team))

    # construct response
    response = HttpResponse(content_type='application/vnd.ms-excel')
    response[
        'Content-Disposition'] = 'attachment; filename=mittab-team-stats.xls'
    book.save(response)
    return response
示例#7
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})
示例#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()]
    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))
示例#9
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))
示例#10
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
        })