Beispiel #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))
Beispiel #2
0
def view_round(request, round_number, errors = None):
    if errors is None:
        errors = []
    valid_pairing, byes = True, []
    print "1: ",time.time()
    round_pairing = list(Round.objects.filter(round_number = round_number))

    random.seed(1337)
    random.shuffle(round_pairing)
    round_pairing.sort(key = lambda x: tab_logic.team_comp(x, round_number),
                       reverse = True)

    print "2: ",time.time()
    #For the template since we can't pass in something nicer like a hash
    round_info = [[pair]+[None]*8 for pair in round_pairing]
    for pair in round_info:
        pair[1] = tab_logic.tot_wins(pair[0].gov_team)
        pair[2] = tab_logic.tot_speaks(pair[0].gov_team)
        pair[3] = tab_logic.num_govs(pair[0].gov_team)    
        pair[4] = tab_logic.num_opps(pair[0].gov_team)    
        pair[5] = tab_logic.tot_wins(pair[0].opp_team)
        pair[6] = tab_logic.tot_speaks(pair[0].opp_team)
        pair[7] = tab_logic.num_govs(pair[0].opp_team)    
        pair[8] = tab_logic.num_opps(pair[0].opp_team)
    print "3: ",time.time()

    paired_teams = [team.gov_team for team in round_pairing] + [team.opp_team for team in round_pairing]
    n_over_two = Team.objects.filter(checked_in=True).count() / 2
    valid_pairing = len(round_pairing) >= n_over_two
    for present_team in Team.objects.filter(checked_in=True):
        if not (present_team in paired_teams):
            errors.append("%s was not in the pairing" % (present_team))
            byes.append(present_team) 
    pairing_exists = len(round_pairing) > 0 
    excluded_judges = Judge.objects.exclude(judges__round_number = round_number).filter(checkin__round_number = round_number)
    non_checkins = Judge.objects.exclude(judges__round_number = round_number).exclude(checkin__round_number = round_number)
    size = max(map(len, [excluded_judges, non_checkins, byes]))
    # The minimum rank you want to warn on
    warning = 5
    judge_slots = [1,2,3]
    print "4: ",time.time()

    # A seemingly complex one liner to do a fairly simple thing
    # basically this generates the table that the HTML will display such that the output looks like:
    # [ Byes ][Judges not in round but checked in][Judges not in round but not checked in]
    # [ Team1][             CJudge1              ][                 Judge1               ]
    # [ Team2][             CJudge2              ][                 Judge2               ]
    # [      ][             CJudge3              ][                 Judge3               ]
    # [      ][                                  ][                 Judge4               ]
    excluded_people = zip(*map( lambda x: x+[""]*(size-len(x)), [list(byes), list(excluded_judges), list(non_checkins)])) 

    return render_to_response('display_info.html',
                               locals(),
                               context_instance=RequestContext(request))
Beispiel #3
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))
Beispiel #4
0
def view_team(request, team_id):
    team_id = int(team_id)
    try:
        team = Team.objects.get(pk=team_id)
        stats = []
        stats.append(("Wins", tab_logic.tot_wins(team)))
        stats.append(("Total Speaks", tab_logic.tot_speaks(team)))
        stats.append(("Govs", tab_logic.num_govs(team)))
        stats.append(("Opps", tab_logic.num_opps(team)))
        stats.append(("Opp Wins", tab_logic.opp_strength(team)))
        stats.append(("Been Pullup", tab_logic.pull_up_count(team)))
        stats.append(("Hit Pullup", tab_logic.hit_pull_up_count(team)))
    except Team.DoesNotExist:
        return render_to_response('error.html', {
            'error_type': "View Team",
            'error_name': str(team_id),
            'error_info': "No such Team"
        },
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = TeamForm(request.POST, instance=team)
        if form.is_valid():
            try:
                form.save()
            except ValueError:
                return render_to_response('error.html', {
                    'error_type':
                    "Team",
                    'error_name':
                    "[" + form.cleaned_data['name'] + "]",
                    'error_info':
                    "Team name cannot be validated, most likely a non-existent team"
                },
                                          context_instance=RequestContext(
                                              request))
            return render_to_response(
                'thanks.html', {
                    'data_type': "Team",
                    'data_name': "[" + form.cleaned_data['name'] + "]"
                },
                context_instance=RequestContext(request))
    else:
        form = TeamForm(instance=team)
        links = [('/team/' + str(team_id) + '/scratches/view/',
                  'Scratches for ' + str(team.name), False),
                 ('/team/' + str(team_id) + '/delete/', 'Delete', True)]
        for deb in team.debaters.all():
            links.append(
                ('/debater/' + str(deb.id) + '/', "View %s" % deb.name, False))
        return render_to_response('data_entry.html', {
            'title': "Viewing Team: %s" % (team.name),
            'form': form,
            'links': links,
            'team_obj': team,
            'team_stats': stats
        },
                                  context_instance=RequestContext(request))

    return render_to_response('data_entry.html', {'form': form},
                              context_instance=RequestContext(request))
Beispiel #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))
Beispiel #6
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)
     )
Beispiel #7
0
def team_stats(request, team_id):
    team_id = int(team_id)
    try:
        team = Team.objects.get(pk=team_id)
        stats = {}
        stats["seed"] = Team.get_seed_display(team).split(" ")[0]
        stats["wins"] = tab_logic.tot_wins(team)
        stats["total_speaks"] = tab_logic.tot_speaks(team)
        stats["govs"] = tab_logic.num_govs(team)
        stats["opps"] = tab_logic.num_opps(team)
        data = {'success': True, 'result':stats}
    except Team.DoesNotExist:
        data = {'success': False}
    return JsonResponse(data)
Beispiel #8
0
def team_stats(request, team_id):
    team_id = int(team_id)
    try:
        team = Team.objects.get(pk=team_id)
        stats = {}
        stats["seed"] = Team.get_seed_display(team).split(" ")[0]
        stats["wins"] = tab_logic.tot_wins(team)
        stats["total_speaks"] = tab_logic.tot_speaks(team)
        stats["govs"] = tab_logic.num_govs(team)
        stats["opps"] = tab_logic.num_opps(team)
        data = {'success': True, 'result': stats}
    except Team.DoesNotExist:
        data = {'success': False}
    return JsonResponse(data)
Beispiel #9
0
def view_team(request, team_id):
    team_id = int(team_id)
    try:
        team = Team.objects.get(pk=team_id)
        stats = []
        stats.append(("Wins", tab_logic.tot_wins(team)))
        stats.append(("Total Speaks", tab_logic.tot_speaks(team)))
        stats.append(("Govs", tab_logic.num_govs(team)))
        stats.append(("Opps", tab_logic.num_opps(team)))
        stats.append(("Opp Wins", tab_logic.opp_strength(team)))
        stats.append(("Been Pullup", tab_logic.pull_up_count(team)))
        stats.append(("Hit Pullup", tab_logic.hit_pull_up_count(team)))
    except Team.DoesNotExist:
        return render_to_response('error.html', 
                                 {'error_type': "View Team",
                                  'error_name': str(team_id),
                                  'error_info':"No such Team"}, 
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = TeamForm(request.POST,instance=team)
        if form.is_valid():
            try:
               form.save()
            except ValueError:
                return render_to_response('error.html', 
                                         {'error_type': "Team",
                                          'error_name': "["+form.cleaned_data['name']+"]",
                                          'error_info':"Team name cannot be validated, most likely a non-existent team"}, 
                                          context_instance=RequestContext(request))
            return render_to_response('thanks.html', 
                                     {'data_type': "Team",
                                      'data_name': "["+form.cleaned_data['name']+"]"}, 
                                      context_instance=RequestContext(request))
    else:
        form = TeamForm(instance=team)
        links = [('/team/'+str(team_id)+'/scratches/view/','Scratches for '+str(team.name), False),
                 ('/team/'+str(team_id)+'/delete/', 'Delete', True)]
        for deb in team.debaters.all():
            links.append(('/debater/'+str(deb.id)+'/', "View %s" % deb.name, False))
        return render_to_response('data_entry.html', 
                                 {'title':"Viewing Team: %s"%(team.name),
                                  'form': form,
                                  'links': links,
                                  'team_obj':team,
                                  'team_stats':stats}, 
                                  context_instance=RequestContext(request))
    
    return render_to_response('data_entry.html', 
                             {'form': form}, 
                             context_instance=RequestContext(request))
Beispiel #10
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))
Beispiel #11
0
def view_team(request, team_id):
    team_id = int(team_id)
    try:
        team = Team.objects.get(pk=team_id)
        stats = []
        stats.append(("Wins", tab_logic.tot_wins(team)))
        stats.append(("Total Speaks", tab_logic.tot_speaks(team)))
        stats.append(("Govs", tab_logic.num_govs(team)))
        stats.append(("Opps", tab_logic.num_opps(team)))
        stats.append(("Avg. Opp Wins", tab_logic.opp_strength(team)))
        stats.append(("Been Pullup", tab_logic.pull_up_count(team)))
        stats.append(("Hit Pullup", tab_logic.hit_pull_up(team)))
    except Team.DoesNotExist:
        return redirect_and_flash_error(request, "Team not found")
    if request.method == "POST":
        form = TeamForm(request.POST, instance=team)
        if form.is_valid():
            try:
                form.save()
            except ValueError:
                return redirect_and_flash_error(
                    request,
                    "An error occured, most likely a non-existent team")
            return redirect_and_flash_success(
                request, "Team {} updated successfully".format(
                    form.cleaned_data["name"]))
    else:
        form = TeamForm(instance=team)
        links = [("/team/" + str(team_id) + "/scratches/view/",
                  "Scratches for {}".format(team.display_backend))]
        for deb in team.debaters.all():
            links.append(
                ("/debater/" + str(deb.id) + "/", "View %s" % deb.name))
        return render(
            request, "common/data_entry.html", {
                "title": "Viewing Team: %s" % (team.display_backend),
                "form": form,
                "links": links,
                "team_obj": team,
                "team_stats": stats
            })

    return render(request, "common/data_entry.html", {"form": form})
Beispiel #12
0
def team_stats(request, team_id):
    team_id = int(team_id)
    try:
        team = Team.objects.get(pk=team_id)
        stats = {}
        stats["seed"] = Team.get_seed_display(team).split(" ")[0]
        stats["wins"] = tab_logic.tot_wins(team)
        stats["total_speaks"] = tab_logic.tot_speaks(team)
        stats["govs"] = tab_logic.num_govs(team)
        stats["opps"] = tab_logic.num_opps(team)

        if hasattr(team, "breaking_team"):
            stats["outround_seed"] = team.breaking_team.seed
            stats[
                "effective_outround_seed"] = team.breaking_team.effective_seed

        data = {"success": True, "result": stats}
    except Team.DoesNotExist:
        data = {"success": False}
    return JsonResponse(data)
Beispiel #13
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
Beispiel #14
0
def view_team(request, team_id):
    team_id = int(team_id)
    try:
        team = Team.objects.get(pk=team_id)
        stats = []
        stats.append(("Wins", tab_logic.tot_wins(team)))
        stats.append(("Total Speaks", tab_logic.tot_speaks(team)))
        stats.append(("Govs", tab_logic.num_govs(team)))
        stats.append(("Opps", tab_logic.num_opps(team)))
        stats.append(("Avg. Opp Wins", tab_logic.opp_strength(team)))
        stats.append(("Been Pullup", tab_logic.pull_up_count(team)))
        stats.append(("Hit Pullup", tab_logic.hit_pull_up_count(team)))
    except Team.DoesNotExist:
        return redirect_and_flash_error(request, "Team not found")
    if request.method == 'POST':
        form = TeamForm(request.POST,instance=team)
        if form.is_valid():
            try:
               form.save()
            except ValueError:
                return redirect_and_flash_error(request,
                        "An error occured, most likely a non-existent team")
            return redirect_and_flash_success(request,
                    "Team {} updated successfully".format(form.cleaned_data["name"]))
    else:
        form = TeamForm(instance=team)
        links = [('/team/'+str(team_id)+'/scratches/view/','Scratches for {}'.format(team.name))]
        for deb in team.debaters.all():
            links.append(('/debater/'+str(deb.id)+'/', "View %s" % deb.name))
        return render(request, 'common/data_entry.html', 
                                 {'title':"Viewing Team: %s"%(team.name),
                                  'form': form,
                                  'links': links,
                                  'team_obj':team,
                                  'team_stats':stats})

    return render(request, 'common/data_entry.html', {'form': form})
Beispiel #15
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})
Beispiel #16
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))
Beispiel #17
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))
Beispiel #18
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
        })