def save_adjudicatorfeedback(self, **kwargs): """Saves the question fields and returns the AdjudicatorFeedback. To be called by save() of child classes.""" af = m.AdjudicatorFeedback(**kwargs) if self._confirm_on_submit: self.discard_all_existing( adjudicator=kwargs['adjudicator'], source_adjudicator=kwargs['source_adjudicator'], source_team=kwargs['source_team']) af.confirmed = True af.score = self.cleaned_data['score'] af.save() for question in self.tournament.adj_feedback_questions.filter( **self.question_filter): if self.cleaned_data[question.reference] is not None: answer = question.answer_type_class( feedback=af, question=question, answer=self.cleaned_data[question.reference]) answer.save() return af
def add_feedback(debate, submitter_type, user, probability=1.0, discarded=False, confirmed=False): if discarded and confirmed: raise ValueError("Feedback can't be both discarded and confirmed!") sources_and_subjects = [ (debate.aff_team, debate.adjudicators.chair), (debate.neg_team, debate.adjudicators.chair), ] sources_and_subjects.extend( itertools.permutations((adj for type, adj in debate.adjudicators), 2)) fbs = list() for source, adj in sources_and_subjects: if random.random() > probability: print " - Skipping", source, "on", adj continue fb = m.AdjudicatorFeedback(submitter_type=submitter_type) if submitter_type == m.AdjudicatorFeedback.SUBMITTER_TABROOM: fb.user = user fb.adjudicator = adj if isinstance(source, m.Adjudicator): fb.source_adjudicator = m.DebateAdjudicator.objects.get( debate=debate, adjudicator=source) elif isinstance(source, m.Team): fb.source_team = m.DebateTeam.objects.get(debate=debate, team=source) else: raise TypeError("source must be an Adjudicator or a Team") score = float(random.randrange(1, 6)) fb.score = score agree = random.choice([None, True, False]) fb.agree_with_decision = agree comments = random.choice(COMMENTS[score]) fb.comments = comments fb.discarded = discarded fb.confirmed = confirmed print source, "on", adj, ":", score fb.save() fbs.append(fb) return fbs
def save(self): # Saves the form and returns the m.AdjudicatorFeedback object da = self.cleaned_data['debate_adjudicator'] da = coerce(da) # Bug in Django 1.6.5 st = m.DebateTeam.objects.get(team=source, debate=da.debate) af = m.AdjudicatorFeedback(adjudicator=da.adjudicator, source_adjudicator=None, source_team=st, **submission_fields) af.score = self.cleaned_data['score'] af.agree_with_decision = self.cleaned_data['agree_with_decision'] af.comments = self.cleaned_data['comment'] af.save() return af
def save(self): # Saves the form and returns the AdjudicatorFeedback object source = self.cleaned_data['source'] source = coerce(source) # Bug in Django 1.6.5 if isinstance(source, m.DebateAdjudicator): sa = source else: sa = None if isinstance(source, m.DebateTeam): st = source else: st = None # Discard existing feedbacks for fb in m.AdjudicatorFeedback.objects.filter( adjudicator=adjudicator, source_adjudicator=sa, source_team=st): fb.discarded = True fb.save() # Save the new one af = m.AdjudicatorFeedback( adjudicator=adjudicator, source_adjudicator=sa, source_team=st, confirmed=True, # assume confirmed on every submission **submission_fields) af.score = self.cleaned_data['score'] af.agree_with_decision = self.cleaned_data['agree_with_decision'] af.comments = self.cleaned_data['comment'] af.save() return af
def add_feedback(debate, submitter_type, user, probability=1.0, discarded=False, confirmed=False): if discarded and confirmed: raise ValueError("Feedback can't be both discarded and confirmed!") sources_and_subjects = [ (debate.aff_team, debate.adjudicators.chair), (debate.neg_team, debate.adjudicators.chair), ] sources_and_subjects.extend( itertools.permutations((adj for type, adj in debate.adjudicators), 2)) fbs = list() for source, adj in sources_and_subjects: if random.random() > probability: print " - Skipping", source, "on", adj continue fb = m.AdjudicatorFeedback(submitter_type=submitter_type) if submitter_type == m.AdjudicatorFeedback.SUBMITTER_TABROOM: fb.submitter = user fb.adjudicator = adj if isinstance(source, m.Adjudicator): fb.source_adjudicator = m.DebateAdjudicator.objects.get( debate=debate, adjudicator=source) elif isinstance(source, m.Team): fb.source_team = m.DebateTeam.objects.get(debate=debate, team=source) else: raise TypeError("source must be an Adjudicator or a Team") score = float(random.randrange(1, 6)) fb.score = score fb.discarded = discarded fb.confirmed = confirmed fb.save() for question in debate.round.tournament.adj_feedback_questions: if question.answer_type_class == m.AdjudicatorFeedbackBooleanAnswer: answer = random.choice([None, True, False]) if answer is None: continue elif question.answer_type_class == m.AdjudicatorFeedbackIntegerAnswer: min_value = int(question.min_value) or 0 max_value = int(question.max_value) or 10 answer = random.randrange(min_value, max_value + 1) elif question.answer_type_class == m.AdjudicatorFeedbackFloatAnswer: min_value = question.min_value or 0 max_value = question.max_value or 10 answer = random.uniform(min_value, max_value) elif question.answer_type_class == m.AdjudicatorFeedbackStringAnswer: if question.answer_type == m.AdjudicatorFeedbackQuestion.ANSWER_TYPE_LONGTEXT: answer = random.choice(COMMENTS[score]) elif question.answer_type == m.AdjudicatorFeedbackQuestion.ANSWER_TYPE_SINGLE_SELECT: answer = random.choice(question.choices_for_field)[0] elif question.answer_type == m.AdjudicatorFeedbackQuestion.ANSWER_TYPE_MULTIPLE_SELECT: answers = random.sample( question.choices_for_field, random.randint(0, len(question.choices_for_field))) answer = m.AdjudicatorFeedbackQuestion.CHOICE_SEPARATOR.join( a[0] for a in answers) else: answer = random.choice(WORDS[score]) question.answer_type_class(question=question, feedback=fb, answer=answer).save() print source, "on", adj, ":", score fbs.append(fb) return fbs
def load_round(self, rounds): _type = { '1': m.Round.TYPE_RANDOM, '2': m.Round.TYPE_PRELIM, '8': m.Round.TYPE_PRELIM, '4': m.Round.TYPE_BREAK, } for line in self.load_table('rounds'): id, name, type, status, pr, fw, c, u = line.split('\t') if int(id) in rounds: r = m.Round( tournament=self.tournament, seq=id, name=name, type=_type[type], draw_status=m.Round.STATUS_CONFIRMED, venue_status=m.Round.STATUS_CONFIRMED, adjudicator_status=m.Round.STATUS_CONFIRMED, feedback_weight=float(fw), ) r.save() r.activate_all() self.rounds[int(id)] = r self.rounds[rounds[-1]].save() for line in self.load_table('debates'): id, round_id, venue_id, c, u = line.split('\t') if int(round_id) in rounds: d = m.Debate( round=self.rounds[int(round_id)], venue=self.venues[int(venue_id)], result_status=m.Debate.STATUS_CONFIRMED, ) d.save() self.debates[int(id)] = d _position = { '1': m.DebateTeam.POSITION_AFFIRMATIVE, '2': m.DebateTeam.POSITION_NEGATIVE, } for line in self.load_table('debates_teams_xrefs'): id, debate_id, team_id, pos, c, u = line.split('\t') if int(debate_id) in self.debates: d = m.DebateTeam( debate=self.debates[int(debate_id)], team=self.teams[int(team_id)], position=_position[pos], ) d.save() self.debate_teams[int(id)] = d _type = { '1': m.DebateAdjudicator.TYPE_CHAIR, '2': m.DebateAdjudicator.TYPE_PANEL, } for line in self.load_table('adjudicator_allocations'): id, debate_id, adj_id, type, c, u = line.split('\t') if int(debate_id) in self.debates: a = m.DebateAdjudicator( debate=self.debates[int(debate_id)], adjudicator=self.adjudicators[int(adj_id)], type=_type[type], ) a.save() self.adjudicator_allocations[int(id)] = a # read in speaker score sheets, then construct # actual scores later debates = {} P_AFF = m.DebateTeam.POSITION_AFFIRMATIVE P_NEG = m.DebateTeam.POSITION_NEGATIVE _side = { P_AFF: 'aff', P_NEG: 'neg', } for line in self.load_table('speaker_score_sheets'): id, aa_id, dt_id, s_id, score, pos, c, u = line.split('\t') if int(dt_id) in self.debate_teams: dt = self.debate_teams[int(dt_id)] d = dt.debate.id if d not in debates: debates[d] = {} a = self.adjudicator_allocations[int(aa_id)].adjudicator.id if a not in debates[d]: debates[d][a] = { P_AFF: {}, P_NEG: {}, } speaker = self.speakers[int(s_id)] score = float(score) debates[d][a][dt.position][int(pos)] = (speaker, score) for debate_id, adjudicators in debates.items(): dr = m.DebateResult(m.Debate.objects.get(pk=debate_id)) for side in (P_AFF, P_NEG): for pos in range(1, 5): first_adj = adjudicators.values()[0] speaker, _ = first_adj[side][pos] dr.set_speaker(_side[side], pos, speaker) for a_id in adjudicators: adj = m.Adjudicator.objects.get(pk=a_id) score = adjudicators[a_id][side][pos][1] dr.set_score(adj, _side[side], pos, score) dr.save() for debate in m.Debate.objects.all(): # set debate brackets if debate.round.prev is None: debate.bracket = 0 else: aff_team = m.Team.objects.standings( debate.round.prev).get(id=debate.aff_team.id) neg_team = m.Team.objects.standings( debate.round.prev).get(id=debate.neg_team.id) debate.bracket = max(aff_team.points, neg_team.points) debate.save() def _int(id): if id.strip() == r'\N': return None return int(id) for line in self.load_table('adjudicator_feedback_sheets'): id, adj_id, aa_id, dt_id, comm, score, c, u = line.split('\t') dt_id = _int(dt_id) aa_id = _int(aa_id) if (dt_id in self.debate_teams or aa_id in self.adjudicator_allocations): dt = self.debate_teams.get(dt_id) aa = self.adjudicator_allocations.get(aa_id) m.AdjudicatorFeedback( adjudicator=self.adjudicators[int(adj_id)], score=float(score), comments=comm.strip(), source_adjudicator=aa, source_team=dt, ).save() self.tournament.current_round = m.Round.objects.order_by('-seq')[0] self.tournament.save()