def _save(self, pipe): redisdb = self.getDB() strdata = redisdb.hget(self.__class__.__name__, self.uid) data = None if strdata: try: data = cPickle.loads(strdata) if not isinstance(data, dict): data = None except: pass data = data or {} str_now = DateTimeUtil.dateTimeToStr(self.now) if data.has_key(self.gachaid): data[self.gachaid]['date'] = str_now else: items = list(data.items()) if self.__class__.RECORD_NUM_MAX <= len(items): # レコードの最大数を超えている. items.sort(key=lambda x: x[1]['date']) data = dict(items[1:]) data[self.gachaid] = { 'card': self.leadercard_mid, 'date': str_now, } strdata = cPickle.dumps(data) pipe.hset(self.__class__.__name__, self.uid, strdata)
def to_dict(self): """DBへ保存するために辞書にする. keyはコンストラクタの引数の名前. """ data = { 'damage': self.__damage, 'cnt': self.__damage_cnt, 'number': self.__number, 'feverendtime': DateTimeUtil.dateTimeToStr(self.__feverendtime), } if self.champagne: data['champagne'] = 1 if self.champagne_num_add: data.update(champagne_post=self.champagne_num_post, champagne_add=self.champagne_num_add) if self.material_num: data['material'] = self.material_num if self.tanzaku_num: data.update(tanzaku=self.tanzaku_num, tanzaku_post=self.tanzaku_num_post) return data
def process(self): self.model_form_cls = self.getFormClass() self.MASTER_EDITTIME_COLUMN = Defines.MASTER_EDITTIME_COLUMN self.setting_property() # 必要な値を定義. self.__new_version = True # by default, the management page is the new version self.model_cls = self.model_form_cls.Meta.model self.content_name = self.getUrlArgs('/model_edit/').get(0) fields = self.get_formfields() excludes = getattr(self.model_form_cls.Meta, 'exclude', []) self.model_form_cls.base_fields.keyOrder = [ field for field in fields if not field in excludes ] urlargs = self.getUrlArgs('/model_edit/%s/' % self.content_name) self.__ope = urlargs.get(0, 'list') if self.__ope == 'csv': self.__page = 0 else: self.__page = int(urlargs.get(1, 1)) version = urllib2.unquote(self.request.get("version") or "") if version == "old": self.__new_version = False self.html_param['url_model_edit_list'] = self.makeModelEditLinkUrl( 'list', self.__page) self.html_param['url_cancel'] = self.makeModelEditLinkUrl() url_csv = self.makeModelEditLinkUrl('csv', self.__get_csv_name()) if url_csv[-1] == '/': url_csv = url_csv[:-1] self.html_param['url_csv'] = url_csv self.html_param['url_load_csv'] = self.makeModelEditLinkUrl('load_csv') self.html_param['MODEL_LABEL'] = self.MODEL_LABEL self.html_param['CHECK_CSV_FORM'] = self.allow_csv() self.allmasters = [] if self.request.method == 'POST' and self.request.django_request.POST.get( 'csv_check') != 'on': self.allmasters = self.getModelAll() # ローカルだとうまくアップできないので代わりに見に行く場所指定. self.__local_datafileurl = os.path.join(settings_sub.TMP_DOC_ROOT, self.__get_csv_name()) self.html_param['local_datafileurl'] = self.__local_datafileurl self.html_param['uploadform'] = UploadFileForm() is_singleton = isinstance(self.model_cls(), Singleton) self.html_param['is_singleton'] = is_singleton # 最終更新時間. last_update = None modellist = self.getModelAll() if self.MASTER_EDITTIME_COLUMN: for aa in modellist: edit_time = getattr(aa, self.MASTER_EDITTIME_COLUMN, None) if last_update is None: last_update = edit_time elif last_update < edit_time: last_update = edit_time if last_update is None: self.html_param['last_update'] = '更新なし' else: self.html_param['last_update'] = DateTimeUtil.dateTimeToStr( last_update) table = { 'list': self.__proc_index, 'csv': self.__proc_csv, 'load_csv': self.__proc_load_csv, } table.update(self.getAdditionalProcess() or {}) f = table.get(self.__ope, None) if f: f() else: self.response.set_status(404)
def __procSearch(self): """レイド検索. """ def to_i(v): if str(v).isdigit(): return int(v) else: return None serchtype = self.request.get('_serchtype') value = self.request.get('_value') state = to_i(self.request.get('_state')) or Defines.HappeningState.END page = (to_i(self.request.get('_page')) or 0) model_mgr = self.getModelMgr() raid_all = dict([ (master.id, master) for master in model_mgr.get_mastermodel_all( RaidMaster, fetch_deleted=True, using=settings.DB_READONLY) ]) uid = None if serchtype == 'uid': uid = to_i(value) elif serchtype == 'dmmid': uid = BackendApi.dmmid_to_appuid( self, [value], using=settings.DB_READONLY).get(value) if uid: PAGE_CONTENT_NUM = 100 filters = { 'oid': uid, 'state': state, } nummax = Happening.count(filters, using=settings.DB_READONLY) page_max = (nummax + PAGE_CONTENT_NUM - 1) / PAGE_CONTENT_NUM offset = page * PAGE_CONTENT_NUM recordlist = Happening.fetchValues(filters=filters, order_by='-ctime', limit=PAGE_CONTENT_NUM, offset=offset, using=settings.DB_READONLY) raiddict = BackendApi.get_model_dict( model_mgr, Raid, [record.id for record in recordlist], using=settings.DB_READONLY) raidlist = [] for record in recordlist: raid = raiddict.get(record.id) master = None if raid: master = raid_all.get(record.mid) if master: raidlist.append({ 'id': record.id, 'mid': master.id, 'name': master.name, 'level': record.level, 'ctime': DateTimeUtil.dateTimeToStr(record.ctime), 'url': self.makeAppLinkUrlAdmin(UrlMaker.view_raid(record.id)) }) else: raidlist.append({ 'id': record.id, 'mid': record.mid, 'name': u'不明', 'level': record.level, 'ctime': DateTimeUtil.dateTimeToStr(record.ctime), 'url': None }) url = UrlMaker.view_raid() url = OSAUtil.addQuery(url, '_serchtype', serchtype) url = OSAUtil.addQuery(url, '_value', value) url = OSAUtil.addQuery(url, '_state', state) def __makePage(index): return { 'num': index, 'url': self.makeAppLinkUrlAdmin( OSAUtil.addQuery(url, '_page', index - 1)), } pagination_data = { 'page_list': [__makePage(p) for p in xrange(1, page_max)], 'now_page': __makePage(page + 1), 'has_next': False, 'has_prev': False, } if page < page_max: pagination_data['next_page'] = __makePage(page + 1) pagination_data['has_next'] = True if 1 < page: pagination_data['prev_page'] = __makePage(page - 1) pagination_data['has_prev'] = True self.html_param['pagination'] = pagination_data self.html_param['raidlist'] = raidlist self.html_param['serchtype'] = serchtype self.html_param['state'] = state self.html_param['value'] = value self.writeAppHtml('infomations/view_raid/search')
def makeRaidObj(self, happeningraidset, o_player, o_person, eventmaster): happeningset = happeningraidset.happening raidboss = happeningraidset.raidboss eventdata = None if eventmaster: fastbonusdata = BackendApi.get_raidevent_fastbonusdata( eventmaster, raidboss, happeningset.happening.etime) rate = 1 if fastbonusdata: rate = fastbonusdata['rate'] # コンボボーナス. now = OSAUtil.get_now() combobonus_rate = BackendApi.get_raidevent_combobonus_powuprate( self.getModelMgr(), eventmaster, raidboss, using=settings.DB_READONLY, now=now) combo_cnt = raidboss.getCurrentComboCount(now=now) combobonus_rate_next = BackendApi.choice_raidevent_combobonus_powuprate( eventmaster, combo_cnt + 1) last_uid = None lastrecord = raidboss.getLastDamageRecord() if lastrecord: last_uid = lastrecord.uid combobonus = { 'cnt': combo_cnt, 'powup': combobonus_rate, 'powup_next': combobonus_rate_next, 'etime': DateTimeUtil.dateTimeToStr(raidboss.combo_etime), 'last_uid': last_uid, } eventdata = { 'id': eventmaster.id, 'name': eventmaster.name, 'owner': raidboss.get_owner_eventpoint() * rate, 'mvp': raidboss.get_mvp_eventpoint() * rate, 'combobonus': combobonus, } oname = Objects.person(self, o_player, o_person)['nickname'] return { 'id': happeningset.id, 'mid': raidboss.raid.mid, 'oid': raidboss.raid.oid, 'oname': oname, 'name': raidboss.master.name, 'level': raidboss.raid.level, 'hp': raidboss.hp, 'hpmax': raidboss.get_maxhp(), 'ctime': DateTimeUtil.dateTimeToStr(happeningset.happening.ctime), 'etime': DateTimeUtil.dateTimeToStr(happeningset.happening.etime), 'state': Defines.HappeningState.MGR_NAMES.get(happeningset.happening.state), 'eventdata': eventdata, }
def process(self): def to_i(v): if str(v).isdigit(): return int(v) else: return None serchtype = self.request.get('_serchtype') value = self.request.get('_value') page = (to_i(self.request.get('_page')) or 0) model_mgr = self.getModelMgr() raid_all = dict([ (master.id, master) for master in model_mgr.get_mastermodel_all( RaidMaster, fetch_deleted=True, using=settings.DB_READONLY) ]) event_all = dict([( master.id, master ) for master in model_mgr.get_mastermodel_all( RaidEventMaster, fetch_deleted=True, using=settings.DB_READONLY)]) uid = None if serchtype == 'uid': uid = to_i(value) elif serchtype == 'dmmid': uid = BackendApi.dmmid_to_appuid( self, [value], using=settings.DB_READONLY).get(value) if uid: PAGE_CONTENT_NUM = 100 filters = { 'uid': uid, } nummax = RaidLog.count(filters, using=settings.DB_READONLY) page_max = (nummax + PAGE_CONTENT_NUM - 1) / PAGE_CONTENT_NUM offset = page * PAGE_CONTENT_NUM raidloglist = RaidLog.fetchValues(filters=filters, order_by='-ctime', limit=PAGE_CONTENT_NUM, offset=offset, using=settings.DB_READONLY) raididlist = [raidlog.raidid for raidlog in raidloglist] recorddict = BackendApi.get_model_dict(model_mgr, Raid, raididlist, using=settings.DB_READONLY) happeningdict = BackendApi.get_model_dict( model_mgr, Happening, raididlist, using=settings.DB_READONLY) raidlist = [] for raidlog in raidloglist: happening = happeningdict.get(raidlog.raidid) record = recorddict.get(raidlog.raidid) raidboss = None eventmaster = None if record and happening: master = raid_all.get(record.mid) if master: raidevent_id = HappeningUtil.get_raideventid( happening.event) eventmaster = event_all.get(raidevent_id) eventraidmaster = None if eventmaster: eventraidmaster = BackendApi.get_raidevent_raidmaster( model_mgr, raidevent_id, master.id) raidboss = RaidBoss(record, master, eventraidmaster) if raidboss: point = 0 eventdata = None is_champagne_call = False champagne_num_add = 0 champagne_num_post = 0 material = 0 if eventmaster: if raidboss.hp < 1: fastbonusdata = BackendApi.get_raidevent_fastbonusdata( eventmaster, raidboss, happening.etime) rate = 1 if fastbonusdata: rate = fastbonusdata['rate'] if happening.oid == uid: point += raidboss.get_owner_eventpoint() else: point += raidboss.getHelpEventPoints(uid).get( uid, 0) if uid in raidboss.getMVPList(): point += raidboss.get_mvp_eventpoint() point = point * rate record = raidboss.getDamageRecord(uid) is_champagne_call = record.champagne champagne_num_add = record.champagne_num_add champagne_num_post = record.champagne_num_post material = record.material_num eventdata = { 'id': eventmaster.id, 'name': eventmaster.name, } raidlist.append({ 'id': raidboss.id, 'mid': raidboss.master.id, 'name': '%s%s' % (raidboss.master.name, u'[イベ]' if raidboss.raideventraidmaster else ''), 'level': raidboss.raid.level, 'ctime': DateTimeUtil.dateTimeToStr(raidboss.raid.ctime), 'url': self.makeAppLinkUrlAdmin( UrlMaker.view_raid(raidboss.id)), 'point': point, 'eventdata': eventdata, 'is_champagne_call': is_champagne_call, 'champagne_num_add': champagne_num_add, 'champagne_num_post': champagne_num_post, 'material': material, }) else: raidlist.append({ 'id': raidlog.raidid, 'mid': record.mid if record else 0, 'name': master.name if master else u'不明', 'level': record.level if record else 0, 'ctime': DateTimeUtil.dateTimeToStr(record.ctime) if record else u'不明', 'url': None, 'point': 0, 'eventdata': None, }) url = UrlMaker.view_raidlog() url = OSAUtil.addQuery(url, '_serchtype', serchtype) url = OSAUtil.addQuery(url, '_value', value) def __makePage(index): return { 'num': index, 'url': self.makeAppLinkUrlAdmin( OSAUtil.addQuery(url, '_page', index - 1)), } pagination_data = { 'page_list': [__makePage(p) for p in xrange(1, page_max + 1)], 'now_page': __makePage(page + 1), 'has_next': False, 'has_prev': False, } if page < page_max: pagination_data['next_page'] = __makePage(page + 1) pagination_data['has_next'] = True if 1 < page: pagination_data['prev_page'] = __makePage(page - 1) pagination_data['has_prev'] = True self.html_param['pagination'] = pagination_data self.html_param['raidlist'] = raidlist self.html_param['serchtype'] = serchtype self.html_param['value'] = value self.html_param['url_view_raidlog'] = self.makeAppLinkUrlAdmin( UrlMaker.view_raidlog()) self.writeAppHtml('infomations/view_raid/log')