Пример #1
0
 def setUp(self):
     self.maxDiff = None
     self.engine = DutchPairingEngine()
Пример #2
0
def create_pairing():
    #現在のラウンド数を取得する
    round_no = Round.objects.get().round_no
    if round_no is 1:
        #最初のラウンドは、Engineを作成する
        engine = DutchPairingEngine()
    else:
        #2ラウンド以降は、pickle化したエンジンを取得する
        engine = load_engine()

    #タプルに変換するためのリスト
    player_class_list = []
    #検索用
    player_class_dict = {}

    #playerクラスを作る
    players = CurrentRoundPlayerList.objects.order_by('pairing_no').all()
    for p in players:
        if round_no is 1:
            distinct_player = Player(name=p.name,
                                     rating=p.rating,
                                     pairing_no=p.pairing_no,
                                     score=p.score,
                                     float_status=p.float_status)
            player_class_list.append(distinct_player)
            player_class_dict[p.pairing_no] = p.name
        else:
            if (len(p.opponents) is not round_no - 1) or (len(p.colour_hist)
                                                          is not round_no - 1):
                raise SwissException("Round No. must be wrong.")

            distinct_player = Player(name=p.name,
                                     rating=p.rating,
                                     pairing_no=p.pairing_no,
                                     score=p.score,
                                     float_status=p.float_status,
                                     opponents=tuple(p.opponents),
                                     colour_hist=tuple(p.colour_hist))
            player_class_list.append(distinct_player)
            player_class_dict[p.pairing_no] = p.name

    player_class_tuple = tuple(player_class_list)

    current_pairing = engine.pair_round(round_no, player_class_tuple)

    #engineをダンプする
    dump_engine(engine)

    #現在のペアリングをDBに入れる
    for cp in current_pairing:
        if not len(CurrentRoundPlayerList.objects.filter(name=cp.name)) is 1:
            raise SwissException("CurrentRoundPlayerList must be wrong.")

        q = CurrentRoundPlayerList.objects.filter(name=cp.name).get()
        q.score = cp.score
        q.float_status = cp.float_status
        q.opponents = list(cp.opponents)
        q.colour_hist = list(cp.colour_hist)

        q.save()

        #Byeのプレーヤーは、PooledResultをこのタイミングで入れておく
        if cp.colour_hist[-1] is Colour.none:
            q = PooledResults(name=cp.name, result=1)
            q.save()
Пример #3
0
 def setUp(self):
     self.maxDiff = None
     self.engine = DutchPairingEngine(self.select_top_seed_colour)