Beispiel #1
0
 def bracket(round_obj):
     gov_wins, opp_wins = tab_logic.tot_wins(round_obj.gov_team), \
                          tab_logic.tot_wins(round_obj.opp_team)
     if abs(gov_wins - opp_wins) <= 1:
         return min(gov_wins, opp_wins)
     else:
         return max(gov_wins, opp_wins) - 1
Beispiel #2
0
 def bracket(round_obj):
     gov_wins, opp_wins = tab_logic.tot_wins(round_obj.gov_team), \
                          tab_logic.tot_wins(round_obj.opp_team)
     if abs(gov_wins - opp_wins) <= 1:
         return min(gov_wins, opp_wins)
     else:
         return max(gov_wins, opp_wins) - 1
Beispiel #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #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(("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 #12
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 #13
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
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(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 #15
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 #16
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 #17
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})