Exemplo n.º 1
0
    def handle(self, *args, **options):
        cur_round = TabSettings.get("cur_round") - 1
        print(("Simulating round %s..." % cur_round))
        rounds_to_simulate = Round.objects.filter(round_number=cur_round,
                                                  victor=Round.NONE)

        for round_obj in rounds_to_simulate:
            self.__simulate_round(round_obj)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        cur_round = TabSettings.get("cur_round") - 1
        print(("Simulating round %s..." % cur_round))
        rounds_to_simulate = Round.objects.filter(round_number=cur_round, victor=Round.NONE)

        for r in rounds_to_simulate:
            print(r)
            self.__simulate_round(r)
Exemplo n.º 3
0
 def count_valid_teams(self):
     num_teams, num_valid_teams = 0, 0
     num_rounds = TabSettings.get('tot_rounds')
     for team in Team.objects.all():
         num_teams += 1
         num_forfeits = NoShow.objects.filter(no_show_team=team).count()
         if num_rounds - num_forfeits >= 3:
             num_valid_teams += 1
     return num_valid_teams, num_teams
Exemplo n.º 4
0
 def count_valid_teams(self):
     num_teams, num_valid_teams = 0, 0
     num_rounds = TabSettings.get('tot_rounds')
     for team in Team.objects.all():
         num_teams += 1
         num_forfeits = NoShow.objects.filter(no_show_team=team).count()
         if num_rounds - num_forfeits >= 3:
             num_valid_teams += 1
     return num_valid_teams, num_teams
Exemplo n.º 5
0
def ranks_for_debater(debater, average_ironmen=True):
    """Returns a list of ranks for the provided debater

    In most normal rounds the ranks of the debater are the ranks the judge
    gave them, but there are some special circumstances.

    Forfeits:
    If a debater won by forfeit, they get their average ranks
    If a debater lost by forfeit, they get ranks of 0
    If a debater was Noshow for a round, they get ranks of 0

    Iron Mans:
    If a debater is an iron man for a round, they get the average of their
    ranks for that round

    Byes:
    If a debater wins in a bye, they get their average ranks
    If a debater was late to a lenient round, they get average ranks
    """
    team = debater.team()
    # We start counting at 1, so when cur_round says 6 that means that we are
    # in round 5 and should have 5 ranks
    num_ranks = TabSettings.get("cur_round") - 1

    debater_roundstats = debater.roundstats_set.all()
    debater_ranks = []

    ranks_per_round = defaultdict(list)
    # We might have multiple roundstats per round if we have iron men, so first
    # group by round number
    for roundstat in debater_roundstats:
        ranks_per_round[roundstat.round.round_number].append(roundstat)

    for round_number in range(1, num_ranks + 1):
        roundstats = ranks_per_round[round_number]
        if roundstats:
            ranks = [float(rs.ranks) for rs in roundstats]
            avg_ranks = sum(ranks) / float(len(roundstats))
            roundstat = roundstats[0]
            if won_by_forfeit(roundstat.round, team):
                debater_ranks.append(avg_deb_ranks(debater))
            elif forfeited_round(roundstat.round, team):
                debater_ranks.append(MAXIMUM_DEBATER_RANKS)
            else:
                if average_ironmen:
                    debater_ranks.append(avg_ranks)
                else:
                    debater_ranks.extend(ranks)
        else:
            ranks = debater_abnormal_round_ranks(debater, round_number)
            if ranks is not None:
                debater_ranks.append(ranks)

    debater_ranks = list(map(float, debater_ranks))
    return debater_ranks
Exemplo n.º 6
0
def backup_round(dst_filename=None, round_number=None, btime=None):
    if round_number is None:
        round_number = TabSettings.get("cur_round", "no-round-number")

    if btime is None:
        btime = int(time.time())

    print("Trying to backup to backups directory")
    if dst_filename is None:
        dst_filename = "site_round_%i_%i" % (round_number, btime)

    dst_filename = _generate_unique_key(dst_filename)
    return LocalDump(dst_filename).backup()
Exemplo n.º 7
0
def backup_round(dst_filename=None, round_number=None, btime=None):
    if round_number is None:
        round_number = TabSettings.get("cur_round")

    if btime is None:
        btime = int(time.time())

    print("Trying to backup to backups directory")
    if dst_filename == None:
        dst_filename = "site_round_%i_%i" % (round_number, btime)

    if backup_exists(dst_filename):
        dst_filename += "_%i" % btime

    return copy_db(DATABASE_PATH, get_backup_filename(dst_filename))
Exemplo n.º 8
0
def backup_round(dst_filename = None, round_number = None, btime = None):
    if round_number is None:
        round_number = TabSettings.get("cur_round")

    if btime is None:
        btime = int(time.time())

    print("Trying to backup to backups directory")
    if dst_filename == None:
        dst_filename = "site_round_%i_%i" % (round_number, btime)

    if backup_exists(dst_filename):
        dst_filename += "_%i" % btime

    return copy_db(DATABASE_PATH, get_backup_filename(dst_filename))
Exemplo n.º 9
0
    def handle(self, *args, **options):
        cur_round = TabSettings.get("cur_round") - 1
        host = options["host"]

        csrf_threads = []
        rounds = Round.objects.filter(round_number=cur_round,
                                      victor=Round.NONE)
        for round_obj in rounds:
            judge = round_obj.chair
            csrf_threads.append(
                GetCsrfThread(host, judge.ballot_code, round_obj))

        num_errors = 0
        while csrf_threads:
            cur_csrf_threads = []
            for _ in range(min(len(csrf_threads), options["connections"])):
                cur_csrf_threads.append(csrf_threads.pop())

            for thr in cur_csrf_threads:
                thr.start()
            for thr in cur_csrf_threads:
                thr.join()

            result_threads = []
            for thr in cur_csrf_threads:
                num_errors += num_errors
                csrf_token, num_errors = thr.result
                if csrf_token is None:
                    print("no csrf token")

                result_thread = SubmitResultThread(thr.host, thr.ballot_code,
                                                   csrf_token, thr.round_obj)
                result_threads.append(result_thread)

            for thr in result_threads:
                thr.start()
            for thr in result_threads:
                thr.join()
            for thr in result_threads:
                num_errors += thr.num_errors
            print("Done with one batch! Sleeping!")
            time.sleep(2)

        print("Done!")
        print("Total errors: %s" % num_errors)
Exemplo n.º 10
0
def avg_deb_ranks(debater):
    """ Computes the average debater ranks for the supplied debater

    Generally this consistes of finding all the ranks we have, averaging iron
    men ranks, and then dividing by the length.

    This does not count forfeit losses or noshow's as 7 because having ranks of
    3.5 in the first place is penalty enough, and some tab polices may want
    forfeits to count as average ranks.
    """
    real_ranks = []
    num_ranks = TabSettings.get("cur_round") - 1
    debater_roundstats = debater.roundstats_set.all()
    team = debater.team()

    ranks_per_round = defaultdict(list)
    # We might have multiple roundstats per round if we have iron men, so first
    # group by round number
    for roundstat in debater_roundstats:
        ranks_per_round[roundstat.round.round_number].append(roundstat)

    for round_number in range(1, num_ranks + 1):
        roundstats = ranks_per_round[round_number]
        if roundstats:
            ranks = [float(rs.ranks) for rs in roundstats]
            avg_ranks = sum(ranks) / float(len(roundstats))
            roundstat = roundstats[0]
            if (won_by_forfeit(roundstat.round, team)
                    or forfeited_round(roundstat.round, team)):
                continue
            real_ranks.append(avg_ranks)

    if not real_ranks:
        return 0
    else:
        return float(sum(real_ranks)) / float(len(real_ranks))
Exemplo n.º 11
0
def speaks_for_debater(debater, average_ironmen=True):
    """Returns a list of speaks for the provided debater

    In most normal rounds the speaks of the debater are the speaks the judge
    gave them, but there are some special circumstances.

    Forfeits:
    If a debater won by forfeit, they get their average speaks
    If a debater lost by forfeit, they get speaks of 0
    If a debater was Noshow for a round, they get speaks of 0

    Iron Mans:
    If a debater is an iron man for a round, they get the average of their
    speaks for that round

    Byes:
    If a debater wins in a bye, they get their average speaks
    If a debater was late to a lenient round, they get average speaks
    """
    team = debater.team()
    # We start counting at 1, so when cur_round says 6 that means that we are
    # in round 5 and should have 5 speaks
    num_speaks = TabSettings.get("cur_round") - 1

    debater_roundstats = debater.roundstats_set.all()
    debater_speaks = []

    speaks_per_round = defaultdict(list)
    # We might have multiple roundstats per round if we have iron men, so first
    # group by round number
    for roundstat in debater_roundstats:
        speaks_per_round[roundstat.round.round_number].append(roundstat)

    for round_number in range(1, num_speaks + 1):
        roundstats = speaks_per_round[round_number]
        if roundstats:
            # This is so if in the odd chance we get a debater paired in
            # twice we take the speaks they actually got
            roundstats.sort(key=lambda rs: rs.speaks, reverse=True)
            roundstat = roundstats[0]
            if not len(set(rs.round for rs in roundstats)) == 1:
                roundstats = roundstats[:1]

            speaks = [float(rs.speaks) for rs in roundstats]
            avg_speaks = sum(speaks) / float(len(roundstats))
            if won_by_forfeit(roundstat.round, team):
                debater_speaks.append(avg_deb_speaks(debater))
            elif forfeited_round(roundstat.round, team):
                debater_speaks.append(MINIMUM_DEBATER_SPEAKS)
            else:
                if average_ironmen:
                    debater_speaks.append(avg_speaks)
                else:
                    debater_speaks.extend(speaks)
        else:
            speaks = debater_abnormal_round_speaks(debater, round_number)
            if speaks is not None:
                debater_speaks.append(speaks)

    debater_speaks = list(map(float, debater_speaks))
    return debater_speaks