Ejemplo n.º 1
0
    def _save_complete_ballotset(self, teams, testdata, post_ballotset_create=None):
        # unconfirm existing ballot
        try:
            existing = m.BallotSubmission.objects.get(debate=self.debate, confirmed=True)
        except m.BallotSubmission.DoesNotExist:
            pass
        else:
            existing.confirmed = False
            existing.save()

        ballotsub = m.BallotSubmission(debate=self.debate, submitter_type=m.BallotSubmission.SUBMITTER_TABROOM)
        ballotset = BallotSet(ballotsub)
        if post_ballotset_create:
            post_ballotset_create(ballotset)
        scores = testdata['scores']

        for team in teams:
            speakers = self._get_team(team).speaker_set.all()
            for pos, speaker in enumerate(speakers, start=1):
                ballotset.set_speaker(team, pos, speaker)
            ballotset.set_speaker(team, 4, speakers[0])

        for adj, sheet in zip(self.adjs, scores):
            for team, teamscores in zip(teams, sheet):
                for pos, score in enumerate(teamscores, start=1):
                    ballotset.set_score(adj, team, pos, score)

        ballotset.confirmed = True
        ballotset.save()

        return ballotset
Ejemplo n.º 2
0
def add_ballot_set(debate,
                   submitter_type,
                   user,
                   discarded=False,
                   confirmed=False,
                   min_score=72,
                   max_score=78):

    if discarded and confirmed:
        raise ValueError("Ballot can't be both discarded and confirmed!")

    # Create a new BallotSubmission
    bsub = m.BallotSubmission(submitter_type=submitter_type, debate=debate)
    if submitter_type == m.BallotSubmission.SUBMITTER_TABROOM:
        bsub.submitter = user
    bsub.save()

    def gen_results():
        r = {'aff': (0, ), 'neg': (0, )}

        def do():
            s = [
                random.randint(min_score, max_score) for i in range(
                    debate.round.tournament.LAST_SUBSTANTIVE_POSITION)
            ]
            s.append(random.randint(min_score, max_score) / 2.0)
            return s

        while sum(r['aff']) == sum(r['neg']):
            r['aff'] = do()
            r['neg'] = do()
        return r

    rr = dict()
    for adj in debate.adjudicators.list:
        rr[adj] = gen_results()

    # Create relevant scores
    bset = BallotSet(bsub)

    for side in ('aff', 'neg'):
        speakers = getattr(debate, '%s_team' % side).speakers
        for i in range(1,
                       debate.round.tournament.LAST_SUBSTANTIVE_POSITION + 1):
            bset.set_speaker(
                team=side,
                position=i,
                speaker=speakers[i - 1],
            )
        bset.set_speaker(team=side,
                         position=debate.round.tournament.REPLY_POSITION,
                         speaker=speakers[0])

        for adj in debate.adjudicators.list:
            for pos in debate.round.tournament.POSITIONS:
                bset.set_score(adj, side, pos, rr[adj][side][pos - 1])

    # Pick a motion
    motions = debate.round.motion_set.all()
    if motions:
        motion = random.choice(motions)
        bset.motion = motion

    bset.discarded = discarded
    bset.confirmed = confirmed

    bset.save()

    # If the ballot is confirmed, the debate should be too.
    if confirmed:
        debate.result_status = m.Debate.STATUS_CONFIRMED
        debate.save()

    return bset
Ejemplo n.º 3
0
def add_ballot_set(debate, submitter_type, user, discarded=False, confirmed=False, min_score=72, max_score=78):

    if discarded and confirmed:
        raise ValueError("Ballot can't be both discarded and confirmed!")

    # Create a new BallotSubmission
    bsub = m.BallotSubmission(submitter_type=submitter_type, debate=debate)
    if submitter_type == m.BallotSubmission.SUBMITTER_TABROOM:
        bsub.submitter = user
    bsub.save()

    def gen_results():
        r = {'aff': (0,), 'neg': (0,)}
        def do():
            s = [random.randint(min_score, max_score) for i in range(debate.round.tournament.LAST_SUBSTANTIVE_POSITION)]
            s.append(random.randint(min_score, max_score)/2.0)
            return s
        while sum(r['aff']) == sum(r['neg']):
            r['aff'] = do()
            r['neg'] = do()
        return r

    rr = dict()
    for adj in debate.adjudicators.list:
        rr[adj] = gen_results()

    # Create relevant scores
    bset = BallotSet(bsub)

    for side in ('aff', 'neg'):
        speakers = getattr(debate, '%s_team' % side).speakers
        for i in range(1, debate.round.tournament.LAST_SUBSTANTIVE_POSITION+1):
            bset.set_speaker(
                team = side,
                position = i,
                speaker = speakers[i - 1],
            )
        bset.set_speaker(
            team = side,
            position = debate.round.tournament.REPLY_POSITION,
            speaker = speakers[0]
        )

        for adj in debate.adjudicators.list:
            for pos in debate.round.tournament.POSITIONS:
                bset.set_score(adj, side, pos, rr[adj][side][pos-1])

    # Pick a motion
    motions = debate.round.motion_set.all()
    if motions:
        motion = random.choice(motions)
        bset.motion = motion

    bset.discarded = discarded
    bset.confirmed = confirmed

    bset.save()

    # If the ballot is confirmed, the debate should be too.
    if confirmed:
        debate.result_status = m.Debate.STATUS_CONFIRMED
        debate.save()

    return bset