def add_result(debate, submitter_type, user, discarded=False, confirmed=False, min_score=72, max_score=78, reply_random=False): """Adds a ballot set to a debate. ``debate`` is the Debate to which the ballot set should be added. ``submitter_type`` is a valid value of BallotSubmission.submitter_type. ``user`` is a User object. ``discarded`` and ``confirmed`` are whether the feedback should be discarded or confirmed, respectively. ``min_score`` and ``max_score`` are the range in which scores should be generated.""" if discarded and confirmed: raise ValueError("Ballot can't be both discarded and confirmed!") t = debate.round.tournament # Create a new BallotSubmission bsub = BallotSubmission(submitter_type=submitter_type, debate=debate) if submitter_type == BallotSubmission.SUBMITTER_TABROOM: bsub.submitter = user bsub.save() # Create relevant scores result = DebateResult(bsub) for side in t.sides: speakers = debate.get_team(side).speakers for i in range(1, t.last_substantive_position + 1): result.set_speaker(side, i, speakers[i - 1]) result.set_ghost(side, i, False) if t.reply_position is not None: reply_speaker = random.randint(0, t.last_substantive_position - 1) if reply_random else 0 result.set_speaker(side, t.reply_position, speakers[reply_speaker]) result.set_ghost(side, t.reply_position, False) if result.is_voting: for scoresheet in result.scoresheets.values(): fill_scoresheet_randomly(scoresheet, t) else: fill_scoresheet_randomly(result.scoresheet, t) result.save() # Pick a motion motions = debate.round.motion_set.all() if motions: motion = random.choice(motions) bsub.motion = motion bsub.discarded = discarded bsub.confirmed = confirmed bsub.save() # Update result status (only takes into account marginal effect, does not "fix") if confirmed: debate.result_status = Debate.STATUS_CONFIRMED elif not discarded and debate.result_status != Debate.STATUS_CONFIRMED: debate.result_status = Debate.STATUS_DRAFT debate.save() if t.pref('teams_in_debate') == 'two': logger.info( "%(debate)s won by %(team)s on %(motion)s", { 'debate': debate.matchup, 'team': result.winning_side(), 'motion': bsub.motion and bsub.motion.reference or "<No motion>" }) elif t.pref('teams_in_debate') == 'bp': logger.info( "%(debate)s: %(ranked)s on %(motion)s", { 'debate': debate.matchup, 'ranked': ", ".join(result.scoresheet.ranked_sides()), 'motion': bsub.motion and bsub.motion.reference or "<No motion>" }) return result
def add_result(debate, submitter_type, user, discarded=False, confirmed=False, reply_random=False): """Adds a ballot set to a debate. ``debate`` is the Debate to which the ballot set should be added. ``submitter_type`` is a valid value of BallotSubmission.submitter_type. ``user`` is a User object. ``discarded`` and ``confirmed`` are whether the feedback should be discarded or confirmed, respectively. ``min_score`` and ``max_score`` are the range in which scores should be generated.""" if discarded and confirmed: raise ValueError("Ballot can't be both discarded and confirmed!") t = debate.round.tournament if not debate.sides_confirmed: debate.sides_confirmed = True debate.save() # Create a new BallotSubmission bsub = BallotSubmission(submitter_type=submitter_type, debate=debate) if submitter_type == BallotSubmission.SUBMITTER_TABROOM: bsub.submitter = user bsub.save() # Create relevant scores result = DebateResult(bsub) if result.uses_speakers: for side in t.sides: speakers = list(debate.get_team(side).speakers) # fix order for i in range(1, t.last_substantive_position + 1): result.set_speaker(side, i, speakers[i - 1]) result.set_ghost(side, i, False) if t.reply_position is not None: reply_speaker = random.randint(0, t.last_substantive_position - 2) if reply_random else 0 result.set_speaker(side, t.reply_position, speakers[reply_speaker]) result.set_ghost(side, t.reply_position, False) if result.is_voting: for scoresheet in result.scoresheets.values(): fill_scoresheet_randomly(scoresheet, t) elif result.uses_advancing: result.set_advancing(random.sample(t.sides, 2)) else: fill_scoresheet_randomly(result.scoresheet, t) assert result.is_valid() result.save() # Pick a motion motions = debate.round.motion_set.all() if motions: num_motions = 3 if motions.count() > 3 else motions.count() sample = random.sample(list(motions), k=num_motions) motion = sample[0] bsub.motion = motion if t.pref('motion_vetoes_enabled') and len(sample) == len(t.sides) + 1: for i, side in enumerate(t.sides, 1): dt = debate.get_dt(side) dt.debateteammotionpreference_set.create( motion=sample[i], preference=3, ballot_submission=bsub, ) bsub.discarded = discarded bsub.confirmed = confirmed bsub.save() # Update result status (only takes into account marginal effect, does not "fix") if confirmed: debate.result_status = Debate.STATUS_CONFIRMED elif not discarded and debate.result_status != Debate.STATUS_CONFIRMED: debate.result_status = Debate.STATUS_DRAFT debate.save() if t.pref('teams_in_debate') == 'two': logger.info( "%(debate)s won by %(team)s on %(motion)s", { 'debate': debate.matchup, 'team': result.winning_side(), 'motion': bsub.motion and bsub.motion.reference or "<No motion>" }) elif t.pref('teams_in_debate') == 'bp': if result.uses_advancing: logger.info( "%(debate)s: %(advancing)s on %(motion)s", { 'debate': debate.matchup, 'advancing': ", ".join(result.advancing_sides()), 'motion': bsub.motion and bsub.motion.reference or "<No motion>" }) else: logger.info( "%(debate)s: %(ranked)s on %(motion)s", { 'debate': debate.matchup, 'ranked': ", ".join(result.scoresheet.ranked_sides()), 'motion': bsub.motion and bsub.motion.reference or "<No motion>" }) return result
def add_result(debate, submitter_type, user, discarded=False, confirmed=False, min_score=72, max_score=78, reply_random=False): """Adds a ballot set to a debate. ``debate`` is the Debate to which the ballot set should be added. ``submitter_type`` is a valid value of BallotSubmission.submitter_type. ``user`` is a User object. ``discarded`` and ``confirmed`` are whether the feedback should be discarded or confirmed, respectively. ``min_score`` and ``max_score`` are the range in which scores should be generated.""" if discarded and confirmed: raise ValueError("Ballot can't be both discarded and confirmed!") t = debate.round.tournament # Create a new BallotSubmission bsub = BallotSubmission(submitter_type=submitter_type, debate=debate) if submitter_type == BallotSubmission.SUBMITTER_TABROOM: bsub.submitter = user bsub.save() # Create relevant scores result = DebateResult(bsub) for side in t.sides: speakers = list(debate.get_team(side).speakers) # fix order for i in range(1, t.last_substantive_position+1): result.set_speaker(side, i, speakers[i-1]) result.set_ghost(side, i, False) if t.reply_position is not None: reply_speaker = random.randint(0, t.last_substantive_position-1) if reply_random else 0 result.set_speaker(side, t.reply_position, speakers[reply_speaker]) result.set_ghost(side, t.reply_position, False) if result.is_voting: for scoresheet in result.scoresheets.values(): fill_scoresheet_randomly(scoresheet, t) else: fill_scoresheet_randomly(result.scoresheet, t) assert result.is_valid() result.save() # Pick a motion motions = debate.round.motion_set.all() if motions: motion = random.choice(motions) bsub.motion = motion bsub.discarded = discarded bsub.confirmed = confirmed bsub.save() # Update result status (only takes into account marginal effect, does not "fix") if confirmed: debate.result_status = Debate.STATUS_CONFIRMED elif not discarded and debate.result_status != Debate.STATUS_CONFIRMED: debate.result_status = Debate.STATUS_DRAFT debate.save() if t.pref('teams_in_debate') == 'two': logger.info("%(debate)s won by %(team)s on %(motion)s", { 'debate': debate.matchup, 'team': result.winning_side(), 'motion': bsub.motion and bsub.motion.reference or "<No motion>" }) elif t.pref('teams_in_debate') == 'bp': logger.info("%(debate)s: %(ranked)s on %(motion)s", { 'debate': debate.matchup, 'ranked': ", ".join(result.scoresheet.ranked_sides()), 'motion': bsub.motion and bsub.motion.reference or "<No motion>" }) return result