示例#1
0
def simulate_season(season):
    # Reset all season data
    print('Clearing season data')
    for r in season.round_set.order_by('-number'):
        r.publish_pairings = False
        r.is_completed = False
        r.save()
    LonePlayerPairing.objects.filter(round__season=season).delete()
    TeamPlayerPairing.objects.filter(team_pairing__round__season=season).delete()
    LonePlayerScore.objects.filter(season_player__season=season).delete()
    TeamScore.objects.filter(team__season=season).delete()
    latereg_players = {latereg.player_id for latereg in PlayerLateRegistration.objects.filter(round__season=season)}
    for sp in season.seasonplayer_set.all():
        if sp.player_id in latereg_players:
            sp.delete()
        else:
            sp.is_active = True
            sp.save()

    # Run each round
    for r in season.round_set.order_by('number'):
        print('Running round %d' % r.number)
        pairinggen.generate_pairings(r)
        r.publish_pairings = True
        r.save()
        simulate_round(r)
        r.is_completed = True
        r.save()
示例#2
0
def simulate_season(season):
    # Reset all season data
    print('Clearing season data')
    for r in season.round_set.order_by('-number'):
        r.publish_pairings = False
        r.is_completed = False
        r.save()
    LonePlayerPairing.objects.filter(round__season=season).delete()
    TeamPlayerPairing.objects.filter(team_pairing__round__season=season).delete()
    LonePlayerScore.objects.filter(season_player__season=season).delete()
    TeamScore.objects.filter(team__season=season).delete()
    latereg_players = {latereg.player_id for latereg in
                       PlayerLateRegistration.objects.filter(round__season=season)}
    for sp in season.seasonplayer_set.all():
        if sp.player_id in latereg_players:
            sp.delete()
        else:
            sp.is_active = True
            sp.save()

    # Run each round
    for r in season.round_set.order_by('number'):
        print('Running round %d' % r.number)
        pairinggen.generate_pairings(r)
        r.publish_pairings = True
        r.save()
        simulate_round(r)
        r.is_completed = True
        r.save()
示例#3
0
def generate_pairings(self, round_id, overwrite=False):
    round_ = Round.objects.get(pk=round_id)
    pairinggen.generate_pairings(round_, overwrite)
    round_.publish_pairings = False
    with reversion.create_revision():
        reversion.set_comment('Generated pairings.')
        round_.save()
    signals.pairings_generated.send(sender=generate_pairings, round_=round_)
示例#4
0
    def run(self, complete_round=False, complete_season=False, update_board_order=False,
            generate_pairings=False, background=False, user=None):
        msg_list = []
        round_to_close = self.round_to_close
        round_to_open = self.round_to_open
        season_to_close = self.season_to_close

        with transaction.atomic():
            if complete_round and round_to_close is not None:
                with reversion.create_revision():
                    reversion.set_user(user)
                    reversion.set_comment('Closed round.')
                    round_to_close.is_completed = True
                    round_to_close.save()
                msg_list.append(
                    ('Round %d set as completed.' % round_to_close.number, messages.INFO))
            if complete_season and season_to_close is not None and (
                round_to_close is None or round_to_close.is_completed):
                with reversion.create_revision():
                    reversion.set_user(user)
                    reversion.set_comment('Closed season.')
                    season_to_close.is_completed = True
                    season_to_close.save()
                msg_list.append(('%s set as completed.' % season_to_close.name, messages.INFO))
            if update_board_order and round_to_open is not None and self.season.league.competitor_type == 'team':
                try:
                    UpdateBoardOrderWorkflow(self.season).run(alternates_only=False)
                    msg_list.append(('Board order updated.', messages.INFO))
                except IndexError:
                    msg_list.append(('Error updating board order.', messages.ERROR))
                    return msg_list
            if generate_pairings and round_to_open is not None:
                if background:
                    signals.do_generate_pairings.send(sender=self.__class__,
                                                      round_id=round_to_open.pk)
                    msg_list.append(('Generating pairings in background.', messages.INFO))
                else:
                    try:
                        pairinggen.generate_pairings(round_to_open, overwrite=False)
                        with reversion.create_revision():
                            reversion.set_user(user)
                            reversion.set_comment('Generated pairings.')
                            round_to_open.publish_pairings = False
                            round_to_open.save()
                        msg_list.append(('Pairings generated.', messages.INFO))
                    except pairinggen.PairingsExistException:
                        msg_list.append(('Unpublished pairings already exist.', messages.WARNING))
                    except pairinggen.PairingHasResultException:
                        msg_list.append(
                            ('Pairings with results can\'t be overwritten.', messages.ERROR))
                    except pairinggen.PairingGenerationException as e:
                        msg_list.append(
                            ('Error generating pairings. %s' % e.message, messages.ERROR))
        return msg_list
示例#5
0
    def run(self, complete_round=False, complete_season=False, update_board_order=False, generate_pairings=False, background=False, user=None):
        msg_list = []
        round_to_close = self.round_to_close
        round_to_open = self.round_to_open
        season_to_close = self.season_to_close

        with transaction.atomic():
            if complete_round and round_to_close is not None:
                with reversion.create_revision():
                    reversion.set_user(user)
                    reversion.set_comment('Closed round.')
                    round_to_close.is_completed = True
                    round_to_close.save()
                msg_list.append(('Round %d set as completed.' % round_to_close.number, messages.INFO))
            if complete_season and season_to_close is not None and (round_to_close is None or round_to_close.is_completed):
                with reversion.create_revision():
                    reversion.set_user(user)
                    reversion.set_comment('Closed season.')
                    season_to_close.is_completed = True
                    season_to_close.save()
                msg_list.append(('%s set as completed.' % season_to_close.name, messages.INFO))
            if update_board_order and round_to_open is not None and self.season.league.competitor_type == 'team':
                try:
                    UpdateBoardOrderWorkflow(self.season).run(alternates_only=False)
                    msg_list.append(('Board order updated.', messages.INFO))
                except IndexError:
                    msg_list.append(('Error updating board order.', messages.ERROR))
                    return msg_list
            if generate_pairings and round_to_open is not None:
                if background:
                    signals.do_generate_pairings.send(sender=self.__class__, round_id=round_to_open.pk)
                    msg_list.append(('Generating pairings in background.', messages.INFO))
                else:
                    try:
                        pairinggen.generate_pairings(round_to_open, overwrite=False)
                        with reversion.create_revision():
                            reversion.set_user(user)
                            reversion.set_comment('Generated pairings.')
                            round_to_open.publish_pairings = False
                            round_to_open.save()
                        msg_list.append(('Pairings generated.', messages.INFO))
                    except pairinggen.PairingsExistException:
                        msg_list.append(('Unpublished pairings already exist.', messages.WARNING))
                    except pairinggen.PairingHasResultException:
                        msg_list.append(('Pairings with results can\'t be overwritten.', messages.ERROR))
                    except pairinggen.PairingGenerationException as e:
                        msg_list.append(('Error generating pairings. %s' % e.message, messages.ERROR))
        return msg_list