Example #1
0
    def save(self):
        # Unconfirm the other, if necessary
        if self.cleaned_data['confirmed']:
            if self.debate.confirmed_ballot != self.ballots and self.debate.confirmed_ballot is not None:
                self.debate.confirmed_ballot.confirmed = False
                self.debate.confirmed_ballot.save()

        bs = BallotSet(self.ballots)

        def do(side):
            for i in self.POSITIONS:
                speaker = self.cleaned_data['%s_speaker_%d' % (side, i)]
                bs.set_speaker(side, i, speaker)
                for adj in self.adjudicators:
                    score = self.cleaned_data[self.score_field_name(
                        adj, side, i)]
                    bs.set_score(adj, side, i, score)

        do('aff')
        do('neg')

        bs.motion = self.cleaned_data['motion']
        bs.aff_motion_veto = self.cleaned_data['aff_motion_veto']
        bs.neg_motion_veto = self.cleaned_data['neg_motion_veto']
        bs.discarded = self.cleaned_data['discarded']
        bs.confirmed = self.cleaned_data['confirmed']

        bs.save()

        self.debate.result_status = self.cleaned_data['debate_result_status']
        self.debate.save()
Example #2
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
Example #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
Example #4
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