Ejemplo n.º 1
0
 def install(self, uid):
     """初回アクセス.
     """
     p = Player()
     p.id = uid
     p.dmmid = self.makeDmmId(uid)
     player = ModelPlayer([p])
     return player
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        redisdb = RedisModel.getDB()

        uid_max = Player.max_value('id')
        for i in xrange(0, uid_max):
            uid = uid_max - i

            changed = False
            for state in Defines.FriendState.NAMES.keys():
                friendlist = Friend.fetchValues(filters={
                    'uid': uid,
                    'state': state
                })
                cur_num = BackendApi._get_friend_num(uid, state)
                if cur_num == len(friendlist):
                    continue

                pipe = redisdb.pipeline()
                pipe.delete(FriendListSet.makeKey(uid, state))
                for friend in friendlist:
                    FriendListSet.create(uid, friend.fid, state,
                                         friend.ctime).save(pipe)
                pipe.execute()
                changed = True
            if changed:
                print '%s' % uid

        print '================================'
        print 'all done'
Ejemplo n.º 3
0
    def get_data(self):
        idmax = Player.max_value('id', using=backup_db)
        if not idmax:
            return []

        LIMIT = 500
        datalist = []
        uid = 1
        date = self.date

        while uid <= idmax:
            range_max = min(idmax + 1, uid + LIMIT)
            uidlist = range(uid, range_max)

            rank_map = BattleEventDailyUserRankSet.fetch(date, uidlist)
            attack_map = BattleEventBattleCountAttack.fetch(date, uidlist)
            attackwin_map = BattleEventBattleCountAttackWin.fetch(
                date, uidlist)
            defense_map = BattleEventBattleCountDefense.fetch(date, uidlist)
            defensewin_map = BattleEventBattleCountDefenseWin.fetch(
                date, uidlist)

            for uid in uidlist:
                datalist.append(
                    (uid, rank_map.get(uid, 0), attack_map.get(uid, 0),
                     attackwin_map.get(uid, 0), defense_map.get(uid, 0),
                     defensewin_map.get(uid, 0)))
            uid += LIMIT

        return datalist
Ejemplo n.º 4
0
    def handle(self, *args, **options):

        uid_max = Player.max_value('id')

        now = OSAUtil.get_now()
        bordertime = now - datetime.timedelta(days=30)

        redisdb = RedisModel.getDB()
        for i in xrange(0, uid_max):
            uid = uid_max - i
            player_login = PlayerLogin.getByKey(uid,
                                                using=settings.DB_READONLY)
            if player_login is None or bordertime <= player_login.ltime:
                continue

            pipe = redisdb.pipeline()

            pipe.delete(UserCardIdListSet.makeKey(uid))
            pipe.delete(CardKindListSet.makeKey(uid))
            pipe.delete(EvolutionAlbumHkLevelListSet.makeKey(uid))

            FriendAcceptNum.create(uid).delete(pipe)

            FreeGachaLastTime.create(uid).delete(pipe)

            RaidHelpFriendData.create(uid).delete(pipe)
            RaidCallFriendTime.create(uid).delete(pipe)

            for topic in Defines.PresentTopic.RANGE:
                pipe.delete(PresentIdListSet.makeKey(uid, topic))

            for treasuretype in Defines.TreasureType.NAMES.keys():
                pipe.delete(TreasureListSet.makeKey(uid, treasuretype))

            pipe.delete(PlayerLogListSet.makeKey(uid))

            LastViewArea.create(uid).delete(pipe)

            pipe.delete(RaidHelpSet.makeKey(uid))

            pipe.delete(RaidLogNotificationSet.makeKey(uid))

            PlayerConfigData.create(uid).delete(pipe)

            pipe.execute()

            print '%s..DELETE' % uid

        print '================================'
        print 'all done'
Ejemplo n.º 5
0
    def get_data(self):
        idmax = Player.max_value('id', using=backup_db)
        if not idmax:
            return []

        str_date = self.date.strftime("%Y/%m/%d")

        LIMIT = 500
        datalist = []
        uid = 1
        while uid <= idmax:
            range_max = min(idmax + 1, uid + LIMIT)
            uidlist = range(uid, range_max)
            modellist = BattleEventResult.fetch(self.date, uidlist)
            for model in modellist:
                datalist.append((str_date, model.rank, model.uid,
                                 model.grouprank, model.point))
            uid += LIMIT
        return datalist
    def handle(self, *args, **options):

        print '======================================='
        print 'Generate cabaret club user ranking data'
        print '======================================='

        players = Player.fetchValues(using=settings.DB_READONLY)
        rand = AppRandom()
        redisdb = RedisModel.getDB()
        pipe = redisdb.pipeline()
        for player in players:
            sales = rand.getIntN(10000)
            CabaClubRanking.create("currentweek", player.id, sales).save(pipe)
            CabaClubRanking.create("lastweek", player.id,
                                   max(100, sales - 1500)).save(pipe)

        pipe.execute()

        print '================================'
        print 'all done...'
Ejemplo n.º 7
0
    def handle(self, *args, **options):
        print '================================'
        print 'reset player is_get_targetrarity'
        print '================================'

        resetdata = GachaBoxResetPlayerData.fetchValues(using=backup_db)
        resetdata_uid = [reset.id for reset in resetdata]

        playerlist = Player.fetchValues(using=backup_db,
                                        excludes={'id__in': resetdata_uid})

        users = [
            player for player in playerlist if player.id not in resetdata_uid
        ]

        # update is_get_targetrarity
        try:
            db_util.run_in_transaction(self.tr_update, resetdata)
        except CabaretError, err:
            print 'error...{}'.format(err.value)
Ejemplo n.º 8
0
    def handle(self, *args, **options):

        print '================================'
        print 'reload_presentidlist'
        print '================================'

        uid_max = Player.max_value('id')
        redisdb = RedisModel.getDB()
        pipe = redisdb.pipeline()
        model_mgr = ModelRequestMgr()

        for uid in xrange(1, uid_max + 1):
            BackendApi._save_presentidlist(uid,
                                           model_mgr,
                                           using=settings.DB_READONLY,
                                           pipe=pipe)
            print '%s..end' % uid

        pipe.execute()
        print '================================'
        print 'all done'
Ejemplo n.º 9
0
    def handle(self, *args, **options):

        print '================================'
        print 'reload_kpi'
        print '================================'

        uid_max = Player.max_value('id', using=settings.DB_READONLY)

        for uid in xrange(1, uid_max + 1):
            itemlist = Item.fetchByOwner(uid, using=settings.DB_READONLY)
            if not itemlist:
                continue

            ope = KpiOperator()
            for item in itemlist:
                ope.set_save_itemnum(item.uid, item.mid, item.rnum, item.vnum)
            ope.save()

            print uid

        print '================================'
        print 'all done...'
Ejemplo n.º 10
0
    def handle(self, *args, **options):

        print '================================'
        print 'select_userlog'
        print '================================'

        target = args[0]
        model_cls = self.getModelClass(target)

        str_ctime_min = args[1]
        ctime_min = DateTimeUtil.strToDateTime(str_ctime_min,
                                               "%Y-%m-%d %H:%M:%S")

        getter = eval(args[2])

        LIMIT = 3000
        uid_max = Player.max_value('id', using=backup_db)

        for uid in xrange(1, uid_max + 1):
            filters = {'uid': uid, 'ctime__gte': ctime_min}
            offset = 0
            num = 0
            while True:
                modellist = model_cls.fetchValues(filters=filters,
                                                  order_by='ctime',
                                                  limit=LIMIT,
                                                  offset=offset,
                                                  using=backup_db)
                if not modellist:
                    break
                offset += len(modellist)

                for model in modellist:
                    num += getter(model)
            if num:
                print '%d,%d' % (uid, num)

        print '================================'
        print 'all done..'
Ejemplo n.º 11
0
    def handle(self, *args, **options):

        print '================================'
        print 'reload_friendlist'
        print '================================'

        uid_max = Player.max_value('id')

        for uid in xrange(1, uid_max + 1):
            if Friend.getValues(filters={'uid': uid},
                                using=settings.DB_READONLY) is None:
                print '%s..none' % uid
                continue

            for state in Defines.FriendState.NAMES.keys():
                BackendApi._save_friendidlist(uid,
                                              state,
                                              ModelRequestMgr(),
                                              using=settings.DB_READONLY)

            print '%s..end' % uid

        print '================================'
        print 'all done'
Ejemplo n.º 12
0
 def get_data(self):
     uid_max = Player.max_value('id', using=backup_db)
     data = ScoutEventTanzakuHash.aggregate(uid_max)
     self.__data = data
     return data or None
Ejemplo n.º 13
0
 def get_playerids(self, dmmids):
     dmmid_list = list(set(dmmids))
     uid_to_dmmid = dict([(int(p.dmmid), int(p.id)) for p in Player.fetchValues(['id', 'dmmid'], filters={'dmmid__in':dmmid_list}, using=backup_db)])
     
     return uid_to_dmmid
Ejemplo n.º 14
0
    def process(self):

        args = self.getUrlArgs('/infomations/view_promotion/')
        dmmid = args.get(0) or ''

        model_mgr = self.getModelMgr()

        data = PeopleRequestData.createForPeople(dmmid)
        request = self.osa_util.makeApiRequest(ApiNames.People, data)
        reqkey = 'Person:%s' % dmmid
        self.addAppApiRequest(reqkey, request)

        ret_data = self.execute_api()
        try:
            person = ret_data[reqkey].get()
            if type(person) in (list, tuple):
                person = person[0]
        except:
            person = People.makeNotFound(dmmid)
        self.html_param['nickname'] = person.nickname

        appname = self.request.get('appname', PromotionSettings.Apps.KOIHIME)
        self.html_param['promotion_appname'] = appname
        self.html_param['promotion_apps'] = PromotionSettings.CONFIG.keys()

        # ギャングオブヘブンのプロモは別形式なので分ける
        if appname == 'Standard':
            uid = Player.getValues(filters={'dmmid': str(dmmid)}).id
            crosspromo_data = model_mgr.get_model(PlayerCrossPromotion,
                                                  uid,
                                                  using=settings.DB_READONLY)
            if crosspromo_data is None:
                self.html_param['displaylist'] = []
            else:
                self.html_param['displaylist'] = [
                    dmmid,
                    crosspromo_data.total_login_count,
                    crosspromo_data.is_battle,
                    crosspromo_data.is_battle_win_continue,
                    crosspromo_data.is_battle_rank5,
                    crosspromo_data.is_level10,
                    crosspromo_data.is_level20,
                    crosspromo_data.is_open_cabaclub,
                    crosspromo_data.is_trade_treasure,
                    crosspromo_data.is_acquired_ssr_card,
                ]
            self.writeAppHtml('infomations/view_promotion_standard')
            return

        master_cls = PromotionUtil.getPromotionPrizeMasterCls(appname)
        promotionmaster_all = model_mgr.get_mastermodel_all(
            master_cls, order_by='id', using=settings.DB_READONLY)
        midlist = [
            promotionmaster.id for promotionmaster in promotionmaster_all
        ]

        uid = BackendApi.dmmid_to_appuid(self, [dmmid],
                                         using=settings.DB_READONLY).get(dmmid)
        if uid:
            userdata_dict = BackendApi.get_promotion_userdata(
                model_mgr, appname, uid, midlist, using=settings.DB_READONLY)
        else:
            userdata_dict = {}

        obj_prizelist = []
        for promotionmaster in promotionmaster_all:
            userdata = userdata_dict.get(promotionmaster.id)
            status = userdata.status if userdata else Defines.PromotionStatus.NONE
            atime = userdata.atime.strftime(
                "%Y-%m-%d %H:%M:%S"
            ) if status != Defines.PromotionStatus.NONE else u'------'
            rtime = userdata.rtime.strftime(
                "%Y-%m-%d %H:%M:%S"
            ) if status == Defines.PromotionStatus.RECEIVED else u'------'

            obj_prizelist.append({
                'id':
                promotionmaster.id,
                'name':
                promotionmaster.name,
                'status':
                status,
                'str_status':
                Defines.PromotionStatus.NAMES[status],
                'atime':
                atime,
                'rtime':
                rtime,
            })
        self.html_param['promotionprizelist'] = obj_prizelist

        self.writeAppHtml('infomations/view_promotion')
Ejemplo n.º 15
0
    def handle(self, *args, **options):

        #        uid_list = (
        #            5,
        #            142927,
        #            142702,
        #            142413,
        #            142177,
        #            141773,
        #            141142,
        #            140679,
        #            140510,
        #            139896,
        #            139206,
        #            138892,
        #            138882,
        #            138380,
        #            137618,
        #            137441,
        #            137198,
        #            136769,
        #            136729,
        #            136383,
        #            136076,
        #            135863,
        #            135265,
        #            135018,
        #            133637,
        #            133377,
        #            133245,
        #            133087,
        #            132508,
        #            131708,
        #            131684,
        #            131217,
        #            129689,
        #            129672,
        #            128334,
        #            127452,
        #            126730,
        #            126551,
        #            126359,
        #            125413,
        #            124413,
        #            124081,
        #            123502,
        #            123276,
        #            123182,
        #            123086,
        #            122663,
        #            121682,
        #            121447,
        #            120378,
        #            120224,
        #            119539,
        #            118344,
        #            115990,
        #            114852,
        #            114802,
        #            114765,
        #            113959,
        #            113221,
        #            112996,
        #            111318,
        #            109272,
        #            109114,
        #            108942,
        #            108771,
        #            108748,
        #            108664,
        #            108365,
        #            108250,
        #            108145,
        #            106770,
        #            106474,
        #            105621,
        #            103726,
        #            103590,
        #            103114,
        #            101811,
        #            101805,
        #            101686,
        #            101399,
        #            101187,
        #            100986,
        #            100909,
        #            100616,
        #            100409,
        #            99927,
        #            99724,
        #            98702,
        #            97335,
        #            96754,
        #            96034,
        #            95933,
        #            94581,
        #            94516,
        #            91956,
        #            91107,
        #            90939,
        #            90171,
        #            89496,
        #            89361,
        #            89237,
        #            89021,
        #            86396,
        #            84414,
        #            82889,
        #            82751,
        #            80707,
        #            76836,
        #            76796,
        #            76734,
        #            76059,
        #            72357,
        #            71135,
        #            69565,
        #            67323,
        #            66410,
        #            66352,
        #            66327,
        #            65830,
        #            65130,
        #            63588,
        #            62426,
        #            62124,
        #            61777,
        #            58634,
        #            57621,
        #            56803,
        #            56184,
        #            55864,
        #            54157,
        #            51287,
        #            47022,
        #            45807,
        #            45708,
        #            45528,
        #            44803,
        #            43644,
        #            42666,
        #            41879,
        #            41351,
        #            41279,
        #            41161,
        #            40379,
        #            39876,
        #            39372,
        #            38964,
        #            37470,
        #            35761,
        #            35640,
        #            35032,
        #            32165,
        #            31117,
        #            29387,
        #            28368,
        #            28093,
        #            26098,
        #            24391,
        #            23765,
        #            20800,
        #            20684,
        #            17322,
        #            16014,
        #            14523,
        #            12722,
        #            8823,
        #            7812,
        #            7621,
        #            7440,
        #            7351,
        #            7001,
        #            6998,
        #            6233,
        #            4776,
        #            2551,
        #            2044,
        #            1980,
        #            1046,
        #            806,
        #        )
        #        redisdb = RedisModel.getDB()
        #        for uid in uid_list:
        #            cardlist = Card.fetchByOwner(uid)
        #            cardidlist = [card.id for card in cardlist]
        #            model_mgr = ModelRequestMgr()
        #            model_mgr.set_got_models(cardlist)
        #            cardsetlist = BackendApi.get_cards(cardidlist)
        #
        #            pipe = redisdb.pipeline()
        #            for cardset in cardsetlist:
        #                BackendApi.save_cardidset(cardset, pipe)
        #            pipe.execute()
        #            print '%s...OK' % uid

        uid_max = Player.max_value('id')

        #        redisdb = RedisModel.getDB()
        for i in xrange(0, uid_max):
            #        for uid in uid_list:
            uid = uid_max - i

            cardnum = BackendApi.get_cardnum(uid)
            db_cardnum = Card.count(filters={"uid": uid})
            if db_cardnum == cardnum:
                continue
            print '%s..NG' % uid

        print '================================'
        print 'all done'
Ejemplo n.º 16
0
    def handle(self, *args, **options):

        print '================================'
        print 'close_rankinggacha'
        print '================================'

        model_mgr = ModelRequestMgr()

        now = OSAUtil.get_now()

        # メンテナンス確認.
        appconfig = BackendApi.get_appconfig(model_mgr)
        if not appconfig.is_maintenance():
            print u'メンテナンスモードにしてください'
            return
        print 'check maintenance...OK'

        print '================================'
        print 'check master'
        group = int(args[0])
        master_list = BackendApi.get_rankinggacha_master_by_group(
            model_mgr, group, using=settings.DB_READONLY)
        if not master_list:
            print u'ランキングガチャではありません'
            return
        boxidlist = [master.id for master in master_list]
        master_dict = dict([(master.id, master) for master in master_list])
        gachamaster_list = GachaMaster.fetchValues(
            filters={'boxid__in': boxidlist}, using=settings.DB_READONLY)
        gachamaster_list = [
            gachamaster.id for gachamaster in gachamaster_list
            if BackendApi.check_schedule(model_mgr,
                                         gachamaster.schedule,
                                         using=settings.DB_READONLY,
                                         now=now)
        ]
        if gachamaster_list:
            print u'ガチャが開いています.id=%s' % gachamaster_list
            return
        print 'check master...OK'

        print '================================'
        print 'update ranking:start'
        # ランキングを更新.
        for master in master_list:
            offset = 0
            limit = 1000
            flag_support_totalranking = master.is_support_totalranking

            while True:
                recordlist = RankingGachaScore.fetchValues(
                    filters={'mid': master.id}, limit=limit, offset=offset)

                pipe = RankingGachaSingleRanking.getDB().pipeline()
                for record in recordlist:
                    RankingGachaSingleRanking.create(master.id, record.uid,
                                                     record.single).save(pipe)
                    if flag_support_totalranking:
                        RankingGachaTotalRanking.create(
                            master.id, record.uid, record.total).save(pipe)
                pipe.execute()

                if len(recordlist) < limit:
                    break
                offset += limit
        print 'update ranking:end'

        print '================================'
        print 'send ranking prizes:start'
        for master in master_list:
            boxid = master.id

            close_model = RankingGachaClose.getByKey(boxid)
            if close_model is None:
                close_model = RankingGachaClose.makeInstance(boxid)
                close_model.insert()

            print 'start...single'
            close_model = self.__send_prize(model_mgr, master.singleprizes,
                                            master.singleprize_text,
                                            close_model, 'prize_flag_single',
                                            RankingGachaSingleRanking)

            if flag_support_totalranking:
                print 'start...total'
                close_model = self.__send_prize(model_mgr, master.totalprizes,
                                                master.totalprize_text,
                                                close_model,
                                                'prize_flag_total',
                                                RankingGachaTotalRanking)

        print '================================'
        print 'send whole prizes:start'
        # 勝利したBOX.
        wholedata_list = RankingGachaWholeData.getByKey(boxidlist)
        arr = [(wholedata.id, wholedata.point) for wholedata in wholedata_list]
        arr.sort(key=lambda x: x[1], reverse=True)
        winner = []
        point_max = None
        for boxid, point in arr:
            if point_max is not None and point < point_max:
                break
            elif point < 1:
                break
            winner.append(boxid)
            point_max = point
        print 'winner:%s' % winner

        queuelist = RankingGachaWholePrizeQueue.fetchValues(
            filters={'boxid__in': boxidlist})
        queuelist.sort(key=lambda x: x.id)

        boxidlist.sort()
        close_model_boxid = boxidlist[0]
        close_model = RankingGachaClose.getByKey(close_model_boxid)

        uid_max = Player.max_value('id')
        for uid in xrange(close_model.prize_flag_whole + 1, uid_max + 1):
            # 全員について検証.
            data = RankingGachaWholePrizeData.getByKey(uid)
            if data is None:
                # 未プレイ.
                continue

            # スコア情報.
            firstpoint_dict = dict([
                (scoredata.mid, scoredata.firstpoint)
                for scoredata in RankingGachaScore.getByKey([
                    RankingGachaScore.makeID(uid, boxid) for boxid in boxidlist
                ])
            ])

            # 未受け取り分.
            queuelist_not_received = [
                queue for queue in queuelist
                if data.queueid < queue.id and firstpoint_dict.get(queue.boxid)
                and firstpoint_dict[queue.boxid] <= queue.point
            ]

            # 勝利判定.
            win_boxidlist = list(set(firstpoint_dict.keys()) & set(winner))

            if not (queuelist_not_received or win_boxidlist):
                # 未受け取りの報酬が無い 且つ 敗北.
                continue

            try:
                model_mgr, close_model = db_util.run_in_transaction(
                    self.__tr_send_wholeprize, uid, queuelist_not_received,
                    master_dict, win_boxidlist, close_model_boxid)
                model_mgr.write_end()
                print '%d...receive' % uid
            except CabaretError, err:
                if err.code == CabaretError.Code.ALREADY_RECEIVED:
                    # 受取済みのキューを指定していた.
                    model_mgr, close_model = db_util.run_in_transaction(
                        self.__tr_send_wholeprize, uid, [], master_dict,
                        win_boxidlist, close_model_boxid)
                    model_mgr.write_end()
                    print '%d...already' % uid
                else:
                    raise
Ejemplo n.º 17
0
class Command(BaseCommand):
    """ハプニングを全て削除する.
    """
    def handle(self, *args, **options):
        
        model_mgr = ModelRequestMgr()
        starttime = OSAUtil.get_now()
        
        print '================================'
        print 'delete_happening_all'
        print '================================'
        
        # クリア済みで受け取っていないハプニング.
        print '================================'
        print 'check raid:start'
        # クリア済みのレイドを全て終了させる.
        filters = {'state__in':[Defines.HappeningState.BOSS, Defines.HappeningState.CLEAR]}
        num = Happening.count(filters)
        print 'happenings %d' % num
        
        # メンテナンス確認.
        appconfig = BackendApi.get_appconfig(model_mgr)
        if not appconfig.is_maintenance():
            print u'メンテナンスモードにしてください'
            return
        print 'check maintenance...OK'
        
        offset = 0
        LIMIT = 200
        
        def tr_clear(happeningid):
            model_mgr = ModelRequestMgr()
            happening = Happening.getByKeyForUpdate(happeningid)
            raidboss = BackendApi.get_raid(model_mgr, happeningid)
            BackendApi.tr_happening_end(model_mgr, happening, raidboss)
            model_mgr.write_all()
            return model_mgr
        
        def tr_miss(happeningid):
            model_mgr = ModelRequestMgr()
            BackendApi.tr_happening_missed(model_mgr, happeningid, force=True)
            model_mgr.write_all()
            return model_mgr
        
        while True:
            happeninglist = Happening.fetchValues(['id','state'], filters, limit=LIMIT, offset=offset)
            offset += LIMIT
            
            for happening in happeninglist:
                try:
                    if happening.state == Defines.HappeningState.CLEAR:
                        model_mgr = db_util.run_in_transaction(tr_clear, happening.id)
                    else:
                        model_mgr = db_util.run_in_transaction(tr_miss, happening.id)
                    model_mgr.write_end()
                except CabaretError, err:
                    if err.code == CabaretError.Code.ALREADY_RECEIVED:
                        pass
                    else:
                        raise
                print 'update %d end' % happening.id
            
            if len(happeninglist) < LIMIT:
                break
        
        print 'check raid:end'
        
        print '================================'
        print 'delete mysql'
        # MySQLから削除.
        delete_target_model_cls_list = (
            RaidLog,
            RaidHelp,
            Raid,
            Happening,
        )
        def tr():
            Query.execute_update('set foreign_key_checks = 0;', [], False)
            for model_cls in delete_target_model_cls_list:
                tablename = model_cls.get_tablename()
                query_string = "truncate table `%s`;" % tablename
                Query.execute_update(query_string, [], False)
                print 'delete...%s' % tablename
            Query.execute_update('set foreign_key_checks = 1;', [], False)
        db_util.run_in_transaction(tr)
        
        print '================================'
        print 'delete redis'
        # Redisから削除.
        redisdb = RedisModel.getDB()
        uid_max = Player.max_value('id')
        for uid in xrange(1, uid_max+1):
            redisdb.delete(RaidLogListSet.makeKey(uid), RaidHelpSet.makeKey(uid))
            print 'delete redis...%s' % uid
        
        print '================================'
        print 'all end..'
        
        diff = OSAUtil.get_now() - starttime
        sec = diff.days * 86400 + diff.seconds
        print 'time %d.%06d' % (sec, diff.microseconds)