示例#1
0
    def process(self):
        v_player = self.getViewerPlayer()
        model_mgr = self.getModelMgr()

        # 合成結果.
        compositiondata = BackendApi.get_compositiondata(
            model_mgr, v_player.id, using=settings.DB_READONLY)

        # ベースカード.
        basecardset = BackendApi.get_cards([compositiondata.result_baseid],
                                           model_mgr,
                                           using=settings.DB_READONLY)
        if not basecardset or basecardset[0].card.mid != compositiondata.mid:
            if settings_sub.IS_LOCAL:
                raise CabaretError(u'教育したキャストが見つかりません.')
            url = UrlMaker.composition()
            self.appRedirect(self.makeAppLinkUrlRedirect(url))
            return
        basecardset = basecardset[0]

        self.html_param['basecard_post'] = Objects.card(self, basecardset)
        compositiondata.set_to_card(basecardset.card)
        self.html_param['basecard_pre'] = Objects.card(self, basecardset)

        # 素材カード.
        materialcardsetlist = BackendApi.get_cards(
            compositiondata.result_materialidlist,
            model_mgr,
            using=settings.DB_READONLY,
            deleted=True)
        self.html_param['cardlist'] = [
            Objects.card(self, cardset) for cardset in materialcardsetlist
        ]

        # 経験値とレベル.
        self.html_param['exp'] = compositiondata.result_exp
        self.html_param['levelup'] = compositiondata.result_lvup

        # お金.
        self.html_param['cost'] = compositiondata.result_cost_gold

        # スキル.
        self.html_param['skilllevelup'] = compositiondata.result_skilllvup

        # 成功 or 大成功.
        self.html_param[
            'is_great_success'] = compositiondata.result_flag_great_success

        # 上昇値.
        level_pre = compositiondata.result_lvpre
        level_add = compositiondata.result_lvup
        power_add = 0
        if 0 < level_add:
            basemaster = basecardset.master
            pow_pre = CardUtil.calcPower(basemaster.gtype,
                                         basemaster.basepower,
                                         basemaster.maxpower, level_pre,
                                         basemaster.maxlevel,
                                         basecardset.card.takeover)
            pow_post = CardUtil.calcPower(basemaster.gtype,
                                          basemaster.basepower,
                                          basemaster.maxpower,
                                          level_pre + level_add,
                                          basemaster.maxlevel,
                                          basecardset.card.takeover)
            power_add = pow_post - pow_pre
        self.html_param['power_add'] = power_add
        self.html_param['level_add'] = level_add
        self.html_param['skilllevel_add'] = compositiondata.result_skilllvup

        # 続けて合成のURL.
        url = UrlMaker.compositionmaterial(basecardset.id)
        self.html_param['url_continue'] = self.makeAppLinkUrl(url)

        self.writeAppHtml('composition/complete')
 def handle(self, *args, **options):
     
     print '================================'
     print 'aggregate_deckmember'
     print '================================'
     
     # 出力先.
     path = OSAUtil.get_now().strftime(args[0])
     
     # 書き込むデータをここに溜め込む.
     writer = Command.Writer(path)
     
     # 対象を更新.
     LoginTimeCloneSet.update()
     
     # アクティブユーザだと判定される日数.
     now = OSAUtil.get_now()
     border_date = now - datetime.timedelta(days=Defines.ACTIVE_DAYS)
     
     LIMIT = 300
     
     model_mgr = ModelRequestMgr()
     cardmasters = dict([(master.id, master) for master in model_mgr.get_mastermodel_all(CardMaster, fetch_deleted=True, using=backup_db)])
     cardsortmasters = dict([(master.id, master) for master in model_mgr.get_mastermodel_all(CardSortMaster, fetch_deleted=True, using=backup_db)])
     
     # ヘッダ列.
     title = [u'ユーザID']
     for _ in xrange(Defines.DECK_CARD_NUM_MAX):
         title.extend([u'name', u'rare', u'hklevel', u'level', u'power'])
     for rare in Defines.Rarity.LIST:
         title.append(Defines.Rarity.NAMES[rare])
     writer.add(','.join(title))
     del title
     
     offset = 0
     while True:
         uidlist = LoginTimeCloneSet.fetchByRange(border_date, now, LIMIT, offset)
         
         # デッキ取得.
         decklist = Deck.getByKey(uidlist, using=backup_db)
         
         for deck in decklist:
             row = []
             
             raremap = {}
             
             # カード取得.
             cardidlist = deck.to_array()
             cards = dict([(card.id, card) for card in Card.getByKey(cardidlist, using=backup_db)])
             
             # ユーザID.
             row.append(str(deck.id))
             
             for cardid in cardidlist:
                 card = cards.get(cardid)
                 master = None
                 sortmaster = None
                 if card:
                     master = cardmasters.get(card.mid)
                     sortmaster = cardsortmasters.get(card.mid)
                 
                 if card is None or master is None or sortmaster is None:
                     name = u'不明'
                     rare = u'不明'
                     hklevel = u'不明'
                     level = u'不明'
                     power = u'不明'
                 else:
                     # カード名.
                     name = str(master.name)
                     # レア度.
                     rare = str(sortmaster.rare)
                     # ハメ管理度.
                     hklevel = str(sortmaster.hklevel)
                     # レベル.
                     level = str(card.level)
                     # 接客力.
                     power = str(CardUtil.calcPower(master.gtype, master.basepower, master.maxpower, card.level, master.maxlevel, card.takeover))
                     
                     raremap[sortmaster.rare] = raremap.get(sortmaster.rare, 0) + 1
                 
                 row.extend([name, rare, hklevel, level, power])
             
             for _ in xrange(Defines.DECK_CARD_NUM_MAX - len(cardidlist)):
                 row.extend(['', '', '', '', ''])
             
             for rare in Defines.Rarity.LIST:
                 row.append(str(raremap.get(rare, 0)))
             
             line = ','.join(row)
             writer.add(line)
         
         offset += LIMIT
         
         if len(uidlist) < LIMIT:
             break
     
     writer.output(overwrite=False)
     
     print '================================'
     print 'all done..'