Exemple #1
0
 def check(self):
     playerrequest = PlayerRequest.getByKey(self.__player.id)
     # プレイ情報.
     playdata = GachaPlayData.getByKey(GachaPlayData.makeID(self.__player.id, self.__gachamaster.boxid))
     playcount = GachaPlayCount.getByKey(GachaPlayCount.makeID(self.__player.id, self.__gachamaster.id))
     
     if playerrequest.req_confirmkey == self.__player.req_confirmkey or playerrequest.req_alreadykey != self.__player.req_confirmkey:
         raise AppTestError(u'ガチャプレイ情報の確認キーが更新されていない')
     elif playcount.getTodayPlayCnt() < 1:
         raise AppTestError(u'ガチャプレイ回数が増えていない.%d, %d, %s' % (playcount.getTodayPlayCnt(), playcount.cnt, playcount.ptime))
     
     # BOX確認.
     box = GachaBox(self.__gachamaster, playdata)
     if box.get_rest_num() != 1:
         raise AppTestError(u'BOXのカードがうまく消費されていない.%d' % box.get_rest_num())
     
     # カードが増えているか.
     cardnum = BackendApi.get_cardnum(self.__player.id)
     if cardnum != self.__gachamaster.continuity:
         raise AppTestError(u'カード枚数がおかしい %d vs %d' % (cardnum, self.__gachamaster.continuity))
     elif cardnum != len(playdata.result['result']):
         raise AppTestError(u'ガチャの結果の長さがおかしい %d vs %d' % (cardnum, len(playdata.result['result'])))
     
     # おまけが来ているか.
     present_num = BackendApi.get_present_num(self.__player.id)
     if present_num < 1:
         raise AppTestError(u'おまけが来ていない')
     
     # チケット消費確認.
     playergachapt = PlayerGachaPt.getByKey(self.__player.id)
     if 0 < playergachapt.tryluckticket:
         raise AppTestError(u'チケットを消費していない')
Exemple #2
0
 def tr_write_playdata(uid, midlist):
     """プレイ情報がないので用意.
     """
     playdatas = {}
     model_mgr = ModelRequestMgr()
     for mid in midlist:
         ins = GachaPlayData.makeInstance(GachaPlayData.makeID(uid, mid))
         model_mgr.set_save(ins)
         playdatas[mid] = ins
     model_mgr.write_all()
     return model_mgr, playdatas
Exemple #3
0
    def check(self):
        model_mgr = ModelRequestMgr()
        # 課金情報.
        entry = BackendApi.get_gachapaymententry(model_mgr,
                                                 self.__payment_entry.id)
        if entry is None:
            raise AppTestError(u'課金レコードが作成されていない')
        elif entry.state != PaymentData.Status.COMPLETED:
            raise AppTestError(u'課金ステータスが異常です.status=%s' % entry.state)

        playerrequest = PlayerRequest.getByKey(self.__player.id)
        # プレイ情報.
        playdata = GachaPlayData.getByKey(
            GachaPlayData.makeID(self.__player.id, self.__gachamaster.boxid))
        playcount = GachaPlayCount.getByKey(
            GachaPlayCount.makeID(self.__player.id, self.__gachamaster.id))

        if playerrequest.req_confirmkey == self.__player.req_confirmkey or playerrequest.req_alreadykey != self.__player.req_confirmkey:
            raise AppTestError(u'ガチャプレイ情報の確認キーが更新されていない')
        elif playcount.getTodayPlayCnt() < 1:
            raise AppTestError(
                u'ガチャプレイ回数が増えていない.%d, %d, %s' %
                (playcount.getTodayPlayCnt(), playcount.cnt, playcount.ptime))

        # BOX確認.
        box = GachaBox(self.__gachamaster, playdata)
        if box.get_rest_num() != 1:
            raise AppTestError(u'BOXのカードがうまく消費されていない.%d' % box.get_rest_num())

        # カードが増えているか.
        cardnum = BackendApi.get_cardnum(self.__player.id)
        tmp_card_num = min(self.__cardnum + entry.continuity,
                           self.__player.cardlimit)
        if tmp_card_num != cardnum:
            raise AppTestError(u'カード枚数がおかしい %d vs %d' %
                               (self.__cardnum, cardnum))

        # おまけが来ているか.
        present_num = BackendApi.get_present_num(self.__player.id)
        if (self.__present_num + self.__gachamaster.continuity) == present_num:
            raise AppTestError(u'おまけが来ていない')
Exemple #4
0
    def check(self):
        model_mgr = ModelRequestMgr()
        # 課金情報.
        entry = BackendApi.get_gachapaymententry(model_mgr,
                                                 self.__payment_entry.id)
        if entry is None:
            raise AppTestError(u'課金レコードが作成されていない')
        elif entry.state != PaymentData.Status.COMPLETED:
            raise AppTestError(u'課金ステータスが異常です.status=%s' % entry.state)

        playerrequest = PlayerRequest.getByKey(self.__player.id)
        # プレイ情報.
        playdata = GachaPlayData.getByKey(
            GachaPlayData.makeID(self.__player.id, self.__gachamaster.boxid))
        playcount = GachaPlayCount.getByKey(
            GachaPlayCount.makeID(self.__player.id, self.__gachamaster.id))

        if playerrequest.req_confirmkey == self.__player.req_confirmkey or playerrequest.req_alreadykey != self.__player.req_confirmkey:
            raise AppTestError(u'ガチャプレイ情報の確認キーが更新されていない')
        elif playcount.getTodayPlayCnt() < 1:
            raise AppTestError(
                u'ガチャプレイ回数が増えていない.%d, %d, %s' %
                (playcount.getTodayPlayCnt(), playcount.cnt, playcount.ptime))

        # BOX確認.
        box = GachaBox(self.__gachamaster, playdata)
        if box.get_rest_num() != 1:
            raise AppTestError(u'BOXのカードがうまく消費されていない.%d' % box.get_rest_num())

        # カードが増えているか.
        cardnum = BackendApi.get_cardnum(self.__player.id)
        tmp_card_num = min(self.__cardnum + entry.continuity,
                           self.__player.cardlimit)
        if tmp_card_num != cardnum:
            raise AppTestError(u'カード枚数がおかしい %d vs %d' %
                               (self.__cardnum, cardnum))

        # おまけが来ているか.
        present_num = BackendApi.get_present_num(self.__player.id)
        if (self.__present_num + self.__gachamaster.continuity) == present_num:
            raise AppTestError(u'おまけが来ていない')

        # ランキングスコア情報.
        scoredata = RankingGachaScore.getByKey(
            RankingGachaScore.makeID(self.__player.id,
                                     self.__rankingmaster.id))
        if scoredata is None:
            raise AppTestError(u'ランキングのスコア情報が作成されていない')

        point = self.__gachamaster.continuity * ApiTest.RANKING_POINT
        # 累計Pt.
        if scoredata.total != point:
            raise AppTestError(u'累計Ptが正しくない.%d vs %d' %
                               (scoredata.total, point))

        # 単発Pt.
        if scoredata.single != point:
            raise AppTestError(u'単発Ptが正しくない.%d vs %d' %
                               (scoredata.single, point))

        # 総計Pt.
        if scoredata.firstpoint != point:
            raise AppTestError(u'初回総計Ptが正しくない.%d vs %d' %
                               (scoredata.firstpoint, point))

        wholedata = RankingGachaWholeData.getByKey(self.__rankingmaster.id)
        if wholedata is None:
            raise AppTestError(u'総計Ptが保存されていない')
        elif wholedata.point != point:
            raise AppTestError(u'総計Ptが正しくない.%d vs %d' %
                               (wholedata.point, point))

        # 総計Pt達成報酬用のキュー.
        queue_cnt = RankingGachaWholePrizeQueue.count()
        if (self.__queue_cnt + 1) != queue_cnt:
            raise AppTestError(u'総計Pt達成報酬のキューが正しく積まれていない.%d vs %d' %
                               (self.__queue_cnt + 1, queue_cnt))
Exemple #5
0
    def handle(self, *args, **options):

        print '================================'
        print 'copy_img'
        print '================================'

        out = args[0]

        # ガチャのマスターを取得.
        gachalist = GachaMaster.fetchValues(filters={
            'consumetype__in':
            Defines.GachaConsumeType.PAYMENT_TYPES,
            'schedule__gt':
            0
        },
                                            using=backup_db)

        # ガチャのボックスデータを作成.
        read_boxids = []

        card_dict = {}
        for gacha in gachalist:
            if gacha.boxid in read_boxids:
                continue

            schedule = ScheduleMaster.getByKey(gacha.schedule, using=backup_db)
            name = u'%s(%s-%s)' % (gacha.name,
                                   schedule.stime.strftime('%m/%d'),
                                   schedule.stime.strftime('%m/%d'))

            boxmaster = GachaBoxMaster.getByKey(gacha.boxid, using=backup_db)
            gachamasterset = GachaMasterSet(gacha, boxmaster, schedule)

            gachabox = GachaBox(gachamasterset,
                                GachaPlayData.makeInstance(
                                    GachaPlayData.makeID(0, gacha.boxid)),
                                blank=True)
            grouplist = GachaGroupMaster.getByKey(gachabox.get_group_id_list(),
                                                  using=backup_db)

            # カードIDとガチャのIDをひもづける.
            for group in grouplist:
                if 1 < len(group.table):
                    continue
                cardid = group.table[0]['id']
                arr = card_dict[cardid] = card_dict.get(cardid) or []
                arr.append(name)

        # カードマスターを取得.
        cardmasterlist = CardMaster.getByKey(card_dict.keys(),
                                             order_by='id',
                                             using=backup_db)

        # CSVを作成.
        rows = []

        def makeRow(row):
            arr = []
            for v in row:
                s = u'%s' % v
                s = s.replace('"', '""')
                arr.append(u'"%s"' % s)
            return u','.join(arr)

        for cardmaster in cardmasterlist:
            cardsortmaster = CardSortMaster.getByKey(cardmaster.id,
                                                     using=backup_db)

            row = [
                cardmaster.id, cardmaster.name,
                Defines.Rarity.NAMES[cardsortmaster.rare],
                Defines.CharacterType.NAMES[cardsortmaster.ctype]
            ]
            row.extend(card_dict[cardmaster.id])
            str_row = makeRow(row)
            print str_row
            rows.append(str_row)
        csv_data = StrUtil.to_s(u'\n'.join(rows), dest_enc='shift-jis')

        f = None
        try:
            f = open(out, "w")
            f.write(csv_data)
            f.close()
        except:
            if f:
                f.close()
                f = None
            raise

        print '================================'
        print 'output:%s' % out
        print 'all done..'
Exemple #6
0
    def __testGacha(self, gachamaster, cnt):
        """ガチャをテスト実行.
        """
        model_mgr = self.getModelMgr()

        test_playdata = GachaPlayData.makeInstance(
            GachaPlayData.makeID(0, gachamaster.boxid))

        # BOX.
        box = GachaBox(gachamaster, test_playdata)
        groupidlist = box.get_group_id_list()
        groupdict = dict([
            (groupmaster.id, GachaBoxGroup(groupmaster))
            for groupmaster in BackendApi.get_gachagroupmaster_list(
                model_mgr, groupidlist, using=backup_db)
        ])

        # 設定値.
        group_rate_dict = {}
        cardrate_dict = {}
        cardgroup_dict = {}
        for groupid in groupidlist:
            rate = box.get_group_rate(groupid)
            group_rate_dict[groupid] = group_rate_dict.get(groupid, 0) + rate

            group_cardrate_dict = {}
            group = groupdict[groupid]
            for carddata in group.carddata_list:
                cardid = carddata.card
                group_cardrate_dict[cardid] = group_cardrate_dict.get(
                    cardid, 0) + carddata.rate

                arr = cardgroup_dict[cardid] = cardgroup_dict.get(cardid) or []
                arr.append(groupid)

            cardrate_dict[groupid] = group_cardrate_dict

        # ランダム.
        rand = AppRandom()

        #        result_list = []
        distribution_dict = dict.fromkeys(cardgroup_dict.keys(), 0)
        group_distribution_dict = dict.fromkeys(groupdict.keys(), 0)

        def addResult(cardid, point, groupid):
            #            result_list.append((cardid, point, groupid))
            distribution_dict[cardid] = (distribution_dict.get(cardid)
                                         or 0) + 1
            group_distribution_dict[groupid] = (
                group_distribution_dict.get(groupid) or 0) + 1

        # ランキングガチャ用ポイント獲得関数.
        point_getter = lambda x: 0
        if gachamaster.consumetype == Defines.GachaConsumeType.RANKING:
            rankinggachamaster = BackendApi.get_rankinggacha_master(
                model_mgr, gachamaster.boxid, using=backup_db)
            if rankinggachamaster:
                randmax = rankinggachamaster.randmax
                randmin = rankinggachamaster.randmin
                point_getter = lambda x: x.point * (100 + rand.getIntN(
                    randmin + randmax) - randmin) / 100

        # BOXからグループを選択.
        groupidlist = []
        for _ in xrange(cnt):
            if box.is_empty:
                # 空になったのでリセット.
                test_playdata.resetGroupCounts()
                box = GachaBox(gachamaster, test_playdata)
            groupid, _ = box.select(rand)
            group = groupdict[groupid]
            carddata = group.select_obj(rand)
            addResult(carddata.card, point_getter(carddata), groupid)


#        self.html_param['result_list'] = result_list
        self.html_param['distribution_dict'] = distribution_dict
        self.html_param['group_dict'] = groupdict
        self.html_param['group_distribution_dict'] = group_distribution_dict
        self.html_param['group_rate_dict'] = group_rate_dict
        self.html_param['group_rate_total'] = sum(group_rate_dict.values())
        self.html_param['cardrate_dict'] = cardrate_dict
        self.html_param['cardgroup_dict'] = cardgroup_dict

        cardmaster_idlist = distribution_dict.keys()
        cardmaster_dict = BackendApi.get_cardmasters(cardmaster_idlist,
                                                     model_mgr,
                                                     using=backup_db)
        self.html_param['cardmaster_dict'] = cardmaster_dict
Exemple #7
0
    def __valid_master(self, master):
        model_mgr = self.getModelMgr()

        if not master.is_public:
            return

        boxmaster = GachaBoxMaster.getByKey(master.boxid)
        if boxmaster is None:
            raise ModelEditValidError(u'存在しないBOXが設定されています.gacha=%d' % master.id)

        if master.stepid != 0:
            stepmaster = GachaStepupMaster.getByKey(master.stepid)
            if stepmaster is None:
                raise ModelEditValidError(u'存在しないSTEPが設定されています.gacha=%d' % master.id)

        if master.seattableid:
            seatmaster = GachaSeatTableMaster.getByKey(master.seattableid)
            if seatmaster is None:
                raise ModelEditValidError(u'存在しないシートテーブルが設定されています.gacha=%d' % master.id)

        if master.gacha_explain_text_id:
            gachaexplainmaster = GachaExplainMaster.getByKey(master.gacha_explain_text_id)
            if gachaexplainmaster is None:
                raise ModelEditValidError(u'存在しないGachaExplainMasterが設定されています.gacha=%d' % master.id)

        if self.valid_error_num < 10:
            for record in self.allmasters:
                if master.id == record.id:
                    self.valid_error_num += 1
                    raise ModelEditValidError(u'IDが重複しています.id={}'.format(master.id))

        master.bonus = master.bonus or []
        if master.bonus:
            def checkBonus(bonus):
                items = {}
                for item in PrizeMaster.getByKey(bonus):
                    items[item.id] = item
                for itemid in bonus:
                    if items.get(itemid) is None:
                        raise ModelEditValidError(u'存在しない引抜のおまけアイテムが設定されています.gacha=%d' % master.id)

            if isinstance(master.bonus[0], dict):
                for data in master.bonus:
                    if data.get('rate', 0) < 1:
                        raise ModelEditValidError(u'確率がないおまけが設定されています.gacha=%d' % master.id)
                    elif not data.get('prize'):
                        raise ModelEditValidError(u'内容がないおまけが設定されています.gacha=%d' % master.id)
                    checkBonus(data['prize'])
            else:
                checkBonus(master.bonus)

        playdata = GachaPlayData.makeInstance(0)
        playdata.mid = master.boxid

        if master.consumetype in Defines.GachaConsumeType.BOX_TYPES:
            # ボックスガチャ.
            if not GachaBox(GachaMasterSet(master, boxmaster), playdata).is_boxgacha:
                raise ModelEditValidError(u'%sなのにBOXでないboxidが指定されています.gacha=%d' % (Defines.GachaConsumeType.NAMES[master.consumetype], master.id))

        if not isinstance(master.variableconsumevalue, dict):
            master.variableconsumevalue = {}

        # 回数別のBOXの検証.
        master.special_boxid = master.special_boxid or []
        if master.special_boxid:
            master_special_boxid = dict(master.special_boxid)
            boxmaster_dict = dict([(bm.id, bm) for bm in GachaBoxMaster.getByKey(master_special_boxid.values())])
            if len(list(set(master_special_boxid.values()))) != len(boxmaster_dict.keys()):
                raise ModelEditValidError(u'存在しないboxidがspecial_boxidに設定されています.gacha=%d' % master.id)

            special_box = dict([(cnt, boxmaster_dict[boxid].box) for cnt, boxid in master.special_boxid])
            box = GachaBox(GachaMasterSet(master, boxmaster), playdata, special_box=special_box)
            try:
                box.validate()
            except CabaretError, err:
                raise ModelEditValidError(u'%s.gacha=%d' % (err.value, master.id))

            # 元のグループのカード.
            cardidlist = []
            for group in GachaGroupMaster.getByKey(box.get_group_id_list()):
                # 各グループの出現率.
                groupdata = GachaBoxGroup(group)
                cardidlist.extend([carddata.card for carddata in groupdata.carddata_list])
            cardidlist = list(set(cardidlist))

            # 回数別のグループのBOX.
            for cnt, boxid in master.special_boxid:
                grouplist = GachaGroupMaster.getByKey(box.get_group_id_list(cnt=cnt))
                for group in grouplist:
                    # 各グループの出現率.
                    groupdata = GachaBoxGroup(group)
                    for carddata in groupdata.carddata_list:
                        if not carddata.card in cardidlist:
                            raise ModelEditValidError(u'%d回目のBOXにしか存在しないカードが有ります.gacha=%d,group=%d,card=%d' % (cnt, master.id, group.id, carddata.card))