コード例 #1
0
def pre_populate_db():
    Week.objects.all().delete()
    Participant.objects.all().delete()
    PotentialMatchup.objects.all().delete()

    for i in range(1, 11):
        week = Week(week_number=i)
        week.save()

    for participant in PARTICIPANTS:
        if not participant.get('name'):
            participant['name'] = participant['full_name'].split(' ')[0]
        participant['url_slug'] = participant['full_name'].lower().replace(
            ' ', '-')
        participant_obj = Participant(**participant)
        participant_obj.save()

    all_participants = Participant.objects.all()
    potential_matchups = []
    for participant in all_participants:
        other_participants = Participant.objects.exclude(
            pk=participant.pk).all()
        for op in other_participants:
            form1 = [participant, op]
            form2 = [op, participant]
            if form1 not in potential_matchups and form2 not in potential_matchups:
                potential_matchup = PotentialMatchup(participant1=participant,
                                                     participant2=op)
                potential_matchup.save()
                potential_matchups.append([participant, op])
コード例 #2
0
    def test_truthbooth_match_eliminates_related_matches(self):
        """ Verify if Max and Paige are a Truth Booth perfect match, all of their
            other potential matches are marked eliminated via truthbooth and
            they are marked as perfect match via truthbooth
        """
        _max = Participant.objects.get(name='Max')
        _paige = Participant.objects.get(name='Paige')
        max_paige_matchup = PotentialMatchup.get(_max, _paige)
        week4_truthbooth = TruthBooth(
            week=self.test_week,
            matchup=max_paige_matchup,
            perfect_match=True
        )
        week4_truthbooth.save()

        max_matchups = _max.potential_matchups
        paige_found = False
        others_found = False
        for matchup in max_matchups:
            if matchup['match'] != _paige:
                others_found = True
                self.assertTrue(matchup['eliminated'])
                self.assertEqual(
                    matchup['elimination_type'],
                    'Eliminated Via Truthbooth'
                )
            else:
                paige_found = True
                self.assertFalse(matchup['eliminated'])
                self.assertEqual(
                    matchup['elimination_type'],
                    'Perfect Match: Truth Booth'
                )
        self.assertTrue(paige_found)
        self.assertTrue(others_found)
コード例 #3
0
ファイル: views.py プロジェクト: astromitts/are-you-the-one
    def post(self, request, *args, **kwargs):
        if not self.has_form_permission:
            messages.error(
                request,
                'Oops - you need to be logged in or running the app locally to post changes'
            )
            return redirect(self.location)
        if 'lock-match' in request.POST:
            participant1 = Participant.objects.get(
                pk=request.POST['participant1'])
            participant2 = Participant.objects.get(
                pk=request.POST['participant2'])
            if participant1 == participant2:
                messages.error(
                    request, 'Match Participants need to be different people')
            else:
                source_matchup = PotentialMatchup.get(
                    participant1=participant1, participant2=participant2)
                matchup = Matchup(week=self.week, matchup=source_matchup)
                matchup.save()
        elif 'lock-truthbooth' in request.POST:
            participant1 = Participant.objects.get(
                pk=request.POST['participant1'])
            participant2 = Participant.objects.get(
                pk=request.POST['participant2'])
            if participant1 == participant2:
                messages.error(
                    request, 'Match Participants need to be different people')
            else:
                perfect_match = request.POST.get('perfect_match') == 'Y'
                TruthBooth.lock(week=self.week,
                                participant1=participant1,
                                participant2=participant2,
                                perfect_match=perfect_match)
        elif 'lock-num-matches' in request.POST:
            self.week.matches_count = int(request.POST['num_matches'])
            self.week.locked = True
            self.week.save()

            if self.week.matches_count == 0:
                self.week.save_blackout()
            elif self.week.matches_count == self.week.matchup_set.count():
                self.week.save_final_matches()

        elif 'undo-match' in request.POST:
            match = Matchup.objects.get(pk=request.POST['undo_match_pk'])
            match.delete()
        elif 'undo-truthbooth' in request.POST:
            match = TruthBooth.objects.get(
                pk=request.POST['undo_truthbooth_pk'])
            match.delete()

        return redirect(self.location)
コード例 #4
0
    def test_blackout_elimination_logic(self):
        """ Verify that when a week has 0 matches, all participating matchups
            get marked as eliminated
        """
        black_out_matches = [
            ('Brandon', 'Kylie'),
            ('Aasha', 'Max'),
            ('Amber', 'Paige'),
            ('Danny', 'Remy'),
            ('Jasmine', 'Justin'),
            ('Jenna', 'Kai'),
            ('Nour', 'Kari'),
            ('Jonathan', 'Basit'),
        ]

        for black_out_match in black_out_matches:
            potential_matchup = PotentialMatchup.get(
                black_out_match[0], black_out_match[1])
            match = Matchup(
                week=self.test_week,
                matchup=potential_matchup
            )
            match.save()
        self.test_week.matches_count = 0
        self.test_week.locked = True
        self.test_week.save()

        for black_out_match in black_out_matches:
            potential_matchup = PotentialMatchup.get(
                black_out_match[0], black_out_match[1])
            self.assertTrue(potential_matchup.eliminated_via_blackout)

        self.test_week.matches_count = 1
        self.test_week.locked = True
        self.test_week.save()

        for black_out_match in black_out_matches:
            potential_matchup = PotentialMatchup.get(
                black_out_match[0], black_out_match[1])
            self.assertFalse(potential_matchup.eliminated_via_blackout)
コード例 #5
0
    def test_all_matches_logic(self):
        perfect_matches = [
            ('Brandon', 'Kylie'),
            ('Aasha', 'Max'),
            ('Amber', 'Paige'),
            ('Danny', 'Remy'),
            ('Jasmine', 'Justin'),
            ('Jenna', 'Kai'),
            ('Nour', 'Kari'),
            ('Jonathan', 'Basit'),
        ]

        for perfect_match in perfect_matches:
            potential_matchup = PotentialMatchup.get(
                perfect_match[0], perfect_match[1])
            match = Matchup(
                week=self.test_week,
                matchup=potential_matchup
            )
            match.save()

        self.test_week.matches_count = 8
        self.test_week.locked = True
        self.test_week.save()

        for perfect_match in perfect_matches:
            potential_matchup = PotentialMatchup.get(
                perfect_match[0], perfect_match[1])
            self.assertTrue(potential_matchup.perfect_match)

        self.test_week.matches_count = 3
        self.test_week.locked = True
        self.test_week.save()

        for perfect_match in perfect_matches:
            potential_matchup = PotentialMatchup.get(
                perfect_match[0], perfect_match[1])
            self.assertFalse(potential_matchup.perfect_match)
コード例 #6
0
def load_week_from_json(week, json_data):
    week.matches_count = json_data['matches_count']
    week.locked = json_data['locked']
    week.save()

    for match in json_data['matchups']:
        source_matchup = PotentialMatchup.get(match['participant1'],
                                              match['participant2'])
        matchup = Matchup(week=week, matchup=source_matchup)
        try:
            matchup.save()
        except IntegrityError:
            pass

    for match in json_data['truthbooths']:
        source_matchup = PotentialMatchup.get(match['participant1'],
                                              match['participant2'])
        matchup = TruthBooth(week=week,
                             matchup=source_matchup,
                             perfect_match=match['perfect_match'])
        try:
            matchup.save()
        except IntegrityError:
            matchup.update(perfect_match=perfect_match)
コード例 #7
0
ファイル: views.py プロジェクト: astromitts/are-you-the-one
    def setup(self, request, *args, **kwargs):
        super(PotentialMatchupDetail, self).setup(request, *args, **kwargs)
        self.participant1 = Participant.objects.get(
            url_slug=kwargs['participant1_slug'])
        self.participant2 = Participant.objects.get(
            url_slug=kwargs['participant2_slug'])

        self.potential_matchup = PotentialMatchup.get(self.participant1,
                                                      self.participant2)
        self.location = reverse('pm_detail',
                                kwargs={
                                    'participant1_slug':
                                    self.participant1.url_slug,
                                    'participant2_slug':
                                    self.participant2.url_slug
                                })
コード例 #8
0
    def test_truthbooth_related_eliminations(self):
        truthbooth_participant1 = 'Justin'
        truthbooth_participant2 = 'Kai'

        test_matchup = PotentialMatchup.get(
            truthbooth_participant1, truthbooth_participant2)

        TruthBooth.lock(
            week=self.test_week,
            participant1=truthbooth_participant1,
            participant2=truthbooth_participant2,
            perfect_match=True
        )

        self.assertFalse(test_matchup.perfect_match_via_truthbooth)

        other_matchup_verified = False  # guard against false positive
        for matchup in test_matchup.related_matchups:
            if matchup != test_matchup:
                self.assertTrue(matchup.eliminated_via_truthbooth)
                other_matchup_verified = True
        self.assertTrue(other_matchup_verified)

        truthbooth = TruthBooth.lock(
            week=self.test_week,
            participant1=truthbooth_participant1,
            participant2=truthbooth_participant2,
            perfect_match=False
        )

        self.assertFalse(test_matchup.perfect_match_via_truthbooth)

        other_matchup_verified = False  # guard against false positive
        for matchup in test_matchup.related_matchups:
            if matchup != test_matchup:
                self.assertFalse(matchup.eliminated_via_truthbooth)
                other_matchup_verified = True
        self.assertTrue(other_matchup_verified)